public override int ProcessGroupMemberIncrease(int subType, int sendTime, long fromGroup, long fromQq, long target) { CoolQApi.SendGroupMsg(fromGroup, $"{CoolQCode.At(fromQq)}\r\n新人捐赠时间,一分也是情,一分也是爱\r\nhttp://git.oschina.net/yks/Newbe.CQP.Framework\r\n{CoolQCode.Image("image.jpg")}"); return(base.ProcessGroupMemberIncrease(subType, sendTime, fromGroup, fromQq, target)); }
/// <summary> /// 处理群成员添加事件 /// </summary> /// <param name="subType">事件类型。1为管理员已同意;2为管理员邀请</param> /// <param name="sendTime">事件发生时间的时间戳</param> /// <param name="fromGroup">事件来源群号</param> /// <param name="fromQq">事件来源QQ</param> /// <param name="target">被操作的QQ</param> /// <returns></returns> public override int ProcessGroupMemberIncrease(int subType, int sendTime, long fromGroup, long fromQq, long target) { //mainForm.displayMsg2("处理群成员添加事件:" + subType + "," + sendTime + "," + fromGroup + "," + fromQq + "," + target); if (!string.IsNullOrWhiteSpace(CacheData.BaseJson.NewerEnterQun)) { string content = CacheData.BaseJson.NewerEnterQun.Replace("{@新用户}", CoolQCode.At(target)); //成员添加后,进行@用户,外加欢迎与 if (subType == 1)//账号为管理员,同意群员入群后触发 { //CoolQApi.SendGroupMsg(fromGroup, CoolQCode.At(target) + "欢迎加入我们的大家庭"); //mainForm.displayMsg2("---给用户发送欢迎语:"+ CoolQCode.At(target) + "欢迎加入我们的大家庭"); CoolQApi.SendGroupMsg(fromGroup, content); } else if (subType == 2)//群员邀请好友,好友同意并入群后触发 { //CoolQApi.SendGroupMsg(fromGroup, CoolQCode.At(fromQq) + "邀请" + CoolQCode.At(target) + "加入我们的大家庭,热烈欢迎"); //mainForm.displayMsg2("---给用户发送欢迎语:" + CoolQCode.At(fromQq) + "邀请" + CoolQCode.At(target) + "加入我们的大家庭,热烈欢迎"); CoolQApi.SendGroupMsg(fromGroup, content); } } return(base.ProcessGroupMemberIncrease(subType, sendTime, fromGroup, fromQq, target)); }
/// <summary> /// 获取信息中@的qq列表 /// </summary> /// <param name="allqqList">群里所有qq成员</param> /// <param name="msg">信息</param> /// <returns></returns> private List <long> CheckHasAtQQ(List <long> allqqList, string msg) { List <long> qqList = new List <long>(); bool flag = false; Dictionary <long, string> QQAtDic = new Dictionary <long, string>(); QQAtDic.Add(-1, CoolQCode.At(-1)); foreach (var tempqq in allqqList) { QQAtDic.Add(tempqq, CoolQCode.At(tempqq)); } foreach (var qqkey in QQAtDic.Keys) { if (msg.Contains(QQAtDic[qqkey])) { qqList.Add(qqkey); } } return(qqList); }
/// <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)); }