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)); }
public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope) { var routeMsg = scope.RouteMessage; if (routeMsg.MessageType == MessageType.Private) { return(null); } string[] ids = CoolQCode.GetAt(routeMsg.RawMessage); if (ids == null || !ids.Contains(routeMsg.ReportMeta.SelfId)) { return(null); } if (StaticRandom.NextDouble() < 0.9) { return(routeMsg .ToSource("", true) .RandomDelaySeconds(5)); } else { var cqImg = new FileImage(Path.Combine(PandaDir, "at.jpg")); return(routeMsg.ToSource(cqImg.ToString())); } }
public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope) { var routeMsg = scope.RouteMessage; long groupId = Convert.ToInt64(routeMsg.GroupId); long userId = Convert.ToInt64(routeMsg.UserId); long discussId = Convert.ToInt64(routeMsg.DiscussId); var type = routeMsg.MessageType; string group, sender, message = routeMsg.Message.RawMessage; var data = CoolQDispatcher.Current.SessionList[(CoolQIdentity)routeMsg.Identity].GetDataAsync().Result; if (type == MessageType.Private) { group = "私聊"; sender = data.Name; } else if (type == MessageType.Discuss) { group = data.Name; sender = routeMsg.UserId; } else { var userInfo = data?.GroupInfo?.Members ?.FirstOrDefault(i => i.UserId == userId) ?? CoolQHttpApiClient.GetGroupMemberInfo(routeMsg.GroupId, routeMsg.UserId).Data; group = data?.Name; sender = string.IsNullOrEmpty(userInfo.Card) ? userInfo.Nickname : userInfo.Card; } Logger.Message($"({group}) {sender}:\r\n {CoolQCode.DecodeToString(message).Replace("\n", "\n ")}"); return(null); }
public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope) { var routeMsg = scope.RouteMessage; if (routeMsg.MessageType == MessageType.Private) { return(null); } var imgList = CoolQCode.GetImageInfo(routeMsg.RawMessage); if (imgList == null) { return(null); } string groupId = routeMsg.GroupId ?? routeMsg.DiscussId; if (!GroupDic.ContainsKey(groupId)) { GroupDic.GetOrAdd(groupId, new GroupSettings { GroupId = groupId, routeMsg = routeMsg }); } foreach (var item in imgList) { if (item.Extension.ToLower() == ".gif") { continue; } if (item.FileInfo.Exists) { GroupDic[groupId].PathQueue.Enqueue(item.FileInfo.FullName); } else { string path = HttpClient.SaveImageFromUrl(item.Url, System.Drawing.Imaging.ImageFormat.Jpeg); GroupDic[groupId].PathQueue.Enqueue(path); } #if DEBUG _totalCount++; #endif } if (GroupDic[groupId].Task == null || GroupDic[groupId].Task.IsCompleted || GroupDic[groupId].Task.IsCanceled) { GroupDic[groupId].Task = Task.Run(() => RunDetector(GroupDic[groupId])); #if DEBUG Logger.Info("[" + groupId + "] (熊猫) 共 " + _totalCount); #endif } return(null); }
/// <summary> /// 确定字体是否为空或有效。若为空或无效,则用默认语句替代。 /// </summary> /// <returns></returns> private string GetRealWord(FontFamily font, string pandaPath) { string word = PandaWord; if (word == null || word.Replace("\n", "").Replace("\r", "").Trim() == "") { word = _blankReply[StaticRandom.Next(0, _blankReply.Length)]; return(word); } word = CoolQCode.DecodeToString(PandaWord.Replace("!", "!").Replace("?", "?")); if (!IsLengthValid(word, pandaPath, font)) { word = _invalidReply[StaticRandom.Next(0, _invalidReply.Length)]; } return(word); }
public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope) { var routeMsg = scope.RouteMessage; if (routeMsg.MessageType == MessageType.Private) return null; string groupId = routeMsg.GroupId ?? routeMsg.DiscussId; if (!GroupDic.ContainsKey(groupId)) GroupDic.GetOrAdd(groupId, new GroupSettings { GroupId = groupId, routeMsg = routeMsg }); var imgList = CoolQCode.GetImageInfo(routeMsg.RawMessage); if (imgList == null) return null; foreach (var item in imgList) { if (item.Extension.ToLower() == ".gif") continue; if (item.FileInfo.Exists) { GroupDic[groupId].PathQueue.Enqueue(item.FileInfo.FullName); } else { var root = WebRequest.GetImageFromUrl(item.Url, item.Md5, item.Extension); GroupDic[groupId].PathQueue.Enqueue(root); } _totalCount++; } if (GroupDic[groupId].Task == null || GroupDic[groupId].Task.IsCompleted || GroupDic[groupId].Task.IsCanceled) { GroupDic[groupId].Task = Task.Run(() => RunDetector(GroupDic[groupId])); Logger.Info("[" + groupId + "] (龙图) 共 " + _totalCount); } return null; }
/// <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); }
public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope) { var routeMsg = scope.RouteMessage; if (!routeMsg.RawMessage.Equals("/转")) { return(null); } using (Session session = new Session(1000 * 60, routeMsg.Identity, routeMsg.UserId)) { SendMessage(routeMsg.ToSource("请发送图片,5张以内,1分钟内有效。", true)); try { CoolQRouteMessage routeMessage = (CoolQRouteMessage)session.GetMessage(); var infoList = CoolQCode.GetImageInfo(routeMessage.RawMessage); if (infoList == null) { return(routeMessage.ToSource("你发送的消息没有包含图片。")); } if (infoList.Length > 5) { return(routeMessage.ToSource("你发送的图片过多。")); } List <Image> imgList = infoList.Select(imgInfo => HttpClient.GetImageFromUrl(imgInfo.Url)) .ToList(); var sendList = HandleImage(imgList); return(routeMessage.ToSource(string.Join("\r\n", sendList))); } catch (TimeoutException) { return(null); } } }
public static void Query() { while (MessageQueue.Count != 0) { if (!MessageQueue.TryDequeue(out var routeMsg)) continue; var cmd = routeMsg.CommandName; const long cabbageId = 1335734629; string uname; if (cmd == "statme" || cmd == "bpme" || cmd == "mybp" || cmd == "costme" || cmd == "mycost") { BllUserRole bllUserRole = new BllUserRole(); List<TableUserRole> userInfo = bllUserRole.GetUserRoleByQq(long.Parse(routeMsg.UserId)); if (userInfo.Count == 0) DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(DefaultReply.IdNotBound, true)); uname = userInfo[0].CurrentUname; } else uname = routeMsg.ArgString; using (Session session = new Session(25000, new CoolQIdentity(cabbageId, MessageType.Private), cabbageId)) { DaylilyCore.Current.MessageDispatcher?.SendMessageAsync( new CoolQRouteMessage($"!{cmd.Replace("my", "").Replace("me", "")} {uname}", new CoolQIdentity(cabbageId, MessageType.Private))); try { CoolQRouteMessage result = (CoolQRouteMessage)session.GetMessage(); session.Timeout = 600; CoolQRouteMessage result2 = null; try { result2 = (CoolQRouteMessage)session.GetMessage(); } catch { // ignored } ImageInfo[] imgList = CoolQCode.GetImageInfo(result.RawMessage) ?? CoolQCode.GetImageInfo(result2?.RawMessage); if (imgList == null) { DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(result.RawMessage)); if (result2 != null) DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(result2.RawMessage)); continue; } //throw new IndexOutOfRangeException("查询失败:" + result.Message); var message = CoolQCode.DecodeToString(result.RawMessage); foreach (var item in imgList) { var str = new FileImage(new Uri(item.Url)); StringFinder sf = new StringFinder(message); sf.FindNext("[图片]"); string str1 = sf.Cut(); if (sf.FindNext("[图片]", false) > message.Length - 1) { message = str1 + str; continue; } sf.FindToLast(); string str2 = sf.Cut(); message = str1 + str + str2; } DaylilyCore.Current.MessageDispatcher?.SendMessageAsync( routeMsg.ToSource(message + "\r\n(查询由白菜支持)")); } catch (IndexOutOfRangeException e) { string msg = e.Message; DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(msg, true)); } catch (TimeoutException) { string msg = "查询失败,白菜没有搭理人家.."; DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(msg, true)); } catch (Exception ex) { string msg = "查询失败,未知错误。"; Logger.Exception(ex); DaylilyCore.Current.MessageDispatcher?.SendMessageAsync(routeMsg.ToSource(msg, true)); } // catch } // using } // while }
/// <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); } }
private static void ProcessRoomMessage(string json, ListenRunTimeConfig config) { try { JObject obj = JObject.Parse(json); if ((int)obj["status"] == 200) { IEnumerable <JToken> datas = obj.SelectTokens("$.content.data[*]"); long tmpTime = 0; DateTime msgTime = new DateTime(1996, 9, 10); foreach (JToken msgs in datas) { //本次消息时间 if ((long)msgs["msgTime"] >= tmpTime) { tmpTime = (long)msgs["msgTime"]; msgTime = DateTime.Parse(msgs["msgTimeStr"].ToString()); } JObject msg = JObject.Parse(msgs["extInfo"].ToString()); //长短时切换~ DateTime now = DateTime.Now; TimeSpan interval = now - msgTime; config.Delay = interval.TotalSeconds > PocketSetting.Interval ? config.LongDelay : config.ShortDelay; //首次运行,直接退出循环 if (config.First) { break; } //时间戳相等说明已经发过了,直接退出 if ((long)msgs["msgTime"] <= config.LastTime) { continue; } //消息分发 switch (msg["messageObject"].ToString()) { case "deleteMessage": //CQ.SendGroupMessage(qqGroup,"你的小偶像删除了一条口袋房间的消息"); break; case "text": if (config.TransmitText) { foreach (long qqGroup in config.QQGroups) { PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), msg["text"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString())); } } break; case "image": JObject img = JObject.Parse(msgs["bodys"].ToString()); string imgFilename = GetImage(img["url"].ToString()); if (imgFilename == "") { continue; } if (config.TransmitImage) { foreach (long qqGroup in config.QQGroups) { if (PocketPlugins.CommonCfg.CoolQAir) { PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n发送了图片:{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), img["url"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString())); } else { PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), CoolQCode.Image(imgFilename), config.IdolName, msgs["msgTimeStr"].ToString())); } } } break; case "faipaiText": if (config.TransmitFanpai) { foreach (long qqGroup in config.QQGroups) { if (msg.Property("fanpaiName") != null) { PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{4}\r\n{0} 回复:{1}\r\n来源:{5}房间 发送时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), msgs["msgTimeStr"].ToString(), "", msg["faipaiContent"].ToString(), config.IdolName)); } else { PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{4}\r\n{0} 回复:{1}\r\n来源:{5}房间 发送时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), msgs["msgTimeStr"].ToString(), "", msg["faipaiContent"].ToString(), config.IdolName)); } } } break; case "audio": JObject audio = JObject.Parse(msgs["bodys"].ToString()); string audioFilename = GetAudio(audio["url"].ToString(), audio["ext"].ToString()); if (audioFilename == "") { continue; } if (config.TransmitAudio) { foreach (long qqGroup in config.QQGroups) { if (PocketPlugins.CommonCfg.CoolQAir) { PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n发送了语音:{1} 来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), audio["url"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString())); } else { PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}", CoolQCode.ShareRecord(audioFilename))); } //PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n{1} 来源:口袋房间", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename))); } } break; case "videoRecord": JObject video = JObject.Parse(msgs["bodys"].ToString()); if (config.TransmitVideo) { foreach (long qqGroup in config.QQGroups) { PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}发送了一个视频,请点击下面链接查看\r\n地址:{1}", msg["senderName"].ToString(), video["url"].ToString())); } } break; case "jujuLive": if (config.TransmitGift) { foreach (long qqGroup in config.QQGroups) { PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), msg["text"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString())); } } break; case "live": if (config.TransmitLive) { foreach (long qqGroup in config.QQGroups) { PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("滴滴滴,你的小偶像{0}开直播辣!\r\n使用口袋PC观看体验更好哦!\r\n或登录网页收看https://h5.48.cn/2017appshare/memberLiveShare/index.html?id={1}", config.IdolName, msg["referenceObjectId"].ToString())); } } break; case "diantai": if (config.TransmitLive) { foreach (long qqGroup in config.QQGroups) { PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("滴滴滴,你的小偶像{0}开电台辣!\r\n使用口袋PC观看体验更好哦!\r\n或登录网页收看https://h5.48.cn/2017appshare/memberLiveShare/index.html?id={1}", config.IdolName, msg["referenceObjectId"].ToString())); } } break; case "idolFlip": if (config.TransmitFlip) { foreach (long qqGroup in config.QQGroups) { if (int.Parse(msg["idolFlipType"].ToString()) == 3) { PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}回答了匿名聚聚的提问:\r\n{1}\r\n回答请进入房间查看", msg["senderName"].ToString(), msg["idolFlipContent"].ToString())); } else { PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}回答了{2}的提问:\r\n{1}\r\n回答请进入房间查看", msg["senderName"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString())); } } } break; } } if (tmpTime != 0) { config.LastTime = tmpTime; } } if (config.First) { config.First = false; } } catch (Exception ex) { WriteLog(ex); } }
private static void ProcessRoomMessage(string json, ListenRunTimeConfig config) { try { JObject obj = JObject.Parse(json); if ((int)obj["status"] == 200) { IEnumerable <JToken> datas = obj.SelectTokens("$.content.data[*]"); long tmpTime = 0; DateTime msgTime = new DateTime(1996, 9, 10); string totalTempMsg = ""; string templeMsgTime = ""; int sort = 1; foreach (JToken msgs in datas) { msgTime = DateTime.Parse(msgs["msgTimeStr"].ToString()); //★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ JObject msg = JObject.Parse(msgs["extInfo"].ToString()); string[] realtime = msgs["msgTimeStr"].ToString().Split(' '); string[] idolnamewords = msg["senderName"].ToString().Split('-'); string idolname = idolnamewords[idolnamewords.Length - 1]; string roomrecentmsg = ""; DateTime dt = new DateTime(1970, 1, 1, 8, 0, 0).AddMilliseconds(((Convert.ToDouble(config.LastTime)))); if (sort == 1) //处理第一条消息的逻辑 { tmpTime = (long)msgs["msgTime"]; //最后一次的第一条时间 templeMsgTime = realtime[1]; //首次消息日志开始 if (PocketPlugins.CommonCfg.msglog == true) { //PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "true"); try { switch (msg["messageObject"].ToString()) { case "deleteMessage": roomrecentmsg = "你的小偶像删除了一条消息"; break; case "text": if (config.TransmitText) { roomrecentmsg = String.Format("{0}:{1}", idolname, msg["text"].ToString()); } break; case "image": JObject img = JObject.Parse(msgs["bodys"].ToString()); if (config.TransmitImage) { roomrecentmsg = String.Format("{0}:\r\n发送图片:{1}", idolname, img["url"].ToString()); } break; case "faipaiText": if (config.TransmitFanpai) { if (msg.Property("fanpaiName") != null) { roomrecentmsg = String.Format("{2} : {3}\r\n{0} 回复 : {1}", idolname, msg["messageText"].ToString(), msg["fanpaiName"].ToString(), msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg; } else { JObject Name = JObject.Parse(GetUserName(msg["faipaiUserId"].ToString())); roomrecentmsg = String.Format("{2} : {3}\r\n{0} 回复 : {1}", idolname, msg["messageText"].ToString(), Name["nickName"].ToString(), msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg; } } break; case "audio": JObject audio = JObject.Parse(msgs["bodys"].ToString()); string audioFilename = GetAudio(audio["url"].ToString(), audio["ext"].ToString()); if (audioFilename == "") { continue; } if (config.TransmitAudio) { roomrecentmsg = String.Format("{0}:\r\n发送语音:{1}", idolname, audio["url"].ToString()); } break; case "videoRecord": JObject video = JObject.Parse(msgs["bodys"].ToString()); if (config.TransmitVideo) { roomrecentmsg = string.Format("{0}发送视频。\r\n地址:{1}\r\n", idolname, video["url"].ToString()); } break; case "jujuLive": if (config.TransmitGift) { roomrecentmsg = string.Format("{0}{1}", idolname, msg["text"].ToString()); } break; case "live": roomrecentmsg = string.Format("直播提醒:你的小心肝{0}的直播:{1}!\r\n请打开口袋48观看哟!设置关注词(直播提醒)不错过直播哦!", idolname, msg["referenceContent"].ToString()); break; case "diantai": if (config.TransmitLive) { roomrecentmsg = string.Format("直播提醒:你的小心肝{0}突然开了个电台:{1}!\r\n快打开口袋48观看哟!设置关注词(直播提醒)不错过直播哦!", idolname, msg["referenceContent"].ToString()); } break; case "idolFlip": if (config.TransmitFlip) { //} if (int.Parse(msg["idolFlipType"].ToString()) == 3) { roomrecentmsg = string.Format("{0} {1}:\r\n{2}", idolname, msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString()); } else { roomrecentmsg = string.Format("{0} 回答 {3} 的提问:\r\n{2}", idolname, msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString()); } } break; default: File.AppendAllText("unknowmsg.log", msgs.ToString() + "\r\n"); roomrecentmsg = "未知类型消息,请检查unknowmsg.log"; break; } PocketPlugins.Api.AddLog(10, CoolQLogLevel.Debug, config.LastTime.ToString() + " " + msgs["msgTime"].ToString()); roomrecentmsg = "上次最晚时间:" + dt.ToString() + " 本次最新时间:" + msgs["msgTimeStr"].ToString() + "\r\n" + config.IdolName + "房间:(调试信息,勾选取消可去除本消息。仅供调试测试查看\r\n" + roomrecentmsg; PocketPlugins.Api.AddLog(10, CoolQLogLevel.Debug, roomrecentmsg); //panel.textBox_recentmsg.Text = roomrecentmsg; } catch (Exception ex) { PocketPlugins.Api.AddLog(10, CoolQLogLevel.Debug, ex.ToString()); } } // else // PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "false"); //else //PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, "false"); //首次消息日志结束 } sort++; //长短时切换~ DateTime now = DateTime.Now; TimeSpan interval = now - msgTime; config.Delay = interval.TotalSeconds > PocketSetting.Interval ? config.LongDelay : config.ShortDelay; //首次运行,直接退出循环 if (config.First) { //PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, string.Format("[{0}]任务启动", IdolName)); config.LastTime = tmpTime; dt = new DateTime(1970, 1, 1, 8, 0, 0).AddMilliseconds(((Convert.ToDouble(config.LastTime)))); PocketPlugins.Api.AddLog(10, CoolQLogLevel.Debug, config.IdolName + " 初始化结束,最新一条消息时间为:" + config.LastTime.ToString() + " " + dt.ToString()); break; } //时间戳相等说明已经发过了,直接退出 if ((long)msgs["msgTime"] <= config.LastTime) { //continue; config.LastTime = tmpTime; break;//一旦小于时间直接终止遍历,赋值最后一次时间。 } //消息分发 switch (msg["messageObject"].ToString()) { case "deleteMessage": totalTempMsg = "你的小偶像删除了一条消息" + "\r\n" + totalTempMsg; //CQ.SendGroupMessage(qqGroup,"你的小偶像删除了一条口袋房间的消息"); break; case "text": if (config.TransmitText) { //foreach (long qqGroup in config.QQGroups) //{ // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), msg["text"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString())); //} if (config.IdolName != msg["senderName"].ToString()) { //totalTempMsg = String.Format("{0}:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["text"].ToString(), realtime[1]) + "\r\n" + totalTempMsg; totalTempMsg = String.Format("{0}:{1}", idolname, msg["text"].ToString()) + "\r\n" + totalTempMsg; } else { //totalTempMsg = String.Format("{0}:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["text"].ToString(), realtime[1]) + "\r\n" + totalTempMsg; totalTempMsg = String.Format("{0}:{1}", idolname, msg["text"].ToString()) + "\r\n" + totalTempMsg; } } break; case "image": JObject img = JObject.Parse(msgs["bodys"].ToString()); string imgFilename = GetImage(img["url"].ToString()); if (imgFilename == "") { continue; } if (config.TransmitImage) { //foreach (long qqGroup in config.QQGroups) //{ // if (PocketPlugins.CommonCfg.CoolQAir) // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n发送了图片:{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), img["url"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString())); // else // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), CoolQCode.Image(imgFilename), config.IdolName, msgs["msgTimeStr"].ToString())); //} if (PocketPlugins.CommonCfg.CoolQAir) { //totalTempMsg = String.Format("{0}:\r\n发送图片:{1}\r\n时间:{2}", msg["senderName"].ToString(), img["url"].ToString(), realtime[1]) + "\r\n" + totalTempMsg; totalTempMsg = String.Format("{0}:\r\n发送图片:{1}", idolname, img["url"].ToString()) + "\r\n" + totalTempMsg; } else { //totalTempMsg = String.Format("{0}:\r\n{1}\r\n时间:{2}", msg["senderName"].ToString(), CoolQCode.Image(imgFilename), realtime[1]) + "\r\n" + totalTempMsg; totalTempMsg = String.Format("{0}:\r\n{1}", idolname, CoolQCode.Image(imgFilename)) + "\r\n" + totalTempMsg; } } break; case "faipaiText": if (config.TransmitFanpai) { //foreach (long qqGroup in config.QQGroups) //{ // if(msg.Property("fanpaiName") != null) // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{4}\r\n{0} 回复:{1}\r\n来源:{5}房间 发送时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), msgs["msgTimeStr"].ToString(), "", msg["faipaiContent"].ToString(), config.IdolName)); // else // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{4}\r\n{0} 回复:{1}\r\n来源:{5}房间 发送时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), msgs["msgTimeStr"].ToString(), "", msg["faipaiContent"].ToString(), config.IdolName)); // } JObject Name = JObject.Parse(GetUserName(msg["faipaiUserId"].ToString())); // PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, string.Format("[{0}]任务已经存在,退出", IdolName)); if (msg.Property("fanpaiName") != null) { //totalTempMsg = String.Format("{3} : {4}\r\n{0} 回复:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), realtime[1], msg["fanpaiName"].ToString(), msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg; totalTempMsg = String.Format("{2} : {3}\r\n{0} 回复 : {1}", idolname, msg["messageText"].ToString(), msg["fanpaiName"].ToString(), msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg; } else { //totalTempMsg = String.Format("{3} : {4}\r\n{0} 回复:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), Name["nickName"], msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg; totalTempMsg = String.Format("{2} : {3}\r\n{0} 回复 : {1}", idolname, msg["messageText"].ToString(), Name["nickName"].ToString(), msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg; } } break; case "audio": JObject audio = JObject.Parse(msgs["bodys"].ToString()); string audioFilename = GetAudio(audio["url"].ToString(), audio["ext"].ToString()); if (audioFilename == "") { continue; } if (config.TransmitAudio) { //foreach (long qqGroup in config.QQGroups) //{ // if (PocketPlugins.CommonCfg.CoolQAir) // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n发送了语音:{1} 来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), audio["url"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString())); // else // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}", CoolQCode.ShareRecord(audioFilename))); // //PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n{1} 来源:口袋房间", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename))); //} if (PocketPlugins.CommonCfg.CoolQAir) { //totalTempMsg = String.Format("{0}:\r\n发送语音:{1}\r\n时间:{2}", msg["senderName"].ToString(), audio["url"].ToString(), realtime[1]) + "\r\n" + totalTempMsg; totalTempMsg = String.Format("{0}:\r\n发送语音:{1}", idolname, audio["url"].ToString()) + "\r\n" + totalTempMsg; } else { //totalTempMsg = String.Format("{0}:\r\n{1}", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename)) + "\r\n" + totalTempMsg; //totalTempMsg = String.Format("{0}:\r\n{1}\r\n时间:{2}", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename), realtime[1]) + "\r\n" + totalTempMsg; totalTempMsg = String.Format("{0}:\r\n{1}", idolname, CoolQCode.ShareRecord(audioFilename)) + "\r\n" + totalTempMsg; } } break; case "videoRecord": JObject video = JObject.Parse(msgs["bodys"].ToString()); if (config.TransmitVideo) { //foreach (long qqGroup in config.QQGroups) //{ // PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}发送了一个视频,请点击下面链接查看\r\n地址:{1}", msg["senderName"].ToString(), video["url"].ToString())); //} totalTempMsg = string.Format("{0}发送视频。\r\n地址:{1}\r\n", idolname, video["url"].ToString()) + "\r\n" + totalTempMsg; } break; case "jujuLive": if (config.TransmitGift) { //foreach (long qqGroup in config.QQGroups) //{ // PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), msg["text"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString())); //} //totalTempMsg = string.Format("{0}{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["text"].ToString(), realtime[1]) + "\r\n" + totalTempMsg; totalTempMsg = string.Format("{0}{1}", idolname, msg["text"].ToString()) + "\r\n" + totalTempMsg; } break; case "live": if (config.TransmitLive) { if (config.Atall && !PocketPlugins.CommonCfg.CoolQAir) { totalTempMsg = string.Format("[CQ:at,qq=all]直播提醒:你的小心肝{0}的直播:{1}!\r\n请打开口袋48观看哟!设置关注词(直播提醒)不错过直播哦!", idolname, msg["referenceContent"].ToString()) + "\r\n" + totalTempMsg; } else { totalTempMsg = string.Format("直播提醒:你的小心肝{0}的直播:{1}!\r\n请打开口袋48观看哟!设置关注词(直播提醒)不错过直播哦!", idolname, msg["referenceContent"].ToString()) + "\r\n" + totalTempMsg; } } break; case "diantai": if (config.TransmitLive) { if (config.Atall && !PocketPlugins.CommonCfg.CoolQAir) { totalTempMsg = string.Format("[CQ:at,qq=all]直播提醒:你的小心肝{0}的电台:{1}!\r\n快打开口袋48观看哟!设置关注词(直播提醒)不错过直播哦!", idolname, msg["referenceContent"].ToString()) + "\r\n" + totalTempMsg; } else { totalTempMsg = string.Format("直播提醒:你的小心肝{0}的电台:{1}!\r\n快打开口袋48观看哟!设置关注词(直播提醒)不错过直播哦!", idolname, msg["referenceContent"].ToString()) + "\r\n" + totalTempMsg; } } break; case "idolFlip": if (config.TransmitFlip) { //foreach (long qqGroup in config.QQGroups) //{ // if (int.Parse(msg["idolFlipType"].ToString()) == 3) // PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}回答了匿名聚聚的提问:\r\n{1}\r\n回答请进入房间查看", msg["senderName"].ToString(), msg["idolFlipContent"].ToString())); // else // PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}回答了{2}的提问:\r\n{1}\r\n回答请进入房间查看", msg["senderName"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString())); //} if (int.Parse(msg["idolFlipType"].ToString()) == 3) { //totalTempMsg = string.Format("{0} {1}:\r\n{2}\r\n时间:{3}", msg["senderName"].ToString(), msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString(), realtime[1]) + "\r\n" + totalTempMsg; totalTempMsg = string.Format("{0} {1}:\r\n{2}", idolname, msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString()) + "\r\n" + totalTempMsg; } else { //totalTempMsg = string.Format("{0} 回答 {3} 的提问:\r\n{2}\r\n时间:{4}", msg["senderName"].ToString(), msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString(),realtime[1]) + "\r\n" + totalTempMsg; totalTempMsg = string.Format("{0} 回答 {3} 的提问:\r\n{2}", idolname, msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString()) + "\r\n" + totalTempMsg; } } break; default: File.AppendAllText("msg.log", msgs.ToString() + "\r\n"); break; } } if (totalTempMsg != "") { totalTempMsg = templeMsgTime + "" + config.IdolName + "房间:\r\n" + totalTempMsg; totalTempMsg = totalTempMsg.Substring(0, totalTempMsg.Length - 2); foreach (long qqGroup in config.QQGroups) { Common.sendgroupmsgChose(qqGroup, totalTempMsg); } if (PocketPlugins.Api.GetLoginQQ() == 2893276319) { totalTempMsg = totalTempMsg.Replace("[CQ:at,qq=all]", ""); PocketPlugins.Api.SendPrivateMsg(1691686998, totalTempMsg); } } } if (config.First) { config.First = false; } } catch (Exception ex) { WriteLog(ex); } }
public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope) { var routeMsg = scope.RouteMessage; // 查黄图 if (routeMsg.Group == null || routeMsg.GroupId != "133605766") { return(null); } var imgList = CoolQCode.GetImageInfo(routeMsg.RawMessage); if (imgList == null) { return(null); } List <string> urlList = new List <string>(); List <CosObject> cacheList = new List <CosObject>(); foreach (var item in imgList) { if (Md5List.Keys.Contains(item.Md5)) { cacheList.Add(Md5List[item.Md5]); } else if (item.Size > 1000 * 60) //60KB { urlList.Add(item.Url); } } if (urlList.Count == 0 && cacheList.Count == 0) { return(null); } Logger.Warn("发现了" + (urlList.Count + cacheList.Count) + "张图"); CosAnalyzer model = new CosAnalyzer { result_list = new List <CosObject>() }; if (urlList.Count != 0) { string str = Newtonsoft.Json.JsonConvert.SerializeObject(new { appid = "1252749411", url_list = urlList.ToArray() }); var abc = WebRequest.CreatePostHttpResponse( "http://service.image.myqcloud.com/detection/porn_detect", str, authorization: Signature.Get()); var respStr = WebRequest.GetResponseString(abc); model = Newtonsoft.Json.JsonConvert.DeserializeObject <CosAnalyzer>(respStr); } model.result_list.AddRange(cacheList); int i = 0; foreach (var item in model.result_list) { if (i < imgList.Length && !Md5List.Keys.Contains(imgList[i].Md5)) { Md5List.Add(imgList[i].Md5, item); } i++; switch (item.data.result) { case 0 when item.data.normal_score > item.data.hot_score && item.data.normal_score > item.data.porn_score && item.data.confidence > 40: continue; case 1: case 2: CoolQHttpApiClient.SetGroupBan(routeMsg.GroupId, routeMsg.UserId, 24 * 60 * 60); return(routeMsg.ToSource("...")); default: break; } if (item.data.porn_score >= item.data.hot_score && item.data.porn_score > 65) { return(AddCount(routeMsg)); } if (item.data.hot_score >= item.data.porn_score && item.data.hot_score > item.data.normal_score && item.data.hot_score > 80) { return(AddCount(routeMsg)); } break; } return(null); //if (user != "2241521134") return null; }
/// <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)); }
public void GetRoomMsg(ListenConfig listenConfig) { try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri("https://pjuju.48.cn/imsystem/api/im/v1/member/room/message/chat")); req.Method = "POST"; req.UserAgent = "okhttp/3.4.1"; JObject rss = new JObject( new JProperty("roomId", listenConfig.KDRoomId), new JProperty("lastTime", 0), new JProperty("limit", 10) ); string postJson = rss.ToString(); byte[] bytes = Encoding.UTF8.GetBytes(postJson); req.ContentType = "application/json"; req.ContentLength = bytes.Length; Stream reqstream = req.GetRequestStream(); reqstream.Write(bytes, 0, bytes.Length); HttpWebResponse response = (HttpWebResponse)req.GetResponse(); Stream streamReceive = response.GetResponseStream(); Encoding encoding = Encoding.UTF8; StreamReader streamReader = new StreamReader(streamReceive, encoding); string strResult = streamReader.ReadToEnd(); streamReceive.Dispose(); streamReader.Dispose(); JObject json = JObject.Parse(strResult); if ((int)json["status"] == 200) { IEnumerable <JToken> datas = json.SelectTokens("$.content.data[*]"); //记录本次最大时间戳 long tmpTime = 0; foreach (JToken msgs in datas) { //历史最后时间戳比对 if ((long)msgs["msgTime"] > listenConfig.Lasttime) { //本次消息时间 if ((long)msgs["msgTime"] > tmpTime) { tmpTime = (long)msgs["msgTime"]; } JObject msg = JObject.Parse(msgs["extInfo"].ToString()); //首次运行,直接退出循环 if (listenConfig.First) { break; } if ((long)msgs["msgTime"] < listenConfig.Lasttime) { break; } switch (msg["messageObject"].ToString()) { case "deleteMessage": //CQ.SendGroupMessage(qqGroup,"你的小偶像删除了一条口袋房间的消息"); break; case "text": CoolQApi.SendGroupMsg(listenConfig.QQGroup, String.Format("口袋房间:\r\n{0}:{1}\r\n发送时间:{2}", msg["senderName"].ToString(), msg["text"].ToString(), msgs["msgTimeStr"].ToString())); break; case "image": JObject img = JObject.Parse(msgs["bodys"].ToString()); string imgFilename = GetImage(img["url"].ToString()); if (imgFilename == "") { return; } CoolQApi.SendGroupMsg(listenConfig.QQGroup, String.Format("口袋房间:\r\n{0}:\r\n{1}", msg["senderName"].ToString(), CoolQCode.Image(imgFilename))); break; case "faipaiText": CoolQApi.SendGroupMsg(listenConfig.QQGroup, String.Format("口袋房间:\r\n翻牌辣!{3}:{4}\r\n{0} 回复:{1}\r\n被翻牌的大佬不来集资一发吗?" + listenConfig.HitYouText + " \r\n发送时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), msgs["msgTimeStr"].ToString(), msg["faipaiName"].ToString(), msg["faipaiContent"].ToString())); break; case "audio": JObject audio = JObject.Parse(msgs["bodys"].ToString()); string audioFilename = GetAudio(audio["url"].ToString(), audio["ext"].ToString()); if (audioFilename == "") { return; } CoolQApi.SendGroupMsg(listenConfig.QQGroup, String.Format("口袋房间:\r\n{0}:\r\n{1}", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename))); break; case "videoRecord": JObject video = JObject.Parse(msgs["bodys"].ToString()); CoolQApi.SendGroupMsg(listenConfig.QQGroup, string.Format("{0}发送了一个视频,请点击下面链接查看\r\n地址:{1}", msg["senderName"].ToString(), video["url"].ToString())); break; default: CoolQApi.SendGroupMsg(listenConfig.QQGroup, "你的小偶像有一条新消息,TeemoBot无法支持该类型消息,请打开口袋48查看~~并向开发反馈下~谢谢~"); break; } } } if (tmpTime != 0) { listenConfig.Lasttime = tmpTime; } } if (listenConfig.First) { listenConfig.First = false; } } catch (Exception ex) { File.AppendAllText("error.log", DateTime.Now.ToString() + "\r\n" + ex.ToString() + "\r\n" + ex.StackTrace + "\r\n"); } }
private static void ProcessRoomMessage(string json, ListenRunTimeConfig config) { try { JObject obj = JObject.Parse(json); if ((int)obj["status"] == 200) { IEnumerable <JToken> datas = obj.SelectTokens("$.content.data[*]"); long tmpTime = 0; DateTime msgTime = new DateTime(1996, 9, 10); string totalTempMsg = ""; foreach (JToken msgs in datas) { //本次消息时间 if ((long)msgs["msgTime"] >= tmpTime) { tmpTime = (long)msgs["msgTime"]; msgTime = DateTime.Parse(msgs["msgTimeStr"].ToString()); } JObject msg = JObject.Parse(msgs["extInfo"].ToString()); //长短时切换~ DateTime now = DateTime.Now; TimeSpan interval = now - msgTime; config.Delay = interval.TotalSeconds > PocketSetting.Interval ? config.LongDelay : config.ShortDelay; //首次运行,直接退出循环 if (config.First) { break; } //时间戳相等说明已经发过了,直接退出 if ((long)msgs["msgTime"] <= config.LastTime) { continue; } string[] realtime = msgs["msgTimeStr"].ToString().Split(' '); //消息分发 switch (msg["messageObject"].ToString()) { case "deleteMessage": totalTempMsg = "你的小偶像删除了一条消息" + "\r\n" + totalTempMsg; //CQ.SendGroupMessage(qqGroup,"你的小偶像删除了一条口袋房间的消息"); break; case "text": if (config.TransmitText) { //foreach (long qqGroup in config.QQGroups) //{ // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), msg["text"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString())); //} if (config.IdolName != msg["senderName"].ToString()) { totalTempMsg = String.Format("{0}:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["text"].ToString(), realtime[1]) + "\r\n" + totalTempMsg; } else { totalTempMsg = String.Format("{0}:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["text"].ToString(), realtime[1]) + "\r\n" + totalTempMsg; } } break; case "image": JObject img = JObject.Parse(msgs["bodys"].ToString()); string imgFilename = GetImage(img["url"].ToString()); if (imgFilename == "") { continue; } if (config.TransmitImage) { //foreach (long qqGroup in config.QQGroups) //{ // if (PocketPlugins.CommonCfg.CoolQAir) // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n发送了图片:{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), img["url"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString())); // else // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), CoolQCode.Image(imgFilename), config.IdolName, msgs["msgTimeStr"].ToString())); //} if (PocketPlugins.CommonCfg.CoolQAir) { totalTempMsg = String.Format("{0}:\r\n发送图片:{1}\r\n时间:{2}", msg["senderName"].ToString(), img["url"].ToString(), realtime[1]) + "\r\n" + totalTempMsg; } else { totalTempMsg = String.Format("{0}:\r\n{1}\r\n时间:{2}", msg["senderName"].ToString(), CoolQCode.Image(imgFilename), realtime[1]) + "\r\n" + totalTempMsg; } } break; case "faipaiText": if (config.TransmitFanpai) { //foreach (long qqGroup in config.QQGroups) //{ // if(msg.Property("fanpaiName") != null) // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{4}\r\n{0} 回复:{1}\r\n来源:{5}房间 发送时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), msgs["msgTimeStr"].ToString(), "", msg["faipaiContent"].ToString(), config.IdolName)); // else // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{4}\r\n{0} 回复:{1}\r\n来源:{5}房间 发送时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), msgs["msgTimeStr"].ToString(), "", msg["faipaiContent"].ToString(), config.IdolName)); // } JObject Name = JObject.Parse(GetUserName(msg["faipaiUserId"].ToString())); // PocketPlugins.Api.AddLog(10, CoolQLogLevel.Info, string.Format("[{0}]任务已经存在,退出", IdolName)); if (msg.Property("fanpaiName") != null) { totalTempMsg = String.Format("{3} : {4}\r\n{0} 回复:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), realtime[1], msg["fanpaiName"].ToString(), msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg; } else { totalTempMsg = String.Format("{3} : {4}\r\n{0} 回复:{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["messageText"].ToString(), realtime[1], Name["nickName"], msg["faipaiContent"].ToString()) + "\r\n" + totalTempMsg; } } break; case "audio": JObject audio = JObject.Parse(msgs["bodys"].ToString()); string audioFilename = GetAudio(audio["url"].ToString(), audio["ext"].ToString()); if (audioFilename == "") { continue; } if (config.TransmitAudio) { //foreach (long qqGroup in config.QQGroups) //{ // if (PocketPlugins.CommonCfg.CoolQAir) // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n发送了语音:{1} 来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), audio["url"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString())); // else // PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}", CoolQCode.ShareRecord(audioFilename))); // //PocketPlugins.Api.SendGroupMsg(qqGroup, String.Format("{0}:\r\n{1} 来源:口袋房间", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename))); //} if (PocketPlugins.CommonCfg.CoolQAir) { totalTempMsg = String.Format("{0}:\r\n发送语音:{1}\r\n时间:{2}", msg["senderName"].ToString(), audio["url"].ToString(), realtime[1]) + "\r\n" + totalTempMsg; } else { //totalTempMsg = String.Format("{0}:\r\n{1}", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename)) + "\r\n" + totalTempMsg; totalTempMsg = String.Format("{0}:\r\n{1}\r\n时间:{2}", msg["senderName"].ToString(), CoolQCode.ShareRecord(audioFilename), realtime[1]) + "\r\n" + totalTempMsg; } } break; case "videoRecord": JObject video = JObject.Parse(msgs["bodys"].ToString()); if (config.TransmitVideo) { //foreach (long qqGroup in config.QQGroups) //{ // PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}发送了一个视频,请点击下面链接查看\r\n地址:{1}", msg["senderName"].ToString(), video["url"].ToString())); //} totalTempMsg = string.Format("{0}发送视频。\r\n地址:{1}\r\n", msg["senderName"].ToString(), video["url"].ToString()) + "\r\n" + totalTempMsg; } break; case "jujuLive": if (config.TransmitGift) { //foreach (long qqGroup in config.QQGroups) //{ // PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}{1}\r\n来源:{2}房间 发送时间:{3}", msg["senderName"].ToString(), msg["text"].ToString(), config.IdolName, msgs["msgTimeStr"].ToString())); //} totalTempMsg = string.Format("{0}{1}\r\n时间:{2}", msg["senderName"].ToString(), msg["text"].ToString(), realtime[1]) + "\r\n" + totalTempMsg; } break; case "live": if (config.TransmitLive) { foreach (long qqGroup in config.QQGroups) { //PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("直播提醒:你的小心肝{0}突然开了个直播,直播哦不是电台!\r\n请打开口袋48观看哟!设置关键词关注“直播提醒”不错过直播哦!", config.IdolName, msg["referenceObjectId"].ToString())); PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("直播提醒:你的小心肝{0}突然开了个直播,直播哦不是电台!\r\n请打开口袋48观看哟!设置关键词关注“直播提醒”不错过直播哦!", config.IdolName)); } } break; case "diantai": if (config.TransmitLive) { foreach (long qqGroup in config.QQGroups) { //PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("直播提醒:你的小心肝{0}突然开了个电台,电台哦不是直播!\r\n请打开口袋48观看哟!设置关键词关注“直播提醒”不错过直播哦!", config.IdolName, msg["referenceObjectId"].ToString())); PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("直播提醒:你的小心肝{0}突然开了个电台,电台哦不是直播!\r\n请打开口袋48观看哟!设置关键词关注“直播提醒”不错过直播哦!", config.IdolName)); } } break; case "idolFlip": if (config.TransmitFlip) { //foreach (long qqGroup in config.QQGroups) //{ // if (int.Parse(msg["idolFlipType"].ToString()) == 3) // PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}回答了匿名聚聚的提问:\r\n{1}\r\n回答请进入房间查看", msg["senderName"].ToString(), msg["idolFlipContent"].ToString())); // else // PocketPlugins.Api.SendGroupMsg(qqGroup, string.Format("{0}回答了{2}的提问:\r\n{1}\r\n回答请进入房间查看", msg["senderName"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString())); //} } if (int.Parse(msg["idolFlipType"].ToString()) == 3) { totalTempMsg = string.Format("{0} {1}:\r\n{2}\r\n时间:{3}", msg["senderName"].ToString(), msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString(), realtime[1]) + "\r\n" + totalTempMsg; } else { totalTempMsg = string.Format("{0} 翻牌了 {3} 的问题:\r\n{2}\r\n时间:{4}", msg["senderName"].ToString(), msg["idolFlipTitle"].ToString(), msg["idolFlipContent"].ToString(), msg["idolFlipUserName"].ToString(), realtime[1]) + "\r\n" + totalTempMsg; } break; default: File.AppendAllText("msg.log", msgs.ToString() + "\r\n"); break; } } if (totalTempMsg != "") { totalTempMsg = config.IdolName + "口袋房间:\r\n" + totalTempMsg; totalTempMsg = totalTempMsg.Substring(0, totalTempMsg.Length - 2); foreach (long qqGroup in config.QQGroups) { PocketPlugins.Api.SendGroupMsg(qqGroup, totalTempMsg); } if (PocketPlugins.Api.GetLoginQQ() == 2893276319) { PocketPlugins.Api.SendPrivateMsg(1691686998, totalTempMsg); } } if (tmpTime != 0) { config.LastTime = tmpTime; } } if (config.First) { config.First = false; } } catch (Exception ex) { WriteLog(ex); } }