from nonebot import get_plugin_config
import nonebot
import nonebot.adapters
import nonebot.adapters.console
import nonebot.adapters.discord
import nonebot.adapters.onebot
from pydantic import BaseModel


class IsAdminConfig(BaseModel):
    admin_qq_group: list[int] = []
    admin_qq_account: list[int] = []
    admin_discord_channel: list[int] = []
    admin_discord_account: list[int] = []

cfg = get_plugin_config(IsAdminConfig)


def is_admin(event: nonebot.adapters.Event):
    if isinstance(event, nonebot.adapters.onebot.v11.MessageEvent):
        if event.user_id in cfg.admin_qq_account:
            return True
        if isinstance(event, nonebot.adapters.onebot.v11.GroupMessageEvent):
            if event.group_id in cfg.admin_qq_group:
                return True
    if isinstance(event, nonebot.adapters.discord.event.MessageEvent):
        if event.channel_id in cfg.admin_discord_channel:
            return True
        if event.user_id in cfg.admin_discord_account:
            return True
    if isinstance(event, nonebot.adapters.console.event.Event):
        return True

    return False
