feat: 彻底移除 yirimirai

This commit is contained in:
Junyan Qin 2024-11-15 20:03:49 +08:00
parent 16153dc573
commit 3239c9ec3f
No known key found for this signature in database
GPG Key ID: 22FE3AFADC710CEB
9 changed files with 21 additions and 169 deletions

View File

@ -125,3 +125,10 @@ class Application:
except Exception as e: except Exception as e:
self.logger.error(f"应用运行致命异常: {e}") self.logger.error(f"应用运行致命异常: {e}")
self.logger.debug(f"Traceback: {traceback.format_exc()}") self.logger.debug(f"Traceback: {traceback.format_exc()}")
async def scoped_shutdown(self, scopes: list[str]):
pass
async def shutdown(self):
for task in self.task_mgr.tasks:
task.cancel()

View File

@ -53,13 +53,17 @@ async def main(loop: asyncio.AbstractEventLoop):
# 挂系统信号处理 # 挂系统信号处理
import signal import signal
ap: app.Application
def signal_handler(sig, frame): def signal_handler(sig, frame):
print("[Signal] 程序退出.") print("[Signal] 程序退出.")
# ap.shutdown()
os._exit(0) os._exit(0)
signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGINT, signal_handler)
app_inst = await make_app(loop) app_inst = await make_app(loop)
ap = app_inst
await app_inst.run() await app_inst.run()
except Exception as e: except Exception as e:
traceback.print_exc() traceback.print_exc()

View File

@ -154,6 +154,9 @@ class TaskWrapper:
"result": self.assume_result().__str__() if self.assume_result() is not None else None, "result": self.assume_result().__str__() if self.assume_result() is not None else None,
}, },
} }
def cancel(self):
self.task.cancel()
class AsyncTaskManager: class AsyncTaskManager:

View File

@ -37,7 +37,7 @@ class PlatformManager:
async def initialize(self): async def initialize(self):
from .sources import yirimirai, nakuru, aiocqhttp, qqbotpy from .sources import nakuru, aiocqhttp, qqbotpy
async def on_friend_message(event: platform_events.FriendMessage, adapter: msadapter.MessageSourceAdapter): async def on_friend_message(event: platform_events.FriendMessage, adapter: msadapter.MessageSourceAdapter):
@ -195,3 +195,7 @@ class PlatformManager:
except Exception as e: except Exception as e:
self.ap.logger.error('平台适配器运行出错: ' + str(e)) self.ap.logger.error('平台适配器运行出错: ' + str(e))
self.ap.logger.debug(f"Traceback: {traceback.format_exc()}") self.ap.logger.debug(f"Traceback: {traceback.format_exc()}")
async def shutdown(self):
for adapter in self.adapters:
await adapter.kill()

View File

@ -328,5 +328,5 @@ class NakuruProjectAdapter(adapter_model.MessageSourceAdapter):
while True: while True:
await asyncio.sleep(1) await asyncio.sleep(1)
def kill(self) -> bool: async def kill(self) -> bool:
return False return False

View File

@ -591,5 +591,5 @@ class OfficialAdapter(adapter_model.MessageSourceAdapter):
self.ap.logger.info("运行 QQ 官方适配器") self.ap.logger.info("运行 QQ 官方适配器")
await self.bot.start(**self.cfg) await self.bot.start(**self.cfg)
def kill(self) -> bool: async def kill(self) -> bool:
return False return False

View File

@ -1,121 +0,0 @@
# import asyncio
# import typing
# from .. import adapter as adapter_model
# from ...core import app
# @adapter_model.adapter_class("yiri-mirai")
# class YiriMiraiAdapter(adapter_model.MessageSourceAdapter):
# """YiriMirai适配器"""
# bot: mirai.Mirai
# def __init__(self, config: dict, ap: app.Application):
# """初始化YiriMirai的对象"""
# self.ap = ap
# self.config = config
# if 'adapter' not in config or \
# config['adapter'] == 'WebSocketAdapter':
# self.bot = mirai.Mirai(
# qq=config['qq'],
# adapter=mirai.WebSocketAdapter(
# host=config['host'],
# port=config['port'],
# verify_key=config['verifyKey']
# )
# )
# elif config['adapter'] == 'HTTPAdapter':
# self.bot = mirai.Mirai(
# qq=config['qq'],
# adapter=mirai.HTTPAdapter(
# host=config['host'],
# port=config['port'],
# verify_key=config['verifyKey']
# )
# )
# else:
# raise Exception('Unknown adapter for YiriMirai: ' + config['adapter'])
# async def send_message(
# self,
# target_type: str,
# target_id: str,
# message: mirai.MessageChain
# ):
# """发送消息
# Args:
# target_type (str): 目标类型,`person`或`group`
# target_id (str): 目标ID
# message (mirai.MessageChain): YiriMirai库的消息链
# """
# task = None
# if target_type == 'person':
# task = self.bot.send_friend_message(int(target_id), message)
# elif target_type == 'group':
# task = self.bot.send_group_message(int(target_id), message)
# else:
# raise Exception('Unknown target type: ' + target_type)
# await task
# async def reply_message(
# self,
# message_source: mirai.MessageEvent,
# message: mirai.MessageChain,
# quote_origin: bool = False
# ):
# """回复消息
# Args:
# message_source (mirai.MessageEvent): YiriMirai消息源事件
# message (mirai.MessageChain): YiriMirai库的消息链
# quote_origin (bool, optional): 是否引用原消息. Defaults to False.
# """
# await self.bot.send(message_source, message, quote_origin)
# async def is_muted(self, group_id: int) -> bool:
# result = await self.bot.member_info(target=group_id, member_id=self.bot.qq).get()
# if result.mute_time_remaining > 0:
# return True
# return False
# def register_listener(
# self,
# event_type: typing.Type[mirai.Event],
# callback: typing.Callable[[mirai.Event, adapter_model.MessageSourceAdapter], None]
# ):
# """注册事件监听器
# Args:
# event_type (typing.Type[mirai.Event]): YiriMirai事件类型
# callback (typing.Callable[[mirai.Event], None]): 回调函数接收一个参数为YiriMirai事件
# """
# async def wrapper(event: mirai.Event):
# await callback(event, self)
# self.bot.on(event_type)(wrapper)
# def unregister_listener(
# self,
# event_type: typing.Type[mirai.Event],
# callback: typing.Callable[[mirai.Event, adapter_model.MessageSourceAdapter], None]
# ):
# """注销事件监听器
# Args:
# event_type (typing.Type[mirai.Event]): YiriMirai事件类型
# callback (typing.Callable[[mirai.Event], None]): 回调函数接收一个参数为YiriMirai事件
# """
# assert isinstance(self.bot, mirai.Mirai)
# bus = self.bot.bus
# assert isinstance(bus, mirai.models.bus.ModelEventBus)
# bus.unsubscribe(event_type, callback)
# async def run_async(self):
# self.bot_account_id = self.bot.qq
# return await MiraiRunner(self.bot)._run()
# async def kill(self) -> bool:
# return False

View File

@ -1,13 +1,5 @@
{ {
"platform-adapters": [ "platform-adapters": [
{
"adapter": "yiri-mirai",
"enable": false,
"host": "127.0.0.1",
"port": 8080,
"verifyKey": "yirimirai",
"qq": 123456789
},
{ {
"adapter": "nakuru", "adapter": "nakuru",
"enable": false, "enable": false,

View File

@ -9,43 +9,6 @@
"items": { "items": {
"type": "object", "type": "object",
"oneOf": [ "oneOf": [
{
"title": "YiriMirai 适配器",
"description": "用于接入 Mirai",
"properties": {
"adapter": {
"type": "string",
"const": "yiri-mirai"
},
"enable": {
"type": "boolean",
"default": false,
"description": "是否启用此适配器",
"layout": {
"comp": "switch",
"props": {
"color": "primary"
}
}
},
"host": {
"type": "string",
"default": "127.0.0.1"
},
"port": {
"type": "integer",
"default": 8080
},
"verifyKey": {
"type": "string",
"default": "yirimirai"
},
"qq": {
"type": "integer",
"default": 123456789
}
}
},
{ {
"title": "Nakuru 适配器", "title": "Nakuru 适配器",
"description": "用于接入 go-cqhttp", "description": "用于接入 go-cqhttp",