private static StrangerInfo UpdatePrivateInfo(long id) { StrangerInfo obj; try { obj = CqApi.GetStrangerInfo(id.ToString()).Data; } catch { obj = InitInfo(); } return(obj ?? InitInfo()); StrangerInfo InitInfo() { var groupInfoV2 = new StrangerInfo { Nickname = id.ToString(), UserId = id, Age = "-1", Sex = "unknown", }; return(groupInfoV2); } }
public override CommonMessageResponse Message_Received(CommonMessage messageObj) { _cm = messageObj; if (List) { if (_cm.PermissionLevel == PermissionLevel.Root) { BllUserRole bllUserRole = new BllUserRole(); List <string> strs = new List <string>(); foreach (var item in _matchList) { var userInfo = bllUserRole.GetUserRoleByQq(long.Parse(item.Qq))[0]; string osuName = userInfo.CurrentUname; string id = item.SetId; string status; if (item.TargetQq == null) { status = "等待匹配"; } else { var info = bllUserRole.GetUserRoleByQq(long.Parse(item.TargetQq))[0]; string name = info.CurrentUname; status = $"已经和{name}匹配"; } if (id == null) { strs.Add(osuName + ": 闲置中。"); } else { strs.Add($"{osuName} 地图号: s/{id} {status}"); } } return(new CommonMessageResponse(string.Join("\r\n", strs), _cm)); } else { return(new CommonMessageResponse(LoliReply.RootOnly, _cm)); } } if (_cm.MessageType != MessageType.Private) { return(new CommonMessageResponse(LoliReply.PrivateOnly, _cm)); } try { using (_session = new Session(DefaultTimeout, _cm.Identity, _cm.UserId)) { BllUserRole bllUserRole = new BllUserRole(); List <TblUserRole> userInfo = bllUserRole.GetUserRoleByQq(long.Parse(messageObj.UserId)); if (userInfo.Count == 0) { return(new CommonMessageResponse("这个功能是需要绑定osu id的,请使用/setid完成绑定", messageObj, true)); } _osuId = userInfo[0].UserId.ToString(); try { // Init if (!_matchList.Select(q => q.Qq).Contains(_cm.UserId)) { const string intro = @"这是一个利用我进行自动化管理的M4M平台,只需将图的链接给我,你无需自己各处求摸。 我会地合理地从库中挑选,并与你和另一人互相推荐,以达成自动匹配M4M的目的。 每个人只能给我一张图,第二张图会覆盖第一张图,所以有什么图需摸要记得更新哦! 最重要的一点:这仅仅是一个平台,真正的交流还需面对面进行。"; SendMessage(new CommonMessageResponse(intro, _cm)); _matchList.Add(new MatchInfo(_cm.UserId)); SaveMatchList(); //apply Thread.Sleep(8000); } // Load _myInfo = _matchList.FirstOrDefault(q => q.Qq == _cm.UserId); _myInfo.IsOperating = true; _myInfo.LastUse = DateTime.Now; if (PluginManager.ApplicationList.FirstOrDefault(o => o.GetType() == typeof(M4MMatchNotice)) is M4MMatchNotice plugin) { if (M4MMatchNotice.Tipped.ContainsKey(_myInfo.Qq)) { M4MMatchNotice.Tipped[_myInfo.Qq] = DateTime.Now; } else { M4MMatchNotice.Tipped.TryAdd(_myInfo.Qq, DateTime.Now); } plugin.SaveSettings(); } // Confirm if (Confirm) { if (_myInfo.TargetQq == null) { return(new CommonMessageResponse("你尚且还没有正在进行的匹配。", _cm)); } var oInfo = _matchList.FirstOrDefault(q => q.Qq == _myInfo.TargetQq); if (DateTime.Now - oInfo.LastConfirmedTime < new TimeSpan(3, 0, 0)) { return(new CommonMessageResponse("你已在三小时之内发出过核对确认,请稍后再试。", _cm)); } oInfo.RequestBeConfirmed(); SaveMatchList(); //apply string nick = CqApi.GetStrangerInfo(oInfo.Qq).Data?.Nickname ?? "玩家"; SendMessage(new CommonMessageResponse($"你已经确认了{nick}({oInfo.Qq})的摸,请及时完成自己的摸!", _cm)); string nick2 = CqApi.GetStrangerInfo(_myInfo.Qq).Data?.Nickname ?? "玩家"; SendMessage(new CommonMessageResponse($"{nick2}({_myInfo.Qq})已经确认查收了你的摸。", new Identity(oInfo.Qq, MessageType.Private))); if (oInfo.LastConfirmedTime == null || _myInfo.LastConfirmedTime == null) { return(null); } Thread.Sleep(2000); oInfo.FinishedSet.Add(_myInfo.SetId); _myInfo.FinishedSet.Add(oInfo.SetId); oInfo.Finish(); _myInfo.Finish(); SendMessage(new CommonMessageResponse( $"你与{nick}({oInfo.Qq})的M4M ({oInfo.SetUrl}) 已完成,合作愉快!", new Identity(_myInfo.Qq, MessageType.Private))); SendMessage(new CommonMessageResponse( $"你与{nick2}({_myInfo.Qq})的M4M ({_myInfo.SetUrl}) 已完成,合作愉快!", new Identity(oInfo.Qq, MessageType.Private))); SaveMatchList(); //apply return(null); } // Finish else if (Finish) { var oInfo = _matchList.FirstOrDefault(q => q.Qq == _myInfo.TargetQq); if (DateTime.Now - _myInfo.LastNoticeTime < new TimeSpan(3, 0, 0)) { return(new CommonMessageResponse("你已在三小时之内发出过完成提醒,请稍后再试。", _cm)); } _myInfo.RequestFinishMatch(); SaveMatchList(); //apply string nick2 = CqApi.GetStrangerInfo(_myInfo.Qq).Data?.Nickname ?? "玩家"; SendMessage(new CommonMessageResponse( $"{nick2}({_myInfo.Qq})已经摸完了你的图:\r\n" + $"{oInfo.SetUrl}\r\n" + $"正在等待你的摸。\r\n" + $"请检查他的modding情况,回复 \"/m4m -确认\" 查收。\r\n" + $"若对方没有摸完,请不要查收。若有疑问请相互交流。", new Identity(oInfo.Qq, MessageType.Private))); return(new CommonMessageResponse("已发送完成请求。", _cm)); } // Cancel else if (Cancel) { var oInfo = _matchList.FirstOrDefault(q => q.Qq == _myInfo.TargetQq); if (oInfo.MatchTime == null) { oInfo.MatchTime = DateTime.Now; // 临时补救 } if (DateTime.Now - oInfo.MatchTime < new TimeSpan(7, 0, 0, 0)) { return(new CommonMessageResponse("取消失败,仅匹配持续一周以上才可取消。", _cm)); } string nick = CqApi.GetStrangerInfo(oInfo.Qq).Data?.Nickname ?? "玩家"; string nick2 = CqApi.GetStrangerInfo(_myInfo.Qq).Data?.Nickname ?? "玩家"; oInfo.FinishedSet.Add(_myInfo.SetId); _myInfo.FinishedSet.Add(oInfo.SetId); oInfo.Finish(); _myInfo.Finish(); SendMessage(new CommonMessageResponse( $"你与{nick}({oInfo.Qq})的M4M ({oInfo.SetUrl}) 已强制取消。", new Identity(_myInfo.Qq, MessageType.Private))); SendMessage(new CommonMessageResponse( $"你与{nick2}({_myInfo.Qq})的M4M ({_myInfo.SetUrl}) 已强制取消。", new Identity(oInfo.Qq, MessageType.Private))); SaveMatchList(); //apply return(null); } // No set after load if (_myInfo.Set == null) { return(SessionNoMap()); } // Matched Main string info; if (_myInfo.TargetQq != null) { var oInfo = _matchList.FirstOrDefault(q => q.Qq == _myInfo.TargetQq); string nick = CqApi.GetStrangerInfo(oInfo.Qq).Data?.Nickname ?? "玩家"; info = $"你已经成功和{nick}({oInfo.Qq})匹配\r\n" + $"· 你的信息:\r\n" + $" 地图地址:{_myInfo.SetUrl}\r\n" + $" 备注:{_myInfo.Mark}\r\n" + $"· 他的信息:\r\n" + $" 地图地址:{oInfo.SetUrl} \r\n" + $" 备注:{oInfo.Mark}\r\n" + $"当你摸图完成时,请使用 \"/m4m -完成\" 提醒对方审阅。\r\n" + $"当对方向你提出审阅请求后,请使用 \"/m4m -确认\" 完成审阅。\r\n" + $"若匹配持续超过一周,可使用 \"/m4m -取消\" 强制取消,且下次不会匹配到此图。"; return(new CommonMessageResponse(info, _cm)); } // Main info = $"· 你的信息:\r\n" + $" 地图地址:{_myInfo.SetUrl} \r\n" + $" 备注:{_myInfo.Mark}\r\n" + $"· 从下面的选项中选择一个你想进行的操作:\r\n" + $">【1】删除已发布的地图。\r\n" + $">【2】管理摸图偏好(当前:{_myInfo.GetPreferenceString()})。\r\n" + $">【3】开始进行m4m匹配。"; SendMessage(new CommonMessageResponse(info, _cm)); CommonMessage cmMain = SessionCondition("1", "2", "3"); switch (cmMain.Message) { case "1": SendMessage(new CommonMessageResponse("删除现有地图,确认吗?\r\n" + "【1】是 【2】否", _cm)); CommonMessage cmPub = SessionCondition("1", "2"); if (cmPub.Message == "1") { _myInfo.RemoveSet(); SaveMatchList(); //apply return(new CommonMessageResponse("删除成功。使用/m4m重新发布地图。", _cm)); } else { return(new CommonMessageResponse("你已取消操作。", _cm)); } case "2": if (SessionMode(out var sessionNoMap)) { return(sessionNoMap); } return(null); case "3": // core MatchInfo[] fullList = _matchList.Where(i => i.Qq != _myInfo.Qq && i.TargetQq == null && i.Set != null && !i.IsOperating && DateTime.Now - i.LastUse < new TimeSpan(7, 0, 0, 0)).ToArray(); if (fullList.Length == 0) { return(new CommonMessageResponse("目前没有可匹配的用户,也有可能是可匹配的用户同时在浏览m4m菜单。请等待他人匹配或稍后重试。", _cm)); } MatchInfo[] canModList = fullList.Where(i => i.Preference.Have(_myInfo.Modes) == 1 && _myInfo.Preference.Have(i.Modes) == 1 && !i.FinishedSet.Contains(_myInfo.SetId) && !_myInfo.FinishedSet.Contains(i.SetId)).ToArray(); if (canModList.Length == 0) { return(new CommonMessageResponse("目前没有与你情况相符合的用户,请等待他人匹配或稍后重试。", _cm)); } MatchInfo[] bestList = new MatchInfo[0]; int count = 0; while (bestList.Length == 0 && count < 120) { bestList = canModList.Where(i => Math.Abs(_myInfo.GetPreferanceTotalLength(i) - i.GetPreferanceTotalLength(_myInfo)) < count).ToArray(); count += 10; Thread.Sleep(1); } MatchInfo matchInfo; if (bestList.Length < 1) { SendMessage(new CommonMessageResponse("目前没有最佳的匹配,继续尝试不佳的匹配吗?\r\n" + "【1】是 【2】否", _cm)); CommonMessage cmContinue = SessionCondition("1", "2"); if (cmContinue.Message == "1") { MatchInfo[] notBestList = new MatchInfo[0]; int c = count; while (notBestList.Length == 0 && c < 10000) { notBestList = canModList.Where(i => Math.Abs(_myInfo.GetPreferanceTotalLength(i) - i.GetPreferanceTotalLength(_myInfo)) < c).ToArray(); c += 50; Thread.Sleep(1); } matchInfo = notBestList[Rnd.Next(notBestList.Length)]; } else { return(new CommonMessageResponse("你已取消操作。请等待他人匹配或稍后重试。", _cm)); } } else { matchInfo = bestList[Rnd.Next(bestList.Length)]; } var data1 = CqApi.GetStrangerInfo(matchInfo.Qq).Data; var data2 = CqApi.GetStrangerInfo(_myInfo.Qq).Data; string sub1 = "Ta", sub2 = "Ta"; string nick1 = "玩家", nick2 = "玩家"; if (data1 != null) { if (data1.Sex == "male") { sub1 = "他"; } else if (data1.Sex == "female") { sub1 = "她"; } nick1 = data1.Nickname; } if (data2 != null) { if (data2.Sex == "male") { sub2 = "他"; } else if (data2.Sex == "female") { sub2 = "她"; } nick2 = data2.Nickname; } _myInfo.Start(matchInfo.Qq); matchInfo.Start(_myInfo.Qq); SaveMatchList(); //apply const string tip = "当你选择完成摸图时,对方会收到一条消息确认你的mod,反之亦然。" + "当双方互批完成时,M4M成功结束!\r\n" + "若有疑问,请与对方互相协商。详细情况请使用 \"/m4m\"。"; SendMessage(new CommonMessageResponse($"{nick2}({_myInfo.Qq}) 与你成功匹配\r\n" + $"{sub2}的地图:{_myInfo.SetUrl}\r\n" + $"{sub2}的备注:{_myInfo.Mark}\r\n" + tip, new Identity(matchInfo.Qq, MessageType.Private))); return(new CommonMessageResponse($"你与{nick1}({matchInfo.Qq}) 成功匹配\r\n" + $"{sub1}的地图:{matchInfo.SetUrl}\r\n" + $"{sub1}的备注:{matchInfo.Mark}\r\n" + tip, _cm)); default: return(new CommonMessageResponse("你开始了?走了.jpg", _cm)); } } catch (TimeoutException) { return(new CommonMessageResponse("由于长时间未操作,已经自动取消m4m状态。", _cm)); } } } catch (NotSupportedException) { return(new CommonMessageResponse("你已在进行m4m状态中。", messageObj, true)); } finally { if (_myInfo != null) { _myInfo.IsOperating = false; SaveMatchList(); //apply } } }
public void Json_Received(object sender, JsonReceivedEventArgs args) { string json = args.JsonString; dynamic obj = JsonConvert.DeserializeObject(json); // 判断post类别 try { if (obj.post_type == "message") { // 私聊 if (obj.message_type == "private") { PrivateMsg parsedObj = JsonConvert.DeserializeObject <PrivateMsg>(json); Core.ReceiveMessage(parsedObj); } // 群聊 else if (obj.message_type == "group") { GroupMsg parsedObj = JsonConvert.DeserializeObject <GroupMsg>(json); Core.ReceiveMessage(parsedObj); } // 讨论组 else if (obj.message_type == "discuss") { DiscussMsg parsedObj = JsonConvert.DeserializeObject <DiscussMsg>(json); Core.ReceiveMessage(parsedObj); } } else if (obj.post_type == "notice") { // 群文件上传 if (obj.notice_type == "group_upload") { GroupFileUpload parsedObj = JsonConvert.DeserializeObject <GroupFileUpload>(json); // TODO } // 群管理员变动 else if (obj.notice_type == "group_admin") { GroupAdminChange parsedObj = JsonConvert.DeserializeObject <GroupAdminChange>(json); // TODO } // 群成员增加/减少 else if (obj.notice_type == "group_decrease" || obj.notice_type == "group_increase") { GroupMemberChange parsedObj = JsonConvert.DeserializeObject <GroupMemberChange>(json); // TODO } // 好友添加 else if (obj.notice_type == "friend_add") { FriendAdd parsedObj = JsonConvert.DeserializeObject <FriendAdd>(json); // TODO } } else if (obj.post_type == "request") { // 加好友请求 if (obj.request_type == "friend") { FriendRequest parsedObj = JsonConvert.DeserializeObject <FriendRequest>(json); // TODO,临时 CqApi.SendPrivateMessage("2241521134", string.Format("{0} ({1})邀请加我为好友", CqApi.GetStrangerInfo(parsedObj.UserId.ToString()).Data?.Nickname, parsedObj.UserId)); } // 加群请求/邀请 else if (obj.request_type == "group") { GroupInvite parsedObj = JsonConvert.DeserializeObject <GroupInvite>(json); // TODO,临时 if (parsedObj.SubType == "invite") { CqApi.SendPrivateMessage("2241521134", string.Format("{0} ({1})邀请我加入群{2}", CqApi.GetStrangerInfo(parsedObj.UserId.ToString()).Data?.Nickname, parsedObj.UserId, parsedObj.GroupId)); } } } } catch (Exception ex) { Logger.Exception(ex); } }