public void StartQQBot() { // 初始化QQ机器人 logger.Info("初始化QQ机器人"); logger.Info($"机器人类型为:{botType.Type}"); client = new DumbQQClient(); botService = BotService.GetServiceInstance(botType.Name); // 好友消息回调 client.FriendMessageReceived += OnFriendMessage; // 群消息回调 client.GroupMessageReceived += OnGroupMessage; // 二维码登录 var result = QrCode.Login(client); switch (result) { case 0: logger.Info($"登录成功,{client.Nickname}!"); break; case 1: logger.Info($"登录失败,正在退出,{client.Nickname}!"); CloseQQClient(); Environment.Exit(1); return; } // 上线提醒 String hello = $"机器人{botName}开始工作,当前工作模式:{botService.Introduction}"; foreach (var group in client.Groups) { if (workGroups.Contains(group.Name)) { logger.Debug($"{group.Name}>>上线提醒:{hello}"); SendMessageToGroup(group.Id, hello); } } }
private static void CurrentDomain_ProcessExit(Object sender, EventArgs e) { logger.Debug("Exiting"); service.CloseQQClient(); }