Skip to content

Commit

Permalink
perf: 私聊回复延迟三秒
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed May 25, 2024
1 parent eda9b1c commit f23733e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions campux/imbot/nbmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def can_send_help_message(user_id: int) -> bool:
help_message_sent_record[user_id] = time.time()
return True

async def fdelay(seconds: float=3):
await asyncio.sleep(seconds)

# ========= 私聊 =========
sign_up = on_command("注册账号", rule=to_me() & is_private & not_bot_self, priority=10, block=True)
reset_password = on_command("重置密码", rule=to_me() & is_private & not_bot_self, priority=10, block=True)
Expand All @@ -46,6 +49,9 @@ async def sign_up_func(event: Event):

try:
pwd = await api.campux_api.sign_up(uin=int(event.get_user_id()))

await fdelay()

await sign_up.finish(f"注册成功,初始密码:\n{pwd}")
except Exception as e:
if isinstance(e, nonebot.exception.FinishedException):
Expand All @@ -57,6 +63,9 @@ async def sign_up_func(event: Event):
async def reset_password_func(event: Event):
try:
pwd = await api.campux_api.reset_password(uin=int(event.get_user_id()))

await fdelay()

await reset_password.finish(f"重置成功,新密码:\n{pwd}")
except Exception as e:
if isinstance(e, nonebot.exception.FinishedException):
Expand All @@ -82,6 +91,9 @@ async def qrcode_callback(content: bytes):
))

try:

await fdelay()

await ap.social.platform_api.relogin(qrcode_callback)
except Exception as e:
if isinstance(e, nonebot.exception.FinishedException):
Expand All @@ -93,6 +105,9 @@ async def qrcode_callback(content: bytes):
async def any_message_func(event: Event):
if not can_send_help_message(int(event.get_user_id())):
return

await fdelay()

await any_message.finish(nonebot.get_driver().config.campux_help_message)

# ========= 群聊 =========
Expand Down

0 comments on commit f23733e

Please sign in to comment.