Example #1
0
        public bool Analyze(MsgInformationEx MsgDTO, object[] param)
        {
            var aspect = param[0] as string;

            switch (aspect)
            {
            case "Group":
                var groupList = AIAnalyzer.AnalyzeGroup();
                MsgSender.PushMsg(MsgDTO, string.Join("\r\n", groupList.Select(g =>
                {
                    var groupNum = g.GroupNum == 0 ? "私聊" : GroupSettingSvc[g.GroupNum].Name;
                    return($"{groupNum}:{g.CommandCount}");
                })));
                return(true);

            case "Ai":
                var aiList = AIAnalyzer.AnalyzeAI();
                MsgSender.PushMsg(MsgDTO, string.Join("\r\n", aiList.Select(a => $"{a.AIName}:{a.CommandCount}")));
                return(true);

            case "Time":
                var timeList = AIAnalyzer.AnalyzeTime();
                MsgSender.PushMsg(MsgDTO, string.Join("\r\n", timeList.Select(t => $"{t.Hour}:{t.CommandCount}")));
                return(true);

            case "Command":
                var commandList = AIAnalyzer.AnalyzeCommand();
                MsgSender.PushMsg(MsgDTO, string.Join("\r\n", commandList.Select(c => $"{c.Command}:{c.CommandCount}")));
                return(true);
            }

            return(false);
        }
Example #2
0
        public override bool OnMsgReceived(MsgInformationEx MsgDTO)
        {
            if (base.OnMsgReceived(MsgDTO))
            {
                return(true);
            }

            if (MsgDTO.Type == MsgType.Private)
            {
                return(false);
            }

            var result = ProcessHello(MsgDTO);

            result |= ProcessMultiMediaHello(MsgDTO);

            if (result)
            {
                AIAnalyzer.AddCommandCount(new CmdRec()
                {
                    FunctionalAi = AIName,
                    Command      = "HelloOverride",
                    GroupNum     = MsgDTO.FromGroup,
                    BindAi       = MsgDTO.BindAi
                });
            }

            return(false);
        }
Example #3
0
        public override bool OnMsgReceived(MsgInformationEx MsgDTO)
        {
            if (base.OnMsgReceived(MsgDTO))
            {
                return(true);
            }

            if (MsgDTO.Type == MsgType.Private)
            {
                return(false);
            }

            if (!ParseFormat(MsgDTO))
            {
                return(false);
            }

            AIAnalyzer.AddCommandCount(new CmdRec()
            {
                FunctionalAi = AIName,
                Command      = "DiceOverride",
                GroupNum     = MsgDTO.FromGroup,
                BindAi       = MsgDTO.BindAi
            });
            return(true);
        }
Example #4
0
        public bool Status(MsgInformationEx MsgDTO, object[] param)
        {
            var startTime = AIAnalyzer.Sys_StartTime;
            var span      = DateTime.Now - startTime;
            var timeStr   = span.ToString(@"dd\.hh\:mm\:ss");

            var msg = $@"系统已成功运行{timeStr}
最近{AIAnalyzer.AnalyzeHours}小时内共处理{AIAnalyzer.GetCommandCount()}条指令
遇到{AIAnalyzer.GetErrorCount()}个错误{PowerState(MsgDTO)}";

            MsgSender.PushMsg(MsgDTO, msg);
            return(true);
        }
Example #5
0
        public bool ExceptionMonitor(MsgInformationEx MsgDTO, object[] param)
        {
            var index = (long)param[0];

            var exMsg = AIAnalyzer.GetErrorMsg((int)index);

            if (string.IsNullOrEmpty(exMsg))
            {
                return(false);
            }

            MsgSender.PushMsg(MsgDTO, exMsg);
            return(true);
        }
Example #6
0
        public override bool OnMsgReceived(MsgInformationEx MsgDTO)
        {
            if (base.OnMsgReceived(MsgDTO))
            {
                return(true);
            }

            if (MsgDTO.Type == MsgType.Private)
            {
                return(false);
            }

            // 群组签到验证
            var groupInfo     = GroupSignInDic.ContainsKey(MsgDTO.FromGroup) ? GroupSignInDic[MsgDTO.FromGroup] : null;
            var signInContent = groupInfo == null ? "签到" : groupInfo.Content;

            if (MsgDTO.FullMsg != signInContent)
            {
                if (MsgDTO.FullMsg == "签到")
                {
                    MsgSender.PushMsg(MsgDTO, "请使用 今日签到内容 命令获取今天的签到口令!");
                }
                return(false);
            }

            AIAnalyzer.AddCommandCount(new CmdRec()
            {
                FunctionalAi = AIName,
                Command      = "SignInOverride",
                GroupNum     = MsgDTO.FromGroup,
                BindAi       = MsgDTO.BindAi
            });

            // 个人签到验证
            if (SignInSuccessiveRecord.IsTodaySigned(MsgDTO.FromGroup, MsgDTO.FromQQ))
            {
                MsgSender.PushMsg(MsgDTO, "你今天已经签过到啦!");
                return(true);
            }

            Sign(MsgDTO);
            return(true);
        }
Example #7
0
        public override bool OnMsgReceived(MsgInformationEx MsgDTO)
        {
            if (base.OnMsgReceived(MsgDTO))
            {
                return(true);
            }

            if (MsgDTO.Type == MsgType.Private)
            {
                return(false);
            }

            var atChecker = new AtChecker();

            if (atChecker.Check(MsgDTO.FullMsg, out _))
            {
                return(false);
            }

            CurCount++;
            if (CurCount < RepeatLimit)
            {
                return(false);
            }

            CurCount %= RepeatLimit;
            Repeat(MsgDTO);
            AIAnalyzer.AddCommandCount(new CmdRec()
            {
                FunctionalAi = AIName,
                Command      = "RepeatorOverride",
                GroupNum     = MsgDTO.FromGroup,
                BindAi       = MsgDTO.BindAi
            });
            return(true);
        }
Example #8
0
        private void Repeat(MsgInformationEx MsgDTO, PlusOneModel groupCache)
        {
            if (groupCache.MsgCache != MsgDTO.FullMsg)
            {
                groupCache.MsgCache          = MsgDTO.FullMsg;
                groupCache.IsAlreadyRepeated = false;

                return;
            }
            if (groupCache.IsAlreadyRepeated)
            {
                return;
            }

            AIAnalyzer.AddCommandCount(new CmdRec()
            {
                FunctionalAi = AIName,
                Command      = "PlusOneOverride",
                GroupNum     = MsgDTO.FromGroup,
                BindAi       = MsgDTO.BindAi
            });
            MsgSender.PushMsg(MsgDTO, MsgDTO.FullMsg);
            groupCache.IsAlreadyRepeated = true;
        }
Example #9
0
        public override bool OnMsgReceived(MsgInformationEx MsgDTO)
        {
            if (base.OnMsgReceived(MsgDTO))
            {
                return(true);
            }

            if (MsgDTO.Type == MsgType.Group)
            {
                var bindAi = BindAiSvc.AiDic.Values.FirstOrDefault(p => MsgDTO.FullMsg.Contains(CodeApi.Code_At(p.SelfNum)));
                if (bindAi == null)
                {
                    return(false);
                }

                MsgDTO.BindAi = bindAi.Name;
            }

            var stateCache = AliveStateSvc.GetState(MsgDTO.FromGroup, MsgDTO.FromQQ);

            if (stateCache != null)
            {
                MsgSender.PushMsg(MsgDTO, $"你已经死了({stateCache.Name})!复活时间:{stateCache.RebornTime:yyyy-MM-dd HH:mm:ss}", true);
                return(false);
            }

            var limitRecord = DailyLimitRecord.Get(MsgDTO.FromQQ, "Tuling");

            if (!limitRecord.Check(TulingDailyLimit))
            {
                MsgSender.PushMsg(MsgDTO, "今天太累了,明天再找我说话吧~", MsgDTO.Type == MsgType.Group);
                return(false);
            }
            limitRecord.Cache();
            limitRecord.Update();

            foreach (var aiNum in BindAiSvc.AllAiNums)
            {
                MsgDTO.FullMsg = MsgDTO.FullMsg.Replace(CodeApi.Code_At(aiNum), string.Empty);
            }

            string response = null;

            foreach (var tuling in ApiKeys.Select(_ => ApiKeys[CurTulingIndex]))
            {
                response = RequestMsg(MsgDTO, tuling.ApiKey);
                if (!string.IsNullOrEmpty(response))
                {
                    break;
                }

                CurTulingIndex = (CurTulingIndex + 1) % ApiKeys.Count;
            }

            if (string.IsNullOrEmpty(response))
            {
                MsgSender.PushMsg(MsgDTO, "今天太累了,明天再找我说话吧~", MsgDTO.Type == MsgType.Group);
                return(false);
            }

            AIAnalyzer.AddCommandCount(new CmdRec()
            {
                FunctionalAi = AIName,
                Command      = "TulingOverride",
                GroupNum     = MsgDTO.FromGroup,
                BindAi       = MsgDTO.BindAi
            });
            MsgSender.PushMsg(MsgDTO, response, MsgDTO.Type == MsgType.Group);
            return(true);
        }
Example #10
0
        private void ListenCallBack(MsgInformation info)
        {
            var source = "未知";

            if (info.FromGroup == 0)
            {
                source = "私聊";
            }
            else
            {
                var groupSetting = GroupSettingSvc[info.FromGroup];
                if (groupSetting != null)
                {
                    source = groupSetting.Name;
                }
            }

            if (info.FromGroup != 0)
            {
                var setting = GroupSettingSvc[info.FromGroup];
                if (setting == null || setting.BindAi != info.BindAi)
                {
                    return;
                }
            }

            var msg = $"[Info] {info.BindAi} {source} {QqNumReflectSvc[info.FromQQ]} {info.Msg}";

            Global.MsgPublish(msg);

            if (BindAiSvc[info.FromQQ] != null)
            {
                return;
            }

            switch (info.Information)
            {
            case InformationType.Message:
            case InformationType.CommandBack:
                WaiterUnit waitUnit = null;
                lock (_lockObj)
                {
                    if (UnitsDic.ContainsKey(info.FromGroup) && !UnitsDic[info.FromGroup].IsNullOrEmpty())
                    {
                        waitUnit = UnitsDic[info.FromGroup].FirstOrDefault(u => u.JudgePredicate(info));
                    }
                }

                if (waitUnit == null)
                {
                    CrossWorldAiSvc.OnMsgReceived(info);
                    break;
                }

                waitUnit.ResultInfos.Add(info);
                waitUnit.Signal.Set();
                AIAnalyzer.AddCommandCount(new CmdRec()
                {
                    FunctionalAi = "Waiter",
                    Command      = "WaiterCallBack",
                    GroupNum     = info.FromGroup,
                    BindAi       = info.BindAi
                });

                break;

            case InformationType.AuthCode:
                break;

            case InformationType.Error:
                AIAnalyzer.AddError(info.Msg);
                break;

            case InformationType.ReceiveMoney:
                CrossWorldAiSvc.OnMoneyReceived(JsonConvert.DeserializeObject <ChargeModel>(info.Msg));
                break;

            case InformationType.GroupMemberIncrease:
            case InformationType.GroupMemberDecrease:
                CrossWorldAiSvc.OnGroupMemberChanged(JsonConvert.DeserializeObject <GroupMemberChangeModel>(info.Msg));
                break;

            case InformationType.ConnectStateChange:
                var bindai = BindAiSvc[info.BindAi];
                bindai.IsConnected = bool.Parse(info.Msg);
                break;
            }
        }
Example #11
0
        public virtual bool OnMsgReceived(MsgInformationEx MsgDTO)
        {
            var query = ModuleDels.Where(c => c.Key.Command == MsgDTO.Command).ToList();

            if (query.IsNullOrEmpty())
            {
                return(false);
            }

            var cmdID = string.Empty;

            try
            {
                foreach (var(enterCommandAttribute, moduleDel) in query)
                {
                    if (!Check(enterCommandAttribute, MsgDTO, out var param))
                    {
                        continue;
                    }

                    AIAnalyzer.AddCommandCount(new CmdRec()
                    {
                        FunctionalAi = AIName,
                        Command      = enterCommandAttribute.Command,
                        GroupNum     = MsgDTO.FromGroup,
                        BindAi       = MsgDTO.BindAi
                    });

                    if (!StateCheck(MsgDTO))
                    {
                        return(true);
                    }

                    var limitRecord = DailyLimitRecord.Get(MsgDTO.FromQQ, enterCommandAttribute.ID);
                    var checkResult = DailyLimitCheck(enterCommandAttribute, MsgDTO, limitRecord);
                    if (!checkResult)
                    {
                        MsgSender.PushMsg(MsgDTO, $"你今天 【{enterCommandAttribute.Command}】 的次数已用完");
                        return(true);
                    }

                    cmdID = enterCommandAttribute.ID;
                    if (!CmdLockerSvc.TryLock(MsgDTO.FromQQ, enterCommandAttribute.ID, TimeSpan.FromMinutes(10)))
                    {
                        return(false);
                    }

                    var result = moduleDel(MsgDTO, param);

                    CmdLockerSvc.ReleaseLock(MsgDTO.FromQQ, enterCommandAttribute.ID);

                    if (!result)
                    {
                        return(true);
                    }

                    limitRecord.Cache();
                    limitRecord.Update();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
            finally
            {
                if (!string.IsNullOrEmpty(cmdID))
                {
                    CmdLockerSvc.ReleaseLock(MsgDTO.FromQQ, cmdID);
                }
            }

            return(false);
        }