Esempio n. 1
0
        public static void OnMessage(MessageSource src, QMessage msg)
        {
            try
            {
                QMessage newMsg = msg;

                bool release = MiddlewareCore.OnMessage(ref src, ref newMsg);
                if (release)
                {
                    int stat = ModuleCore.OnMessage(src, newMsg);
                    ServiceCore.OnMessage(src, newMsg, msg, stat != -1, stat >= 0 ? ModuleCore.Modules[stat] : null);
                }
            }
            catch (Exception e)
            {
                StringBuilder sb = new(DateTime.Now.ToString());

                sb.Append($"\nMessage: ");
                if (src.IsGroup)
                {
                    sb.Append($"[{src.group!.ID}] ");
                }
                sb.Append($"[{src.user.ID}] ");
                sb.Append(msg);

                sb.Append($"\n{e}");

                if (BotReg.GetBool("CORE/LOG_ERROR", true) && BotAuth.HasOwner)
                {
                    _ = BotAPI.SendPrivateMessageAsync(BotAuth.Owner, new PlainMessage(sb.ToString()));
                }
                sb.Append("\n\n");
                File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "/log_error.txt", sb.ToString());
            }
        }
Esempio n. 2
0
 public static void OnFriendRequest(IApplyResponseArgs args)
 {
     if (BotReg.GetBool("CORE/ALLOW_FRIEND_REQUEST", false))
     {
         BotAPI.HandleNewFriendApplyAsync(args, FriendApplyAction.Allow).Wait();
         if (BotAuth.HasOwner && BotReg.GetBool("LOG/FRIEND_REQUEST", true))
         {
             _ = BotAPI.SendPrivateMessageAsync(BotAuth.Owner, new PlainMessage($"Accept friend request: {args.FromQQ}"));
         }
         _ = BotInfo.ReloadFriends();
     }
 }