コード例 #1
0
        /// <summary>
        /// 处理群消息方法
        /// </summary>
        /// <param name="obj"></param>
        private void DealWithGroupMessage(object obj)
        {
            try
            {
                object[] paramaters = (object[])obj;

                long   fromGroup = (long)paramaters[2];
                long   fromQq    = (long)paramaters[3];
                string msg       = (string)paramaters[5];

                if (!m_QQdics.ContainsKey(fromGroup))
                {
                    //获取群成员 需要api权限160
                    List <GroupMemberInfo> memebers = CoolQApi.GetGroupMemberList(fromGroup).Model.ToList();
                    m_QQdics.Add(fromGroup, memebers.Select(t => t.Number).ToList());
                }

                List <long> qqList = CheckHasAtQQ(m_QQdics[fromGroup], msg);

                if (qqList.Count > 0)
                {
                    //禁言部分
                    if (msg.Contains("禁言") || msg.Contains("闭嘴") || msg.Contains("别说话") || msg.Contains("让你说话了么") || msg.Contains("ShutUp"))
                    {
                        foreach (var targetqq in qqList)
                        {
                            //全体成员跳过
                            if (targetqq == -1)
                            {
                                continue;
                            }

                            //对该机器人
                            if (targetqq == CoolQApi.GetLoginQQ())
                            {
                                CoolQApi.SendGroupMsg(fromGroup, CoolQCode.At(fromQq) + " 小逼,想禁言我?找死是吧!3分钟不谢!");
                                CoolQApi.SetGroupBan(fromGroup, fromQq, 180);
                                break;
                            }

                            //成功概率1/3
                            bool success = m_Rand.Next(4200) % 3 == 1;
                            if (success)
                            {
                                CoolQApi.SendGroupMsg(fromGroup, CoolQCode.At(fromQq) + "对" + CoolQCode.At(targetqq) + "释放了禁言术! 成功了!  " + CoolQCode.At(targetqq) + "被禁言3分钟!");
                                CoolQApi.SetGroupBan(fromGroup, targetqq, 180);
                            }
                            else
                            {
                                CoolQApi.SendGroupMsg(fromGroup, CoolQCode.At(fromQq) + "对" + CoolQCode.At(targetqq) + "释放了禁言术! 但是什么都没有发生!");
                            }
                        }
                    }
                    //踢出群部分
                    if (msg.Contains("滚") || msg.Contains("KickOut") || msg.Contains("踢了") || msg.Contains("飞踢") || msg.Contains("ThaiKick"))
                    {
                        foreach (var targetqq in qqList)
                        {
                            //全体成员跳过
                            if (targetqq == -1)
                            {
                                continue;
                            }
                            //对该机器人
                            if (targetqq == CoolQApi.GetLoginQQ())
                            {
                                CoolQApi.SendGroupMsg(fromGroup, CoolQCode.At(fromQq) + " 小逼,想踢我?找死是吧!翻滚吧!");
                                CoolQApi.SetGroupKick(fromGroup, fromQq, false);
                                break;
                            }
                            //成功概率1/5
                            bool success = m_Rand.Next(4200) % 5 == 1;
                            if (success)
                            {
                                CoolQApi.SendGroupMsg(fromGroup, CoolQCode.At(fromQq) + "狠狠踢了" + CoolQCode.At(targetqq) + "一脚! " + CoolQCode.At(targetqq) + "飞了好远,直到飞出了群");
                                CoolQApi.SetGroupKick(fromGroup, targetqq, false);
                            }
                            else
                            {
                                CoolQApi.SendGroupMsg(fromGroup, CoolQCode.At(fromQq) + "想要狠狠踢" + CoolQCode.At(targetqq) + "一脚,结果没有踢着,把脚崴了。好惨!");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                CoolQApi.AddLog(1, CoolQLogLevel.Error, e.Message);
            }
        }
コード例 #2
0
        public override int Enabled()
        {
            //面板重新启用时候判断
            if (ExitTask)
            {
                ExitTask = false;
                MemberIdCache.Clear();
            }


            if (File.Exists("config.ini"))
            {
                string config = File.ReadAllText("config.ini");
                try
                {
                    JObject configJson = JObject.Parse(config);
                    foreach (JObject idol in configJson.SelectTokens("$.Idols.[*]"))
                    {
                        ListenConfig listenConfig = new ListenConfig();
                        listenConfig.QQGroup         = long.Parse(idol["QQGroup"].ToString());
                        listenConfig.KDRoomId        = long.Parse(idol["KDRoomId"].ToString());
                        listenConfig.IdolName        = idol["IdolName"].ToString();
                        listenConfig.GetRoomMsgDelay = int.Parse(idol["GetRoomMsgDelay"].ToString());
                        listenConfig.GetLiveDelay    = int.Parse(idol["GetLiveDelay"].ToString());
                        listenConfig.GetWeiboDelay   = int.Parse(idol["GetWeiboDelay"].ToString());
                        listenConfig.HitYouText      = idol["NeedYou"].ToString();

                        MemberIdCache.Add(listenConfig.IdolName, listenConfig.QQGroup);
                        CoolQApi.AddLog(CoolQLogLevel.Info, listenConfig.IdolName + "info load ok:kid " + listenConfig.KDRoomId);
                        new Task(() => {
                            while (!ExitTask)
                            {
                                GetRoomMsg(listenConfig);
                                listenConfig.MsgCount++;
                                CoolQApi.AddLog(CoolQLogLevel.Debug, "get room msg count:" + listenConfig.MsgCount + " msg lasttime:" + listenConfig.Lasttime + " member:" + listenConfig.IdolName + " kdroomid" + listenConfig.KDRoomId);
                                Thread.Sleep(listenConfig.GetRoomMsgDelay);
                            }
                        }).Start();
                    }


                    new Task(() =>
                    {
                        while (!ExitTask)
                        {
                            GetLive();
                            LiveCount++;
                            CoolQApi.AddLog(CoolQLogLevel.Debug, "get live count:" + LiveCount);
                            Thread.Sleep(int.Parse(configJson["GetLiveDelay"].ToString()));
                        }
                    }).Start();
                }
                catch (Exception ex)
                {
                    File.AppendAllText("error.log", DateTime.Now.ToString() + "\r\n" + ex.ToString() + "\r\n" + ex.StackTrace + "\r\n");
                    CoolQApi.AddLog(CoolQLogLevel.Error, "请检查config.ini是否配置正确,七项缺一不可");
                    return(base.Enabled());
                }
            }
            else
            {
                CoolQApi.AddLog(CoolQLogLevel.Debug, "config error");
            }
            return(base.Enabled());
        }