Skip to content

Commit

Permalink
feat: 彻底移除 yirimirai
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Nov 15, 2024
1 parent 16153dc commit 3239c9e
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 169 deletions.
7 changes: 7 additions & 0 deletions pkg/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,10 @@ async def never_ending():
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()
4 changes: 4 additions & 0 deletions pkg/core/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
3 changes: 3 additions & 0 deletions pkg/core/taskmgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def to_dict(self) -> dict:
"result": self.assume_result().__str__() if self.assume_result() is not None else None,
},
}

def cancel(self):
self.task.cancel()


class AsyncTaskManager:
Expand Down
6 changes: 5 additions & 1 deletion pkg/platform/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, ap: app.Application = None):

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):

Expand Down Expand Up @@ -195,3 +195,7 @@ async def exception_wrapper(adapter):
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()
2 changes: 1 addition & 1 deletion pkg/platform/sources/nakuru.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,5 @@ async def run_async(self):
while True:
await asyncio.sleep(1)

def kill(self) -> bool:
async def kill(self) -> bool:
return False
2 changes: 1 addition & 1 deletion pkg/platform/sources/qqbotpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,5 +591,5 @@ async def run_async(self):
self.ap.logger.info("运行 QQ 官方适配器")
await self.bot.start(**self.cfg)

def kill(self) -> bool:
async def kill(self) -> bool:
return False
121 changes: 0 additions & 121 deletions pkg/platform/sources/yirimirai.py

This file was deleted.

8 changes: 0 additions & 8 deletions templates/platform.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
37 changes: 0 additions & 37 deletions templates/schema/platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 3239c9e

Please sign in to comment.