app/liteyuki/liteyuki_main/core.py

62 lines
1.4 KiB
Python
Raw Normal View History

2024-03-24 22:04:51 +08:00
from nonebot import require
from nonebot.permission import SUPERUSER
2024-03-27 00:05:51 +08:00
from git import Repo
from liteyuki.utils.config import config
2024-03-27 00:05:51 +08:00
from liteyuki.utils.ly_typing import T_Bot, T_MessageEvent
from .reloader import Reloader
from ..utils.message import send_markdown
2024-03-24 22:04:51 +08:00
require("nonebot_plugin_alconna")
from nonebot_plugin_alconna import on_alconna, Alconna
cmd_liteyuki = on_alconna(
Alconna(
"liteyuki"
),
permission=SUPERUSER
)
2024-03-27 00:05:51 +08:00
update_liteyuki = on_alconna(
Alconna(
["update-liteyuki", "更新轻雪"]
),
permission=SUPERUSER
)
reload_liteyuki = on_alconna(
Alconna(
["reload-liteyuki", "重启轻雪"]
),
permission=SUPERUSER
)
@cmd_liteyuki.handle()
async def _(bot: T_Bot):
await cmd_liteyuki.finish(f"Hello, Liteyuki!\nBot {bot.self_id}\nLiteyukiID {config.get('liteyuki_id', 'No')}")
2024-03-27 00:05:51 +08:00
@update_liteyuki.handle()
async def _(bot: T_Bot, event: T_MessageEvent):
# 使用git pull更新
origins = ["origin", "origin2"]
repo = Repo(".")
for origin in origins:
try:
repo.remotes[origin].pull()
break
except Exception as e:
print(f"Pull from {origin} failed: {e}")
2024-03-27 00:15:12 +08:00
logs = repo.index.diff()
2024-03-27 00:05:51 +08:00
reply = "Liteyuki updated!\n"
reply += f"```\n{logs}\n```"
await send_markdown(reply, bot, event=event, at_sender=False)
@reload_liteyuki.handle()
async def _():
await reload_liteyuki.send("Liteyuki reloading")
Reloader.reload(3)