Exemple #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);
            }
        }
        /// <summary>
        /// 处理群聊消息
        /// </summary>
        /// <param name="subType">消息类型,目前固定为1</param>
        /// <param name="sendTime">消息发送时间的时间戳</param>
        /// <param name="fromGroup">消息来源群号</param>
        /// <param name="fromQq">发送此消息的QQ号码</param>
        /// <param name="fromAnonymous">发送此消息的匿名用户</param>
        /// <param name="msg">消息内容</param>
        /// <param name="font">消息所使用字体</param>
        /// <returns></returns>
        public override int ProcessGroupMessage(int subType, int sendTime, long fromGroup, long fromQq, string fromAnonymous, string msg, int font)
        {
            MyDictionaryUtil <long, int> myDictionaryUtil = new MyDictionaryUtil <long, int>();
            int result = myDictionaryUtil.GetValue(CacheData.BaseJson.CheckedQQQun, fromGroup);
            //说明用户回复的是指定的关键词
            string replayContent2 = null;

            if (result == 1)//监控此群
            {
                try
                {
                    replayContent2 = CacheData.BaseJson.Keys[msg + "-##-1-##-1"];
                    CoolQApi.SendGroupMsg(fromGroup, replayContent2);
                    return(base.ProcessGroupMessage(subType, sendTime, fromGroup, fromQq, fromAnonymous, msg, font));
                }
                catch (KeyNotFoundException ke)
                {
                    try
                    {
                        replayContent2 = CacheData.BaseJson.Keys[msg + "-##-1-##-0"];
                        CoolQApi.SendGroupMsg(fromGroup, replayContent2);
                        return(base.ProcessGroupMessage(subType, sendTime, fromGroup, fromQq, fromAnonymous, msg, font));
                    }
                    catch (KeyNotFoundException ke2)
                    {
                    }
                }
            }
            result = myDictionaryUtil.GetValue(CacheData.MovieConfig.CheckedQQQun, fromGroup);
            if (result == 1)
            {
                //
                string contentStr = msg.Trim();
                bool   b          = true;
                if (CacheData.MovieConfig.IsNeed)
                {
                    string at = CoolQCode.At(CoolQApi.GetLoginQQ());
                    if (msg.StartsWith(at))//需@机器人触发指令
                    {
                        contentStr = contentStr.Replace(at, "");
                        contentStr = contentStr.Trim();
                    }
                    else
                    {
                        b = false;
                    }
                }

                if (b)
                {
                    if (contentStr.StartsWith(CacheData.MovieConfig.SearchCommand))
                    {
                        String url = "";
                        try
                        {
                            string searchContent = contentStr.Substring(1);
                            if (string.IsNullOrWhiteSpace(searchContent))
                            {
                                //CoolQApi.SendPrivateMsg(fromQQ, "请输入要搜索的内容,例如:搜黑豹");
                                //CoolQApi.SendPrivateMsg(fromQQ, CacheData.MovieConfig.NoSearchedMovie);
                                replayContent2 = CacheData.MovieConfig.NoSearchedMovieInQun;
                                replayContent2 = replayContent2.Replace("{@用户}", CoolQCode.At(fromQq));
                                CoolQApi.SendGroupMsg(fromGroup, replayContent2);
                                return(base.ProcessGroupMessage(subType, sendTime, fromGroup, fromQq, fromAnonymous, msg, font));
                            }
                            else
                            {
                                //CoolQApi.SendPrivateMsg(fromQQ, "正在寻找资源,请稍等...");
                                List <KunyunInfo> list = KuYunSearch.Search(searchContent, CacheData.MovieConfig.ConvertLinkIndex);
                                if (list == null || list.Count == 0)
                                {
                                    //CoolQApi.SendPrivateMsg(fromQQ, "暂时未找到此资源");
                                    string temp = CacheData.MovieConfig.NoSearchedMovieInQun;
                                    temp = temp.Replace("{@用户}", CoolQCode.At(fromQq));
                                    CoolQApi.SendGroupMsg(fromGroup, temp);


                                    return(base.ProcessGroupMessage(subType, sendTime, fromGroup, fromQq, fromAnonymous, msg, font));
                                }
                                else if (list.Count == 1)//说明找到了具体电影的链接
                                {
                                    string        replayContent = CacheData.MovieConfig.HaveSearchedMovieInQun;
                                    StringBuilder sb            = new StringBuilder(" ");
                                    foreach (KunyunInfo k in list)
                                    {
                                        replayContent = replayContent.Replace("{电影名}", k.name);
                                        foreach (MovieInfo2 res in k.url)
                                        {
                                            if (k.resourceTYpe == 1)//m3u8
                                            {
                                                sb.Append(res.MovieName + "  " + MyLinkCoverter.CovertUrlInSuoIm(res.Url, true) + Environment.NewLine);
                                            }
                                            else//直接观看链接
                                            {
                                                sb.Append(res.MovieName + "  " + MyLinkCoverter.CovertUrlInSuoIm(res.Url, false) + Environment.NewLine);
                                            }
                                        }
                                    }
                                    replayContent = replayContent.Replace("{电影链接}", sb.ToString());
                                    replayContent = replayContent.Replace("{@用户}", CoolQCode.At(fromQq));
                                    CoolQApi.SendGroupMsg(fromGroup, replayContent);
                                    return(base.ProcessGroupMessage(subType, sendTime, fromGroup, fromQq, fromAnonymous, msg, font));
                                }
                                else//说明找到了相关的好几个电影
                                {
                                    StringBuilder sb = new StringBuilder("我找到了多个相关资源,请保持搜索格式,聊天回复以下具体某个资源获取观影链接:" + Environment.NewLine);
                                    foreach (KunyunInfo k in list)
                                    {
                                        sb.Append(CacheData.MovieConfig.SearchCommand + k.name + Environment.NewLine);
                                    }
                                    CoolQApi.SendGroupMsg(fromGroup, sb.ToString());
                                    return(base.ProcessGroupMessage(subType, sendTime, fromGroup, fromQq, fromAnonymous, msg, font));
                                }
                            }
                        }
                        catch (Exception e2)
                        {
                            //CoolQApi.SendPrivateMsg(fromQQ, "小喵出现问题,请过会再来尝试");
                            MyLogUtil.ErrToLog("接收群聊信息后处理过程出现异常,原因:" + e2);
                            return(base.ProcessGroupMessage(subType, sendTime, fromGroup, fromQq, fromAnonymous, msg, font));
                        }
                    }
                }
            }

            //mainForm.displayMsg2("处理群聊消息:" + subType + "," + sendTime + "," + fromGroup + "," + fromQq + "," + fromAnonymous + "," + msg + "," + font);

            return(base.ProcessGroupMessage(subType, sendTime, fromGroup, fromQq, fromAnonymous, msg, font));
        }