Files
zhenxun_bot/zhenxun/builtin_plugins/restart/__init__.py
T

64 lines
1.9 KiB
Python
Raw Normal View History

import nonebot
2024-08-12 22:26:13 +08:00
from nonebot import on_command
from nonebot.adapters import Bot
from nonebot.params import ArgStr
from nonebot.permission import SUPERUSER
from nonebot.plugin import PluginMetadata
from nonebot.rule import to_me
from nonebot_plugin_uninfo import Uninfo
2024-08-12 22:26:13 +08:00
from zhenxun.configs.config import BotConfig
from zhenxun.configs.utils import PluginExtraData
2024-08-12 22:26:13 +08:00
from zhenxun.services.log import logger
2026-04-18 23:42:10 +08:00
from zhenxun.utils._restart_utils import handle_restart_connect, request_restart
2024-08-12 22:26:13 +08:00
from zhenxun.utils.enum import PluginType
from zhenxun.utils.message import MessageUtils
__plugin_meta__ = PluginMetadata(
name="重启",
description="执行脚本重启真寻",
2024-11-22 10:27:10 +08:00
usage="""
2024-08-12 22:26:13 +08:00
重启
""".strip(),
extra=PluginExtraData(
author="HibiKier", version="0.1", plugin_type=PluginType.SUPERUSER
).to_dict(),
2024-08-12 22:26:13 +08:00
)
_matcher = on_command(
"重启",
permission=SUPERUSER,
rule=to_me(),
priority=1,
block=True,
)
driver = nonebot.get_driver()
@_matcher.got(
"flag",
2024-11-22 10:27:10 +08:00
prompt=f"确定是否重启{BotConfig.self_nickname}?\n确定请回复[是|好|确定]\n(重启失败咱们将失去联系,请谨慎!)",
2024-08-12 22:26:13 +08:00
)
2024-11-22 10:27:10 +08:00
async def _(bot: Bot, session: Uninfo, flag: str = ArgStr("flag")):
if flag.lower() in {"true", "是", "好", "确定", "确定是"}:
2024-08-24 17:06:23 +08:00
await MessageUtils.build_message(
2024-08-24 19:32:52 +08:00
f"开始重启{BotConfig.self_nickname}..请稍等..."
2024-08-24 17:06:23 +08:00
).send()
2024-08-12 22:26:13 +08:00
logger.info("开始重启真寻...", "重启", session=session)
2026-04-18 23:42:10 +08:00
ok, message = await request_restart(
"command.matcher",
receipt_bot_id=str(bot.self_id),
receipt_user_id=str(session.user.id),
)
if not ok:
await MessageUtils.build_message(message).send()
2024-08-12 22:26:13 +08:00
else:
await MessageUtils.build_message("已取消操作...").send()
@driver.on_bot_connect
async def _(bot: Bot):
2026-04-18 23:42:10 +08:00
await handle_restart_connect(bot)