From dd7d16bd1d1f5d79821b05842a9f647ff27d8687 Mon Sep 17 00:00:00 2001 From: Irelia <1074822720@qq.com> Date: Tue, 25 Jun 2024 18:52:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E4=BB=BB=E5=8A=A1=E6=89=A7=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=8F=AF=E8=83=BD=E6=AF=94=E4=BB=BB=E5=8A=A1=E5=91=A8?= =?UTF-8?q?=E6=9C=9F=E6=97=B6=E9=97=B4=E9=95=BF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_biliforward/__init__.py | 8 ++++++-- nonebot_plugin_biliforward/biliapi.py | 3 ++- nonebot_plugin_biliforward/rawmsg.py | 2 +- pyproject.toml | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/nonebot_plugin_biliforward/__init__.py b/nonebot_plugin_biliforward/__init__.py index 1928e7e..3ab1872 100644 --- a/nonebot_plugin_biliforward/__init__.py +++ b/nonebot_plugin_biliforward/__init__.py @@ -7,6 +7,7 @@ from nonebot.log import logger import asyncio import time +import datetime require("nonebot_plugin_saa") require("nonebot_plugin_localstore") @@ -46,6 +47,7 @@ add_whitelist = on_command('添加b站转发白名单') enable_auto_select_bot() +interval = 1000 @bili_login.handle() async def handle_bili_login(): @@ -106,7 +108,7 @@ async def handle_add_whitelist(event: GroupMessageEvent, session: async_scoped_s await whitelistdatabase.commit() await Text(f"用户{user_info.uname}(uid:{user_info.mid})已关注并添加到本群转发白名单").finish() -@scheduler.scheduled_job('cron', second='*/10') +@scheduler.scheduled_job('interval', seconds=interval, id='bili_fetch_msg', next_run_time=datetime.datetime.now()) async def bili_fetch_msg(): session = get_session() whitelistdatabase = WhiteListDatabase(session=session) @@ -133,4 +135,6 @@ async def bili_fetch_msg(): await msg.send_to(target=TargetQQGroup(group_id=group_id)) await msginfodatabase.insert_msg_info(external_msg=raw_msg.get_new_msginfo()) await msginfodatabase.commit() - await session.close() \ No newline at end of file + await session.close() + await asyncio.sleep(5) + scheduler.add_job(bili_fetch_msg, 'interval', seconds=interval, id='bili_fetch_msg', next_run_time=datetime.datetime.now() + datetime.timedelta(seconds=1), replace_existing=True) diff --git a/nonebot_plugin_biliforward/biliapi.py b/nonebot_plugin_biliforward/biliapi.py index 3f7ee3a..2097bb8 100644 --- a/nonebot_plugin_biliforward/biliapi.py +++ b/nonebot_plugin_biliforward/biliapi.py @@ -112,7 +112,8 @@ async def fetch_msg(talker_id: int) -> None|list[RawMsg]: msg_list: None|list[RawMsg] = None params = { 'talker_id': talker_id, - 'session_type': 1 + 'session_type': 1, + 'size':10 } async with httpx.AsyncClient() as client: cookie_file = store.get_data_file(PLUGIN_NAME, "cookie") diff --git a/nonebot_plugin_biliforward/rawmsg.py b/nonebot_plugin_biliforward/rawmsg.py index 8d640d4..0e4e6de 100644 --- a/nonebot_plugin_biliforward/rawmsg.py +++ b/nonebot_plugin_biliforward/rawmsg.py @@ -17,7 +17,7 @@ def __init__(self, rawmsg: dict) -> None: async def if_new(self, msg_db: MsgInfoDatabase) -> bool: now_time = time.time() - if now_time - self.timestamp > 12: + if now_time - self.timestamp > 3600: return False msg = await msg_db.get_msg_info(msg_key=self.msg_key) diff --git a/pyproject.toml b/pyproject.toml index 2bb1233..f36353b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot-plugin-biliforward" -version = "0.1.0" +version = "0.1.1" description = "" authors = ["Irelia <1074822720@qq.com>"] license = "MIT"