Skip to content

Commit

Permalink
add new config format
Browse files Browse the repository at this point in the history
  • Loading branch information
Variante committed Mar 29, 2024
1 parent fa9f2b3 commit cf3af71
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ B站UP的更新与开播通知机,默认每分钟爬取一次B站账号的动
|:-----:|:----:|:----:|:----:|
| bnotifier_cookies ||| 上面导出的B站cookies的文件路径 |
| bnotifier_push_updates || {} | 设置追踪更新的UP主的ID(点击主页后地址中显示的space.bilibili.com/\[这个号码\])以及要推送的QQ群号,格式为{UP1: \[QQ群1, QQ群2, ...\], ...}。注意全部号码都应为字符串,一个例子:`{"823532": ["xxxxx", "yyyyy"]}`|
| bnotifier_push_lives ||| 同bnotifier_push_updates但这个变量控制的是开播通知 |
| bnotifier_push_updates_by_group || {} | 作用同bnotifier_push_updates但格式为{QQ群: \[UP1, UP2, \]},选择一个更适合你的方式即可 |
| bnotifier_push_lives || {} | 同bnotifier_push_updates但这个变量控制的是开播通知 |
| bnotifier_push_lives_by_group || {} | 格式同bnotifier_push_updates_by_group但这个变量控制的是开播通知 |

其它配置为开发调试时使用,正常使用无需调整。

Expand Down
15 changes: 15 additions & 0 deletions nonebot_plugin_bilibili_notifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ def get_credential(file: str):
def get_last_update():
return int(time.time()) - config.bnotifier_timeshift

# 把{qq: [mid]}的形式转化为{mid: [qq]}
def convert_by_group(by_group: dict, normal: dict):
for k, v in by_group.items():
for ups in v:
if ups in normal:
normal[ups].append(k)
else:
normal[ups] = [k]


config = get_plugin_config(Config)
logger.debug(config)
credential = get_credential(config.bnotifier_cookies)
Expand All @@ -98,6 +108,11 @@ def get_last_update():
last_live = None
# 设置延时
settings.timeout = config.bnotifier_api_timeout
# 将by group的配置转化为标准配置
convert_by_group(config.bnotifier_push_updates_by_group, config.bnotifier_push_updates)
convert_by_group(config.bnotifier_push_lives_by_group, config.bnotifier_push_lives)
logger.info(f'推送更新消息的用户:群:{config.bnotifier_push_updates}' )
logger.info(f'推送直播消息的用户:群:{config.bnotifier_push_lives}' )

@scheduler.scheduled_job('cron', second='0', misfire_grace_time=60) # = UTC+8 1445
async def fetch_bilibili_updates():
Expand Down
10 changes: 10 additions & 0 deletions nonebot_plugin_bilibili_notifier/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ class Config(BaseModel):
推送直播更新的up
{UPs: [QQ群, ...]}
"""
bnotifier_push_updates_by_group: dict = {}
"""
推送视频/动态更新的up (以QQ群为key)
{QQ群: [UPs, ...]}
"""
bnotifier_push_lives_by_group: dict = {}
"""
推送直播更新的up (以QQ群为key)
{QQ群: [UPs, ...]}
"""
bnotifier_push_after: int = 0
"""
dev用,只推送晚于这个时间的动态,默认0为程序启动时间
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nonebot-plugin-bilibili-notifier"
version = "0.0.1"
version = "0.0.2"
description = "NoneBot2 plugin for Bilibili update and live notifications"
authors = [
{name = "Variante", email = "[email protected]"},
Expand Down

0 comments on commit cf3af71

Please sign in to comment.