import os

import dotenv
import nonebot
from nonebot.adapters.console import Adapter as ConsoleAdapter
from nonebot.adapters.discord import Adapter as DiscordAdapter
from nonebot.adapters.minecraft import Adapter as MinecraftAdapter
from nonebot.adapters.onebot.v11 import Adapter as OnebotAdapter

from konabot.common.log import init_logger
from konabot.common.nb.exc import BotExceptionMessage
from konabot.common.path import LOG_PATH

dotenv.load_dotenv()
env = os.environ.get("ENVIRONMENT", "prod")
env_enable_console = os.environ.get("ENABLE_CONSOLE", "none")
env_enable_qq = os.environ.get("ENABLE_QQ", "none")
env_enable_discord = os.environ.get("ENABLE_DISCORD", "none")
env_enable_minecraft = os.environ.get("ENABLE_MINECRAFT", "none")


def main():
    init_logger(LOG_PATH, [
        BotExceptionMessage,
    ])

    nonebot.init()

    driver = nonebot.get_driver()

    if (env != "prod" and env != "test" and env_enable_console.upper() != "FALSE") or (env_enable_console.upper() == "TRUE"):
        driver.register_adapter(ConsoleAdapter)

    if env_enable_qq.upper() == "TRUE":
        driver.register_adapter(OnebotAdapter)

    if env_enable_discord.upper() == "TRUE":
        driver.register_adapter(DiscordAdapter)

    if env_enable_minecraft.upper() == "TRUE":
        driver.register_adapter(MinecraftAdapter)

    # nonebot.load_builtin_plugin("echo")
    nonebot.load_plugins("konabot/plugins")
    nonebot.load_plugin("nonebot_plugin_analysis_bilibili")

    nonebot.run()

if __name__ == "__main__":
    main()
