mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 03:32:33 +08:00
feat: 彻底移除 yirimirai
This commit is contained in:
parent
16153dc573
commit
3239c9ec3f
|
@ -125,3 +125,10 @@ class Application:
|
|||
except Exception as e:
|
||||
self.logger.error(f"应用运行致命异常: {e}")
|
||||
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()
|
||||
|
|
|
@ -53,13 +53,17 @@ async def main(loop: asyncio.AbstractEventLoop):
|
|||
# 挂系统信号处理
|
||||
import signal
|
||||
|
||||
ap: app.Application
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
print("[Signal] 程序退出.")
|
||||
# ap.shutdown()
|
||||
os._exit(0)
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
app_inst = await make_app(loop)
|
||||
ap = app_inst
|
||||
await app_inst.run()
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
|
|
|
@ -155,6 +155,9 @@ class TaskWrapper:
|
|||
},
|
||||
}
|
||||
|
||||
def cancel(self):
|
||||
self.task.cancel()
|
||||
|
||||
|
||||
class AsyncTaskManager:
|
||||
"""保存app中的所有异步任务
|
||||
|
|
|
@ -37,7 +37,7 @@ class PlatformManager:
|
|||
|
||||
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):
|
||||
|
||||
|
@ -195,3 +195,7 @@ class PlatformManager:
|
|||
except Exception as e:
|
||||
self.ap.logger.error('平台适配器运行出错: ' + str(e))
|
||||
self.ap.logger.debug(f"Traceback: {traceback.format_exc()}")
|
||||
|
||||
async def shutdown(self):
|
||||
for adapter in self.adapters:
|
||||
await adapter.kill()
|
||||
|
|
|
@ -328,5 +328,5 @@ class NakuruProjectAdapter(adapter_model.MessageSourceAdapter):
|
|||
while True:
|
||||
await asyncio.sleep(1)
|
||||
|
||||
def kill(self) -> bool:
|
||||
async def kill(self) -> bool:
|
||||
return False
|
|
@ -591,5 +591,5 @@ class OfficialAdapter(adapter_model.MessageSourceAdapter):
|
|||
self.ap.logger.info("运行 QQ 官方适配器")
|
||||
await self.bot.start(**self.cfg)
|
||||
|
||||
def kill(self) -> bool:
|
||||
async def kill(self) -> bool:
|
||||
return False
|
||||
|
|
|
@ -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
|
|
@ -1,13 +1,5 @@
|
|||
{
|
||||
"platform-adapters": [
|
||||
{
|
||||
"adapter": "yiri-mirai",
|
||||
"enable": false,
|
||||
"host": "127.0.0.1",
|
||||
"port": 8080,
|
||||
"verifyKey": "yirimirai",
|
||||
"qq": 123456789
|
||||
},
|
||||
{
|
||||
"adapter": "nakuru",
|
||||
"enable": false,
|
||||
|
|
|
@ -9,43 +9,6 @@
|
|||
"items": {
|
||||
"type": "object",
|
||||
"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 适配器",
|
||||
"description": "用于接入 go-cqhttp",
|
||||
|
|
Loading…
Reference in New Issue
Block a user