Merge branch 'rename'

This commit is contained in:
felinae98 2021-11-18 15:49:55 +08:00
commit e5d324a8b4
No known key found for this signature in database
GPG Key ID: 00C8B010587FF610
38 changed files with 187 additions and 8774 deletions

View File

@ -47,7 +47,7 @@ jobs:
- image: cimg/python:3.9
- image: browserless/chrome
environment:
HK_REPORTER_BROWSER: ws://localhost:3000
BISON_BROWSER: ws://localhost:3000
steps:
- checkout
# - run: sed -e '41,45d' -i pyproject.toml

View File

@ -1,5 +1,5 @@
FROM python:3.9
RUN python3 -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
RUN python3 -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
RUN python3 -m pip install poetry && poetry config virtualenvs.create false
WORKDIR /app
COPY ./pyproject.toml ./poetry.lock* /app/

View File

@ -1,12 +0,0 @@
module.exports = {
title: 'Nonebot HK Reporter',
description: 'Docs for Nonebot HK Reporter',
themeConfig: {
nav: [
{ text: '主页', link: '/' },
{ text: '部署与使用', link: '/usage/' },
{ text: '开发', link: '/dev/' },
{ text: 'Github', link: 'https://github.com/felinae98/nonebot-hk-reporter' }
]
}
}

View File

@ -1,15 +0,0 @@
---
home: true
heroText: Nonebot HK Reporter
tagline: 本bot励志做全世界跑得最快的搬运机器人
actionText: 快速部署
actionLink: /usage/
features:
- title: KISS
details: 作为插件可以Simple和Stupid作为插件可以Simple和Stupid作为Bot提供适用的功能
- title: 拓展性强
details: 没有自己想要的网站?只要简单的爬虫知识就可以给它适配一个新的网站
- title: 通用,强大
details: 社交媒体?网站更新?游戏开服?只要能爬就都能推,还支持自定义过滤
footer: MIT Licensed
---

View File

@ -1,53 +0,0 @@
---
sidebar: auto
---
# 开发指南
本插件需要你的帮助!只需要会写简单的爬虫,就能给本插件适配新的网站。
## 基本概念
* `nonebot_hk_reporter.post.Post`: 可以理解为推送内容,其中包含需要发送的文字,图片,链接,平台信息等
* `nonebot_hk_reporter.types.RawPost`: 从站点/平台中爬到的单条信息
* `nonebot_hk_reporter.types.Target`: 目标账号Bilibili微博等社交媒体中的账号
* `nonebot_hk_reporter.types.Category`: 信息分类,例如视频,动态,图文,文章等
* `nonebot_hk_reporter.types.Tag`: 信息标签例如微博中的超话或者hashtag
## 快速上手
上车!我们走
先明确需要适配的站点类型,先明确两个问题:
#### 我要发送什么样的推送
* `nonebot_hk_reporter.platform.platform.NewMessage` 最常见的类型,每次爬虫向特定接口爬取一个消息列表,
与之前爬取的信息对比,过滤出新的消息,再根据用户自定义的分类和标签进行过滤,最后处理消息,把
处理过后的消息发送给用户
例如微博Bilibili
* `nonebot_hk_reporter.platform.platform.StatusChange` 每次爬虫获取一个状态,在状态改变时发布推送
例如:游戏开服提醒,主播上播提醒
* `nonebot_hk_reporter.platform.platform.SimplePost``NewMessage`相似,但是不过滤新的消息
,每次发送全部消息
例如:每日榜单定时发送
#### 这个平台是否有账号的概念
* `nonebot_hk_reporter.platform.platform.TargetMixin` 有账号的概念
例如Bilibili用户微博用户
* `nonebot_hk_reporter.platform.platform.NoTargetMixin` 没有账号的概念
例如:游戏公告,教务处公告
现在你已经选择了两个类,现在你需要在`src/plugins/nonebot_hk_reporter/platform`下新建一个py文件
在里面新建一个类,继承你刚刚选择的两个类,重载一些关键的函数,然后……就完成了,不需要修改别的东西了。
例如要适配微博微博有账号并且我希望bot搬运新的消息所以微博的类应该这样定义
```python
class Weibo(NewMessage, TargetMixin):
...
```
当然我们非常希望你对自己适配的平台写一些单元测试,你可以模仿`tests/platforms/test_*.py`中的内容写
一些单元测试。为保证多次运行测试的一致性可以mock http的响应测试的内容包括获取RawPost处理成Post
测试分类以及提取tag等当然最好和rsshub做一个交叉验证。
::: danger
Nonebot项目使用了全异步的处理方式所以你需要对异步Python asyncio的机制有一定了解当然
依葫芦画瓢也是足够的
:::
## 类的方法与成员变量
## 方法与变量的定义

View File

@ -1,100 +0,0 @@
---
sidebar: auto
---
# 部署和使用
本节将教你快速部署和使用一个nonebot-hk-reporter如果你不知道要选择哪种部署方式推荐使用[docker-compose](#docker-compose部署-推荐)
## 部署
本项目可以作为单独的Bot使用可以作为nonebot2的插件使用
### 作为Bot使用
额外提供自动同意超级用户的好友申请和同意超级用户的加群邀请的功能
#### docker-compose部署推荐
1. 在一个新的目录中下载[docker-compose.yml](https://raw.githubusercontent.com/felinae98/nonebot-hk-reporter/main/docker-compose.yml)
将其中的`<your QQ>`改成自己的QQ号
```bash
wget https://raw.githubusercontent.com/felinae98/nonebot-hk-reporter/main/docker-compose.yml
```
2. 运行配置go-cqhttp
```bash
docker-compose run go-cqhttp
```
通信方式选择:`3: 反向 Websocket 通信`
编辑`bot-data/config.yml`,更改下面字段:
```
account: # 账号相关
uin: <QQ号> # QQ账号
password: "<QQ密码>" # 密码为空时使用扫码登录
message:
post-format: array
............
servers:
- ws-reverse:
universal: ws://nonebot:8080/cqhttp/ws # 将这个字段写为这个值
```
3. 登录go-cqhttp
再次
```bash
docker-compose run go-cqhttp
```
参考[go-cqhttp文档](https://docs.go-cqhttp.org/faq/slider.html#%E6%96%B9%E6%A1%88a-%E8%87%AA%E8%A1%8C%E6%8A%93%E5%8C%85)
完成登录
4. 确定完成登录后启动bot
```bash
docker-compose up -d
```
#### docker部署
本项目的docker镜像为`felinae98/nonebot-hk-reporter`可以直接pull后run进行使用
相关配置参数可以使用`-e`作为环境变量传入
#### 直接运行(不推荐)
可以参考[nonebot的运行方法](https://v2.nonebot.dev/guide/getting-started.html)
::: danger
本项目中使用了Python 3.9的语法如果出现问题请检查Python版本
:::
1. 首先安装poetry[安装方法](https://python-poetry.org/docs/#installation)
2. clone本项目在项目中`poetry install`安装依赖
3. 编辑`.env.prod`配置各种环境变量,见[Nonebot2配置](https://v2.nonebot.dev/guide/basic-configuration.html)
4. 运行`poetry run python bot.py`启动机器人
### 作为插件使用
本部分假设大家会部署nonebot2
#### 手动安装
1. 安装pip包`nonebot-hk-reporter`
2. 在`bot.py`中导入插件`nonebot_hk_reporter`
### 自动安装
使用`nb-cli`执行:`nb plugin install nonebot_hk_reporter`
## 配置
可参考[源文件](https://github.com/felinae98/nonebot-hk-reporter/blob/main/src/plugins/nonebot_hk_reporter/plugin_config.py)
* `HK_REPORTER_CONFIG_PATH`: 插件存放配置文件的位置,如果不设定默认为项目目录下的`data`目录
* `HK_REPORTER_USE_PIC`: 将文字渲染成图片后进行发送,多用于规避风控
* `HK_REPORTER_BROWSER`: 在某些情况下需要使用到chrome进行渲染
* 使用browserless提供的Chrome管理服务设置为`ws://xxxxxxxx`值为Chrome Endpoint推荐
* 使用本地安装的Chrome设置为`local:<chrome path>`,例如`local:/usr/bin/google-chrome-stable`
* 如果不进行配置那么会在使用到Chrome的时候自动进行安装不推荐
### 需要使用Chrome的情况
* 设置了`HK_REPORTER_USE_PIC`,需要将文字渲染成图片
* 渲染明日方舟游戏内公告
## 使用
::: warning
本节假设`COMMAND_START`设置中包含`''`如果出现bot不响应的问题请先
排查这个设置
:::
### 命令
#### 在本群中进行配置
所有命令都需要@bot触发
* 添加订阅仅管理员和群主和SUPERUSER`添加订阅`
* 查询订阅:`查询订阅`
* 删除订阅仅管理员和群主和SUPERUSER`删除订阅`
#### 私聊机器人进行配置需要SUPERUER权限
* 添加订阅:`管理-添加订阅`
* 查询订阅:`管理-查询订阅`
* 删除订阅:`管理-删除订阅`
### 所支持平台的uid
#### Weibo
* 对于一般用户主页`https://weibo.com/u/6441489862?xxxxxxxxxxxxxxx``/u/`后面的数字即为uid
* 对于有个性域名的用户如:`https://weibo.com/arknights`,需要点击左侧信息标签下“更多”,链接为`https://weibo.com/6279793937/about`其中中间数字即为uid
#### Bilibili
主页链接一般为`https://space.bilibili.com/161775300?xxxxxxxxxx`数字即为uid
#### RSS
RSS链接即为uid

View File

@ -1,17 +0,0 @@
{
"name": "nonebot-hk-reporter-docs",
"version": "1.0.0",
"description": "Docs for nonebot-hk-reporter",
"main": "index.js",
"repository": "git@github.com:felinae98/nonebot-hk-reporter.git",
"author": "felinae98 <731499577@qq.com>",
"license": "MIT",
"private": false,
"devDependencies": {
"vuepress": "^1.8.2"
},
"scripts": {
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs"
}
}

537
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,15 @@
[tool.poetry]
name = "nonebot-hk-reporter"
name = "nonebot-bison"
version = "0.3.3"
description = "Subscribe message from social medias"
authors = ["felinae98 <felinae225@qq.com>"]
license = "MIT"
homepage = "https://github.com/felinae98/nonebot-hk-reporter"
homepage = "https://github.com/felinae98/nonebot-bison"
keywords = ["nonebot", "nonebot2", "qqbot"]
readme = "README.md"
packages = [
{ include = "nonebot_hk_reporter/*.py", from = "./src/plugins/" },
{ include = "nonebot_hk_reporter/platform/*.py", from = "./src/plugins/" }
{ include = "nonebot_bison/*.py", from = "./src/plugins/" },
{ include = "nonebot_bison/platform/*.py", from = "./src/plugins/" }
]
classifiers = [
"Development Status :: 2 - Pre-Alpha",
@ -34,17 +34,17 @@ apscheduler = "^3.7.0"
ipdb = "^0.13.4"
pytest = "^6.2.4"
pytest-asyncio = "^0.15.1"
respx = "^0.17.0"
respx = "^0.19.0"
coverage = "^5.5"
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
[[tool.poetry.source]]
name = "aliyun"
url = "https://mirrors.aliyun.com/pypi/simple/"
default = true
# [[tool.poetry.source]]
# name = "aliyun"
# url = "https://mirrors.aliyun.com/pypi/simple/"
# default = true
[tool.pytest.ini_options]
markers = [

View File

@ -14,14 +14,18 @@ from .platform import platform_manager
supported_target_type = platform_manager.keys()
def get_config_path() -> str:
if plugin_config.hk_reporter_config_path:
data_dir = plugin_config.hk_reporter_config_path
if plugin_config.bison_config_path:
data_dir = plugin_config.bison_config_path
else:
working_dir = os.getcwd()
data_dir = path.join(working_dir, 'data')
if not path.isdir(data_dir):
os.makedirs(data_dir)
return path.join(data_dir, 'hk_reporter.json')
old_path = path.join(data_dir, 'hk_reporter.json')
new_path = path.join(data_dir, 'bison.json')
if os.path.exists(old_path) and not os.path.exists(new_path):
os.rename(old_path, new_path)
return new_path
class NoSuchUserException(Exception):
pass

View File

@ -54,7 +54,7 @@ def do_add_sub(add_sub: Type[Matcher]):
@add_sub.handle()
async def init_id(bot: Bot, event: Event, state: T_State):
if platform_manager[state['platform']].has_target:
state['_prompt'] = '请输入订阅用户的id详情查阅https://nonebot-hk-reporter.vercel.app/usage/#%E6%89%80%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%9A%84uid'
state['_prompt'] = '请输入订阅用户的id详情查阅https://nonebot-bison.vercel.app/usage/#%E6%89%80%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%9A%84uid'
else:
state['id'] = 'default'
state['name'] = await platform_manager[state['platform']].get_target_name(Target(''))

View File

@ -134,7 +134,7 @@ class MessageProcessMixin(PlatformNameMixin, CategoryMixin, ParsePostMixin, abst
# if post_id in exists_posts_set:
# continue
if (post_time := self.get_date(raw_post)) and time.time() - post_time > 2 * 60 * 60 and \
plugin_config.hk_reporter_init_filter:
plugin_config.bison_init_filter:
continue
try:
self.get_category(raw_post)
@ -157,7 +157,7 @@ class NewMessageProcessMixin(StorageMixinProto, MessageProcessMixin, abstract=Tr
filtered_post = await self.filter_common(raw_post_list)
store = self.get_stored_data(target) or self.MessageStorage(False, set())
res = []
if not store.inited and plugin_config.hk_reporter_init_filter:
if not store.inited and plugin_config.bison_init_filter:
# target not init
for raw_post in filtered_post:
post_id = self.get_id(raw_post)

View File

@ -0,0 +1,21 @@
from pydantic import BaseSettings
import warnings
import nonebot
class PlugConfig(BaseSettings):
bison_config_path: str = ""
bison_use_pic: bool = False
bison_use_local: bool = False
bison_browser: str = ''
bison_init_filter: bool = True
bison_use_queue: bool = True
class Config:
extra = 'ignore'
global_config = nonebot.get_driver().config
plugin_config = PlugConfig(**global_config.dict())
if plugin_config.bison_use_local:
warnings.warn('BISON_USE_LOCAL is deprecated, please use BISON_BROWSER')

View File

@ -29,7 +29,7 @@ class Post:
def _use_pic(self):
if not self.override_use_pic is None:
return self.override_use_pic
return plugin_config.hk_reporter_use_pic
return plugin_config.bison_use_pic
async def _pic_url_to_image(self, data: Union[str, bytes]) -> Image.Image:
pic_buffer = BytesIO()

View File

@ -53,7 +53,7 @@ for platform_name, platform in platform_manager.items():
fetch_and_send, platform.schedule_type, **platform.schedule_kw,
args=(platform_name,))
if plugin_config.hk_reporter_use_queue:
if plugin_config.bison_use_queue:
scheduler.add_job(do_send_msgs, 'interval', seconds=0.3, coalesce=True)
class SchedulerLogFilter(logging.Filter):

View File

@ -33,7 +33,7 @@ async def do_send_msgs():
LAST_SEND_TIME = time.time()
async def send_msgs(bot, user, user_type, msgs):
if plugin_config.hk_reporter_use_queue:
if plugin_config.bison_use_queue:
for msg in msgs:
QUEUE.append((bot, user, user_type, msg, 2))
else:

View File

@ -24,7 +24,7 @@ class Singleton(type):
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
if not plugin_config.hk_reporter_browser and not plugin_config.hk_reporter_use_local \
if not plugin_config.bison_browser and not plugin_config.bison_use_local \
and not check_chromium():
os.environ['PYPPETEER_DOWNLOAD_HOST'] = 'http://npm.taobao.org/mirrors'
download_chromium()
@ -38,15 +38,15 @@ class Render(metaclass=Singleton):
self.remote_browser = False
async def get_browser(self) -> Browser:
if plugin_config.hk_reporter_browser:
if plugin_config.hk_reporter_browser.startswith('local:'):
path = plugin_config.hk_reporter_browser.split('local:', 1)[1]
if plugin_config.bison_browser:
if plugin_config.bison_browser.startswith('local:'):
path = plugin_config.bison_browser.split('local:', 1)[1]
return await launch(executablePath=path, args=['--no-sandbox'])
if plugin_config.hk_reporter_browser.startswith('ws:'):
if plugin_config.bison_browser.startswith('ws:'):
self.remote_browser = True
return await connect(browserWSEndpoint=plugin_config.hk_reporter_browser)
raise RuntimeError('HK_REPORTER_BROWSER error')
if plugin_config.hk_reporter_use_local:
return await connect(browserWSEndpoint=plugin_config.bison_browser)
raise RuntimeError('bison_BROWSER error')
if plugin_config.bison_use_local:
return await launch(executablePath='/usr/bin/chromium', args=['--no-sandbox'])
return await launch(args=['--no-sandbox'])
@ -119,7 +119,7 @@ class Render(metaclass=Singleton):
async def parse_text(text: str) -> MessageSegment:
'return raw text if don\'t use pic, otherwise return rendered opcode'
if plugin_config.hk_reporter_use_pic:
if plugin_config.bison_use_pic:
render = Render()
return await render.text_to_pic_cqcode(text)
else:

View File

@ -1,21 +0,0 @@
from pydantic import BaseSettings
import warnings
import nonebot
class PlugConfig(BaseSettings):
hk_reporter_config_path: str = ""
hk_reporter_use_pic: bool = False
hk_reporter_use_local: bool = False
hk_reporter_browser: str = ''
hk_reporter_init_filter: bool = True
hk_reporter_use_queue: bool = True
class Config:
extra = 'ignore'
global_config = nonebot.get_driver().config
plugin_config = PlugConfig(**global_config.dict())
if plugin_config.hk_reporter_use_local:
warnings.warn('HK_REPORTER_USE_LOCAL is deprecated, please use HK_REPORTER_BROWSER')

View File

@ -5,18 +5,18 @@ import typing
if typing.TYPE_CHECKING:
import sys
sys.path.append('./src/plugins')
import nonebot_hk_reporter
import nonebot_bison
@pytest.fixture#(scope="module")
def plugin_module(tmpdir):
nonebot.init(hk_reporter_config_path=str(tmpdir))
nonebot.init(bison_config_path=str(tmpdir))
nonebot.load_plugins('src/plugins')
plugins = nonebot.get_loaded_plugins()
plugin = list(filter(lambda x: x.name == 'nonebot_hk_reporter', plugins))[0]
plugin = list(filter(lambda x: x.name == 'nonebot_bison', plugins))[0]
return plugin.module
@pytest.fixture
def dummy_user_subinfo(plugin_module: 'nonebot_hk_reporter'):
def dummy_user_subinfo(plugin_module: 'nonebot_bison'):
user = plugin_module.types.User('123', 'group')
return plugin_module.types.UserSubInfo(
user=user,

View File

@ -7,12 +7,12 @@ import feedparser
if typing.TYPE_CHECKING:
import sys
sys.path.append('./src/plugins')
import nonebot_hk_reporter
import nonebot_bison
from .utils import get_json, get_file
@pytest.fixture
def arknights(plugin_module: 'nonebot_hk_reporter'):
def arknights(plugin_module: 'nonebot_bison'):
return plugin_module.platform.platform_manager['arknights']
@pytest.fixture(scope='module')
@ -23,17 +23,27 @@ def arknights_list_0():
def arknights_list_1():
return get_json('arknights_list_1.json')
@pytest.fixture(scope='module')
def monster_siren_list_0():
return get_json('monster-siren_list_0.json')
@pytest.fixture(scope='module')
def monster_siren_list_1():
return get_json('monster-siren_list_1.json')
@pytest.mark.asyncio
@respx.mock
async def test_fetch_new(arknights, dummy_user_subinfo, arknights_list_0, arknights_list_1):
async def test_fetch_new(arknights, dummy_user_subinfo, arknights_list_0, arknights_list_1, monster_siren_list_0, monster_siren_list_1):
ak_list_router = respx.get("https://ak-conf.hypergryph.com/config/prod/announce_meta/IOS/announcement.meta.json")
detail_router = respx.get("https://ak-fs.hypergryph.com/announce/IOS/announcement/675.html")
version_router = respx.get('https://ak-conf.hypergryph.com/config/prod/official/IOS/version')
preannouncement_router = respx.get('https://ak-conf.hypergryph.com/config/prod/announce_meta/IOS/preannouncement.meta.json')
monster_siren_router = respx.get("https://monster-siren.hypergryph.com/api/news")
ak_list_router.mock(return_value=Response(200, json=arknights_list_0))
detail_router.mock(return_value=Response(200, text=get_file('arknights-detail-675.html')))
version_router.mock(return_value=Response(200, json=get_json('arknights-version-0.json')))
preannouncement_router.mock(return_value=Response(200, json=get_json('arknights-pre-0.json')))
monster_siren_router.mock(return_value=Response(200, json=monster_siren_list_0))
target = ''
res = await arknights.fetch_new_post(target, [dummy_user_subinfo])
assert(ak_list_router.called)
@ -51,4 +61,5 @@ async def test_fetch_new(arknights, dummy_user_subinfo, arknights_list_0, arknig
assert(post.target_name == '明日方舟游戏内公告')
assert(len(post.pics) == 1)
assert(post.pics == ['https://ak-fs.hypergryph.com/announce/images/20210623/e6f49aeb9547a2278678368a43b95b07.jpg'])
print(res3[0][1])
r = await post.generate_messages()

View File

@ -5,7 +5,7 @@ from httpx import Response
if typing.TYPE_CHECKING:
import sys
sys.path.append('./src/plugins')
import nonebot_hk_reporter
import nonebot_bison
from .utils import get_json
@ -14,7 +14,7 @@ def bing_dy_list():
return get_json('bilibili_bing_list.json')['data']['cards']
@pytest.fixture
def bilibili(plugin_module: 'nonebot_hk_reporter'):
def bilibili(plugin_module: 'nonebot_bison'):
return plugin_module.platform.platform_manager['bilibili']
@pytest.mark.asyncio

View File

@ -1,44 +0,0 @@
import pytest
import typing
import respx
from httpx import Response
import feedparser
if typing.TYPE_CHECKING:
import sys
sys.path.append('./src/plugins')
import nonebot_hk_reporter
from .utils import get_json, get_file
@pytest.fixture
def monster_siren(plugin_module: 'nonebot_hk_reporter'):
return plugin_module.platform.platform_manager['monster-siren']
@pytest.fixture(scope='module')
def monster_siren_list_0():
return get_json('monster-siren_list_0.json')
@pytest.fixture(scope='module')
def monster_siren_list_1():
return get_json('monster-siren_list_1.json')
@pytest.mark.asyncio
@respx.mock
async def test_fetch_new(monster_siren, dummy_user_subinfo, monster_siren_list_0, monster_siren_list_1):
ak_list_router = respx.get("https://monster-siren.hypergryph.com/api/news")
ak_list_router.mock(return_value=Response(200, json=monster_siren_list_0))
target = ''
res = await monster_siren.fetch_new_post(target, [dummy_user_subinfo])
assert(ak_list_router.called)
assert(len(res) == 0)
mock_data = monster_siren_list_1
ak_list_router.mock(return_value=Response(200, json=mock_data))
res3 = await monster_siren.fetch_new_post(target, [dummy_user_subinfo])
assert(len(res3[0][1]) == 1)
post = res3[0][1][0]
assert(post.target_type == 'monster-siren')
assert(post.text == '#D.D.D.PHOTO')
assert(post.url == 'https://monster-siren.hypergryph.com/info/241303')
assert(post.target_name == '塞壬唱片新闻')
assert(len(post.pics) == 0)

View File

@ -8,10 +8,10 @@ from httpx import Response
if typing.TYPE_CHECKING:
import sys
sys.path.append('./src/plugins')
import nonebot_hk_reporter
import nonebot_bison
@pytest.fixture
def ncm_artist(plugin_module: 'nonebot_hk_reporter'):
def ncm_artist(plugin_module: 'nonebot_bison'):
return plugin_module.platform.platform_manager['ncm-artist']
@pytest.fixture(scope='module')

View File

@ -7,9 +7,9 @@ import pytest
if typing.TYPE_CHECKING:
import sys
sys.path.append('./src/plugins')
import nonebot_hk_reporter
from nonebot_hk_reporter.types import *
from nonebot_hk_reporter.post import Post
import nonebot_bison
from nonebot_bison.types import *
from nonebot_bison.post import Post
from time import time
now = time()
@ -26,18 +26,18 @@ raw_post_list_2 = raw_post_list_1 + [
]
@pytest.fixture
def dummy_user(plugin_module: 'nonebot_hk_reporter'):
def dummy_user(plugin_module: 'nonebot_bison'):
user = plugin_module.types.User('123', 'group')
return user
@pytest.fixture
def user_info_factory(plugin_module: 'nonebot_hk_reporter', dummy_user):
def user_info_factory(plugin_module: 'nonebot_bison', dummy_user):
def _user_info(category_getter, tag_getter):
return plugin_module.types.UserSubInfo(dummy_user, category_getter, tag_getter)
return _user_info
@pytest.fixture
def mock_platform_without_cats_tags(plugin_module: 'nonebot_hk_reporter'):
def mock_platform_without_cats_tags(plugin_module: 'nonebot_bison'):
class MockPlatform(plugin_module.platform.platform.NewMessage,
plugin_module.platform.platform.TargetMixin):
@ -76,7 +76,7 @@ def mock_platform_without_cats_tags(plugin_module: 'nonebot_hk_reporter'):
return MockPlatform()
@pytest.fixture
def mock_platform(plugin_module: 'nonebot_hk_reporter'):
def mock_platform(plugin_module: 'nonebot_bison'):
class MockPlatform(plugin_module.platform.platform.NewMessage,
plugin_module.platform.platform.TargetMixin):
@ -123,7 +123,7 @@ def mock_platform(plugin_module: 'nonebot_hk_reporter'):
return MockPlatform()
@pytest.fixture
def mock_platform_no_target(plugin_module: 'nonebot_hk_reporter'):
def mock_platform_no_target(plugin_module: 'nonebot_bison'):
class MockPlatform(plugin_module.platform.platform.NewMessage,
plugin_module.platform.platform.NoTargetMixin):
@ -174,7 +174,7 @@ def mock_platform_no_target(plugin_module: 'nonebot_hk_reporter'):
return MockPlatform()
@pytest.fixture
def mock_platform_no_target_2(plugin_module: 'nonebot_hk_reporter'):
def mock_platform_no_target_2(plugin_module: 'nonebot_bison'):
class MockPlatform(plugin_module.platform.platform.NewMessage,
plugin_module.platform.platform.NoTargetMixin):
@ -230,7 +230,7 @@ def mock_platform_no_target_2(plugin_module: 'nonebot_hk_reporter'):
return MockPlatform()
@pytest.fixture
def mock_status_change(plugin_module: 'nonebot_hk_reporter'):
def mock_status_change(plugin_module: 'nonebot_bison'):
class MockPlatform(plugin_module.platform.platform.StatusChange,
plugin_module.platform.platform.NoTargetMixin):
@ -359,7 +359,7 @@ async def test_status_change(mock_status_change, user_info_factory):
assert(len(res4) == 0)
@pytest.mark.asyncio
async def test_group(plugin_module: 'nonebot_hk_reporter', mock_platform_no_target, mock_platform_no_target_2, user_info_factory):
async def test_group(plugin_module: 'nonebot_bison', mock_platform_no_target, mock_platform_no_target_2, user_info_factory):
group_platform = plugin_module.platform.platform.NoTargetGroup([mock_platform_no_target, mock_platform_no_target_2])
res1 = await group_platform.fetch_new_post('dummy', [user_info_factory(lambda _: [1,4], lambda _: [])])
assert(len(res1) == 0)

View File

@ -9,12 +9,12 @@ import feedparser
if typing.TYPE_CHECKING:
import sys
sys.path.append('./src/plugins')
import nonebot_hk_reporter
import nonebot_bison
from .utils import get_json, get_file
@pytest.fixture
def weibo(plugin_module: 'nonebot_hk_reporter'):
def weibo(plugin_module: 'nonebot_bison'):
return plugin_module.platform.platform_manager['weibo']
@pytest.fixture(scope='module')

View File

@ -4,14 +4,14 @@ import typing
if typing.TYPE_CHECKING:
import sys
sys.path.append('./src/plugins')
import nonebot_hk_reporter
import nonebot_bison
@pytest.fixture
def config(plugin_module):
plugin_module.config.start_up()
return plugin_module.config.Config()
def test_create_and_get(config: 'nonebot_hk_reporter.config.Config', plugin_module: 'nonebot_hk_reporter'):
def test_create_and_get(config: 'nonebot_bison.config.Config', plugin_module: 'nonebot_bison'):
config.add_subscribe(
user='123',
user_type='group',

View File

@ -4,7 +4,7 @@ import typing
if typing.TYPE_CHECKING:
import sys
sys.path.append('./src/plugins')
import nonebot_hk_reporter
import nonebot_bison
merge_source_9 = [
'https://wx1.sinaimg.cn/large/0071VPLMgy1gq0vib7zooj30dx0dxmz5.jpg',
@ -23,7 +23,7 @@ merge_source_9 = [
]
@pytest.mark.asyncio
async def test_9_merge(plugin_module: 'nonebot_hk_reporter'):
async def test_9_merge(plugin_module: 'nonebot_bison'):
post = plugin_module.post.Post('', '', '', pics=merge_source_9)
await post._pic_merge()
assert len(post.pics) == 5

View File

@ -4,11 +4,11 @@ import typing
if typing.TYPE_CHECKING:
import sys
sys.path.append('./src/plugins')
import nonebot_hk_reporter
import nonebot_bison
@pytest.mark.asyncio
@pytest.mark.render
async def test_render(plugin_module: 'nonebot_hk_reporter'):
async def test_render(plugin_module: 'nonebot_bison'):
render = plugin_module.utils.Render()
res = await render.text_to_pic('''a\nbbbbbbbbbbbbbbbbbbbbbb\ncd
<h1>中文</h1>

8008
yarn.lock

File diff suppressed because it is too large Load Diff