"""
QQ机器人主入口
"""
import sys
from pathlib import Path

# 添加项目根目录到Python路径
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

from src.core.bot import MyClient, build_intents
from src.core.config import Config
from src.utils.logger import setup_logger


def main():
    """主函数"""
    # 设置日志
    logger = setup_logger()
    
    try:
        # 验证配置
        Config.validate()
        logger.info("配置验证通过")
        
        # 创建并启动机器人（最小权限，避免 4014 disallowed intents）
        logger.info("正在启动QQ机器人...")
        intents = build_intents()
        client = MyClient(intents=intents)
        client.run(appid=Config.BOT_APPID, secret=Config.BOT_SECRET)
        
    except ValueError as e:
        logger.error(f"配置错误: {e}")
        logger.error("请检查 .env 文件配置")
        sys.exit(1)
    except Exception as e:
        logger.error(f"启动失败: {e}", exc_info=True)
        sys.exit(1)


if __name__ == "__main__":
    main()
