Skip to content

Commit

Permalink
fix: 修复检查消息任务执行时间可能比任务周期时间长的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
BraveCowardp committed Jun 25, 2024
1 parent 17b2823 commit dd7d16b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions nonebot_plugin_biliforward/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from nonebot.log import logger
import asyncio
import time
import datetime

require("nonebot_plugin_saa")
require("nonebot_plugin_localstore")
Expand Down Expand Up @@ -46,6 +47,7 @@
add_whitelist = on_command('添加b站转发白名单')

enable_auto_select_bot()
interval = 1000

@bili_login.handle()
async def handle_bili_login():
Expand Down Expand Up @@ -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)
Expand All @@ -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()
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)
3 changes: 2 additions & 1 deletion nonebot_plugin_biliforward/biliapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_biliforward/rawmsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot-plugin-biliforward"
version = "0.1.0"
version = "0.1.1"
description = ""
authors = ["Irelia <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit dd7d16b

Please sign in to comment.