from typing import Union
from nonebot.plugin import PluginMetadata

# onebot11 协议
from nonebot.adapters.onebot.v11 import Bot as V11Bot

from .config import driver, plugin_config
from .utils import send_notice, mail_config

__plugin_meta__ = PluginMetadata(
    name="QQbot断连通知",
    description="QQbot断连时的通知插件",
    usage="",
    type="application",
    # 发布必填，当前有效类型有：`library`（为其他插件编写提供功能），`application`（向机器人用户提供功能）。
    homepage="https://github.com/Cypas/nonebot_plugin_disconnect_notice",
    # 发布必填。
    supported_adapters={"~onebot.v11"},
)


@driver.on_bot_disconnect
async def disconnect(bot: V11Bot):
    """bot断连触发器"""
    send_notice(bot)


@driver.on_startup()
async def startup(bot: V11Bot):
    """插件载入时检测配置完整性"""
    if not mail_config.check_params():
        # 缺少参数,私聊通知主人
        super_user: str = plugin_config.SUPERUSERS[0]
        if super_user:
            await bot.send_private_msg(user_id=int(super_user), message="缺少mail配置项，请按照"
                                                                        "https://github.com"
                                                                        "/Cypasnonebot_plugin_disconnect_notice#%EF%B8%8F-%E9%85%8D%E7%BD%AE"
                                                                        "\n添加配置项后，再载入插件")
