mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
⚡️ 修改Bot
的创建时机
This commit is contained in:
parent
1619311abe
commit
6a85ed297c
@ -48,7 +48,10 @@ class _Bot:
|
|||||||
data = await self.queue.get()
|
data = await self.queue.get()
|
||||||
task = asyncio.create_task(data)
|
task = asyncio.create_task(data)
|
||||||
self.bg_tasks.add(task)
|
self.bg_tasks.add(task)
|
||||||
|
try:
|
||||||
task.add_done_callback(lambda _: self.bg_tasks.discard(task))
|
task.add_done_callback(lambda _: self.bg_tasks.discard(task))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
|
|
||||||
|
|
||||||
class Bot:
|
class Bot:
|
||||||
|
@ -44,10 +44,9 @@ async def handle_event(ws: _Bot, msg: MessageReceive):
|
|||||||
# 获取用户权限,越小越高
|
# 获取用户权限,越小越高
|
||||||
user_pm = await get_user_pml(msg)
|
user_pm = await get_user_pml(msg)
|
||||||
event = await msg_process(msg)
|
event = await msg_process(msg)
|
||||||
bot = Bot(ws, event)
|
|
||||||
print(f'[收到消息] {msg}')
|
print(f'[收到消息] {msg}')
|
||||||
pending = [
|
pending = [
|
||||||
_check_command(ws, bot, SL.lst[sv].TL[tr], event)
|
_check_command(ws, event, SL.lst[sv].TL[tr], event)
|
||||||
for sv in SL.lst
|
for sv in SL.lst
|
||||||
for tr in SL.lst[sv].TL
|
for tr in SL.lst[sv].TL
|
||||||
if (
|
if (
|
||||||
@ -64,7 +63,10 @@ async def handle_event(ws: _Bot, msg: MessageReceive):
|
|||||||
await asyncio.gather(*pending, return_exceptions=True)
|
await asyncio.gather(*pending, return_exceptions=True)
|
||||||
|
|
||||||
|
|
||||||
async def _check_command(ws: _Bot, Bot: Bot, trigger: Trigger, message: Event):
|
async def _check_command(
|
||||||
|
ws: _Bot, ev: Event, trigger: Trigger, message: Event
|
||||||
|
):
|
||||||
if trigger.check_command(message):
|
if trigger.check_command(message):
|
||||||
|
bot = Bot(ws, ev)
|
||||||
message = await trigger.get_command(message)
|
message = await trigger.get_command(message)
|
||||||
ws.queue.put_nowait(trigger.func(Bot, message))
|
ws.queue.put_nowait(trigger.func(bot, message))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user