fix: 修复nakuru无法运行的问题

This commit is contained in:
RockChinQ
2024-02-12 13:37:41 +08:00
parent abc19e78b8
commit 991a0aa5f6
3 changed files with 23 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
from __future__ import annotations
# 加了之后会导致https://github.com/Lxns-Network/nakuru-project/issues/25
# from __future__ import annotations
import asyncio
import typing
@@ -12,7 +13,6 @@ import nakuru.entities.components as nkc
from .. import adapter as adapter_model
from ...pipeline.longtext.strategies import forward
from ...core import app
class NakuruProjectMessageConverter(adapter_model.MessageConverter):
@@ -170,11 +170,11 @@ class NakuruProjectAdapter(adapter_model.MessageSourceAdapter):
listener_list: list[dict]
ap: app.Application
# ap: app.Application
cfg: dict
def __init__(self, cfg: dict, ap: app.Application):
def __init__(self, cfg: dict, ap):
"""初始化nakuru-project的对象"""
cfg['port'] = cfg['ws_port']
del cfg['ws_port']
@@ -261,8 +261,10 @@ class NakuruProjectAdapter(adapter_model.MessageSourceAdapter):
):
try:
source_cls = NakuruProjectEventConverter.yiri2target(event_type)
# 包装函数
async def listener_wrapper(app: nakuru.CQHTTP, source: NakuruProjectAdapter.event_converter.yiri2target(event_type)):
async def listener_wrapper(app: nakuru.CQHTTP, source: source_cls):
await callback(self.event_converter.target2yiri(source), self)
# 将包装函数和原函数的对应关系存入列表
@@ -275,7 +277,7 @@ class NakuruProjectAdapter(adapter_model.MessageSourceAdapter):
)
# 注册监听器
self.bot.receiver(self.event_converter.yiri2target(event_type).__name__)(listener_wrapper)
self.bot.receiver(source_cls.__name__)(listener_wrapper)
except Exception as e:
traceback.print_exc()
raise e
@@ -325,7 +327,7 @@ class NakuruProjectAdapter(adapter_model.MessageSourceAdapter):
await self.bot._run()
self.ap.logger.info("运行 Nakuru 适配器")
while True:
await asyncio.sleep(100)
await asyncio.sleep(1)
def kill(self) -> bool:
return False