Merge branch 'main' into arknights

This commit is contained in:
felinae98 2021-02-26 21:44:43 +08:00
commit cae55d8f38
No known key found for this signature in database
GPG Key ID: 00C8B010587FF610
19 changed files with 67 additions and 23 deletions

21
LICENSE Normal file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 felinae98
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -1,4 +1,12 @@
# hk-reporter 通用订阅推送插件
<div align="center">
<h1>hk-reporter </br>通用订阅推送插件</h1>
[![pypi](https://badgen.net/pypi/v/nonebot-hk-reporter)](https://pypi.org/project/nonebot-hk-reporter/)
[![qq group](https://img.shields.io/badge/QQ%E7%BE%A4-868610060-orange )](https://qm.qq.com/cgi-bin/qm/qr?k=pXYMGB_e8b6so3QTqgeV6lkKDtEeYE4f&jump_from=webapi)
</div>
## 简介
一款自动爬取各种站点社交平台更新动态并将信息推送到QQ的机器人。基于 [`NoneBot2`](https://github.com/nonebot/nonebot2 ) 开发(诞生于明日方舟的蹲饼活动)
@ -9,13 +17,13 @@
* 文字
* 不支持视频
* 不支持转发的内容
* bilibili
* Bilibili
* 图片
* 专栏
* 文字
* 视频链接
* 不支持转发的内容
* rss
* RSS
* 从description中提取图片
* 文字
@ -25,6 +33,15 @@
本项目可作为单独插件使用仅包含订阅相关功能绝对simple和stupid也可直接克隆项目进行使用包含自动同意superuser自动接受入群邀请等功能
作为插件使用请安装`nonebot-hk-reporter`包,并在`bot.py`中加载`nonebot_hk_reporter`插件;或直接克隆本项目进行使用
配置与安装请参考[nonebot2文档](https://v2.nonebot.dev/)
<details>
<summary>Docker部署方法</summary>
Docker镜像地址为`felinae98/nonebot-hk-reporter`对应main分支`felinae98/nonebot-hk-reporter:arknights`对应arknights分支。例子
```bash
docker run --name nonebot-hk-reporter --network <network name> -d -e 'SUPERUSERS=[<Your QQ>]' -v <config dir>:/data -e 'hk_reporter_config_path=/data' -e 'HK_REPORTER_USE_PIC=True' -e 'HK_REPORTER_USE_LOCAL=True' felinae98/nonebot-hk-reporter
```
go-cqhttp镜像可使用`felinae98/go-cqhttp-ffmpeg`(数据目录为`/data`需要注意两个容器需要在同一个network中。
</details>
### 配置变量
* `HK_REPORTER_CONFIG_PATH` (str) 配置文件保存目录,如果不设置,则为当前目录下的`data`文件夹
@ -37,26 +54,26 @@
* 查询订阅:`查询订阅`
* 删除订阅(仅管理员和群主):`删除订阅`
平台代码包含:weibobilibilirss
平台代码包含:WeiboBilibiliRSS
<details>
<summary>各平台uid</summary>
下面均以pc站点为例
* weibo
* Weibo
* 对于一般用户主页`https://weibo.com/u/6441489862?xxxxxxxxxxxxxxx``/u/`后面的数字即为uid
* 对于有个性域名的用户如:`https://weibo.com/arknights`,需要点击左侧信息标签下“更多”,链接为`https://weibo.com/6279793937/about`其中中间数字即为uid
* bilibili
* Bilibili
* 主页链接一般为`https://space.bilibili.com/161775300?xxxxxxxxxx`数字即为uid
* rss
* rss链接即为uid
* RSS
* RSS链接即为uid
</details>
### 文字转图片
因为可能要发送长文本所以bot很可能被风控如有需要请开启以图片形式发送文字本项目使用的图片转文字方法是chromium经典杀鸡用牛刀
因为可能要发送长文本所以bot很可能被风控如有需要请开启以图片形式发送文字本项目使用的文字转图片方法是Chromium经典杀鸡用牛刀
如果确定要开启推荐自行安装chromium设置使用本地chromium并且保证服务器有比较大的内存。
如果确定要开启推荐自行安装Chromium设置使用本地Chromium并且保证服务器有比较大的内存。
## 功能
* 定时爬取定网站
* 定时爬取定网站
* 通过图片发送文本,防止风控
* 使用队列限制发送频率

@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot-hk-reporter"
version = "0.2.2"
version = "0.2.5"
description = "Subscribe message from social medias"
authors = ["felinae98 <felinae225@qq.com>"]
license = "MIT"
@ -8,8 +8,8 @@ homepage = "https://github.com/felinae98/nonebot-hk-reporter"
keywords = ["nonebot", "nonebot2", "qqbot"]
readme = "README.md"
packages = [
{ include = "hk_reporter/*.py", from = "./src/plugins/" },
{ include = "hk_reporter/platform/*.py", from = "./src/plugins/" }
{ include = "nonebot_hk_reporter/*.py", from = "./src/plugins/" },
{ include = "nonebot_hk_reporter/platform/*.py", from = "./src/plugins/" }
]
classifiers = [
"Development Status :: 2 - Pre-Alpha",

@ -5,8 +5,10 @@ import nonebot
from nonebot import logger
import base64
from pyppeteer import launch
from pyppeteer.chromium_downloader import check_chromium, download_chromium
from html import escape
from hashlib import sha256
from tempfile import NamedTemporaryFile
from .plugin_config import plugin_config
@ -19,6 +21,10 @@ class Singleton(type):
supported_target_type = ('weibo', 'bilibili', 'rss', 'arknights')
if not plugin_config.hk_reporter_use_local and not check_chromium():
os.environ['PYPPETEER_DOWNLOAD_HOST'] = 'http://npm.taobao.org/mirrors'
download_chromium()
class Render(metaclass=Singleton):
def __init__(self):
@ -44,14 +50,14 @@ class Render(metaclass=Singleton):
return str(data)
async def text_to_pic(self, text: str) -> str:
hash_text = sha256(text.encode()).hexdigest()[:20]
lines = text.split('\n')
parsed_lines = list(map(lambda x: '<p>{}</p>'.format(escape(x)), lines))
html_text = '<div style="width:17em;padding:1em">{}</div>'.format(''.join(parsed_lines))
with open('/tmp/text-{}.html'.format(hash_text), 'w') as f:
f.write(html_text)
data = await self.render('file:///tmp/text-{}.html'.format(hash_text), target='div')
os.remove('/tmp/text-{}.html'.format(hash_text))
with NamedTemporaryFile('wt', suffix='.html', delete=False) as tmp:
tmp_path = tmp.name
tmp.write(html_text)
data = await self.render('file://{}'.format(tmp_path), target='div')
os.remove(tmp_path)
return data
async def text_to_pic_cqcode(self, text:str) -> str:
@ -61,10 +67,10 @@ class Render(metaclass=Singleton):
# logger.debug(code)
return code
async def parse_text(text: str):
async def parse_text(text: str) -> str:
'return raw text if don\'t use pic, otherwise return rendered opcode'
if plugin_config.hk_reporter_use_pic:
r = Render()
return await r.text_to_pic_cqcode(text)
render = Render()
return await render.text_to_pic_cqcode(text)
else:
return text