public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope) { var routeMsg = scope.RouteMessage; BllUserRole bllUserRole = new BllUserRole(); List <TableUserRole> userInfo = bllUserRole.GetUserRoleByQq(long.Parse(routeMsg.UserId)); if (userInfo.Count == 0) { return(routeMsg.ToSource(DefaultReply.IdNotBound, true)); } var id = userInfo[0].UserId; var client = new OldSiteApiClient(); var beatmapSets = client.GetBeatmapSetsByCreator(new UserId(id)) .Where(k => k.Beatmaps.FirstOrDefault()?.LastUpdate.AddDays(28) < DateTimeOffset.Now) .ToArray(); if (beatmapSets.Length == 0) { return(routeMsg.ToSource("你没有Graveyard Beatmaps!", true)); } var beatmapSet = beatmapSets[StaticRandom.Next(beatmapSets.Length)]; var cqMusic = new CustomMusic( $"https://osu.ppy.sh/s/{beatmapSet.Id}", $"https://b.ppy.sh/preview/{beatmapSet.Id}.mp3", beatmapSet.Title, $"{beatmapSet.Artist}\r\n({beatmapSet.FavouriteCount} fav)", $"https://b.ppy.sh/thumb/{beatmapSet.Id}l.jpg"); return(routeMsg .ToSource(cqMusic.ToString()) .ForceToSend()); }
public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope) { var routeMsg = scope.RouteMessage; string userName = Decode(UserName); if (string.IsNullOrEmpty(userName)) { return(routeMsg.ToSource(DefaultReply.ParamMissing)); } BllUserRole bllUserRole = new BllUserRole(); OldSiteApiClient client = new OldSiteApiClient(); int userNum = client.GetUser(UserComponent.FromUserName(UserName), out var userObj); if (userNum == 0) { return(routeMsg.ToSource(DefaultReply.IdNotFound, true)); } if (userNum > 1) { // ignored } var role = bllUserRole.GetUserRoleByQq(long.Parse(routeMsg.UserId)); if (role.Count != 0) { if (role[0].CurrentUname == userObj.UserName) { return(routeMsg.ToSource("我早就认识你啦.", true)); } string msg = role[0].CurrentUname + ",我早就认识你啦. 有什么问题请找Mother Ship(扔锅)"; return(routeMsg.ToSource(msg, true)); } var newRole = new TableUserRole { UserId = userObj.UserId, Role = "creep", QQ = long.Parse(routeMsg.UserId), LegacyUname = "[]", CurrentUname = userObj.UserName, IsBanned = false, RepeatCount = 0, SpeakingCount = 0, Mode = 0, }; var exist = bllUserRole.GetUserRoleByUid(userObj.UserId); if (exist != null && exist.Count > 0) { return(routeMsg.ToSource("这个账号已经被QQ: " + exist.First().QQ + "绑定啦,请联系妈船或对方QQ哦.")); } int c = bllUserRole.InsertUserRole(newRole); return(c < 1 ? routeMsg.ToSource("由于各种强大的原因,绑定失败..") : routeMsg.ToSource("明白了," + userObj.UserName + ",多好的名字呢.")); }
public override CommonMessageResponse Message_Received(CommonMessage messageObj) { string osuId = Decode(OsuId); if (string.IsNullOrEmpty(osuId)) { return(new CommonMessageResponse(LoliReply.ParamMissing, messageObj)); } BllUserRole bllUserRole = new BllUserRole(); int userNum = OldSiteApi.GetUser(OsuId, out var userObj); if (userNum == 0) { return(new CommonMessageResponse(LoliReply.IdNotFound, messageObj, true)); } if (userNum > 1) { // ignored } var role = bllUserRole.GetUserRoleByQq(long.Parse(messageObj.UserId)); if (role.Count != 0) { if (role[0].CurrentUname == userObj.username) { return(new CommonMessageResponse("我早就认识你啦.", messageObj, true)); } string msg = role[0].CurrentUname + ",我早就认识你啦. 有什么问题请找Mother Ship(扔锅)"; return(new CommonMessageResponse(msg, messageObj, true)); } var newRole = new TblUserRole { UserId = long.Parse(userObj.user_id), Role = "creep", QQ = long.Parse(messageObj.UserId), LegacyUname = "[]", CurrentUname = userObj.username, IsBanned = false, RepeatCount = 0, SpeakingCount = 0, Mode = 0, }; int c = bllUserRole.InsertUserRole(newRole); return(c < 1 ? new CommonMessageResponse("由于各种强大的原因,绑定失败..", messageObj) : new CommonMessageResponse("明白了," + userObj.username + ",多好的名字呢.", messageObj)); }
public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope) { var routeMsg = scope.RouteMessage; string id; string uname; OldSiteApiClient client = new OldSiteApiClient(); if (UserName == null) { BllUserRole bllUserRole = new BllUserRole(); List <TableUserRole> userInfo = bllUserRole.GetUserRoleByQq(long.Parse(routeMsg.UserId)); if (userInfo.Count == 0) { return(routeMsg.ToSource(DefaultReply.IdNotBound, true)); } id = userInfo[0].UserId.ToString(); uname = userInfo[0].CurrentUname; } else { int userNum = client.GetUser(UserComponent.FromUserName(UserName), out var userObj); if (userNum == 0) { return(routeMsg.ToSource(DefaultReply.IdNotFound, true)); } if (userNum > 1) { // ignored } id = userObj.UserId.ToString(); uname = userObj.UserName; } var eloInfo = EloApiClient.GetEloByUid(long.Parse(id)); switch (eloInfo.Result.ToLower()) { case "fail" when eloInfo.Message.ToLower() == "unranked": return(routeMsg.ToSource(uname + "大概没有参加什么mapping赛事..所以没有数据..", true)); case "fail": return(routeMsg.ToSource("未知错误..查询不到..", true)); default: return(routeMsg.ToSource( $"{eloInfo.User.Name},有elo点{Math.Round(eloInfo.User.Elo, 2)},当前#{eloInfo.User.Ranking}.", true)); } }
public override CommonMessageResponse Message_Received(CommonMessage messageObj) { string id; string uname; if (OsuId == null) { BllUserRole bllUserRole = new BllUserRole(); List <TblUserRole> userInfo = bllUserRole.GetUserRoleByQq(long.Parse(messageObj.UserId)); if (userInfo.Count == 0) { return(new CommonMessageResponse(LoliReply.IdNotBound, messageObj, true)); } id = userInfo[0].UserId.ToString(); uname = userInfo[0].CurrentUname; } else { int userNum = OldSiteApi.GetUser(OsuId, out var userObj); if (userNum == 0) { return(new CommonMessageResponse(LoliReply.IdNotFound, messageObj, true)); } if (userNum > 1) { // ignored } id = userObj.user_id; uname = userObj.username; } var eloInfo = EloApi.GetEloByUid(long.Parse(id)); switch (eloInfo.Result.ToLower()) { case "fail" when eloInfo.Message.ToLower() == "unranked": return(new CommonMessageResponse(uname + "大概没有参加什么mapping赛事..所以没有数据..", messageObj, true)); case "fail": return(new CommonMessageResponse("未知错误..查询不到..", messageObj, true)); default: return(new CommonMessageResponse( $"{eloInfo.User.Name},有elo点{Math.Round(eloInfo.User.Elo, 2)},当前#{eloInfo.User.Ranking}.", messageObj, true)); } }
public override CommonMessageResponse Message_Received(CommonMessage messageObj) { BllUserRole bllUserRole = new BllUserRole(); List <TblUserRole> userInfo = bllUserRole.GetUserRoleByQq(long.Parse(messageObj.UserId)); if (userInfo.Count == 0) { return(new CommonMessageResponse(LoliReply.IdNotBound, messageObj, true)); } var id = userInfo[0].UserId.ToString(); List <Beatmapsets> totalList = new List <Beatmapsets>(); Beatmapsets[] tmpArray; int page = 0; const int count = 10; do { string json = WebRequestUtil.GetResponseString( WebRequestUtil.CreateGetHttpResponse( "https://osu.ppy.sh/users/" + id + "/beatmapsets/graveyard?offset=" + page + "&limit=" + count)); Logger.Debug("GET JSON"); tmpArray = JsonConvert.DeserializeObject <Beatmapsets[]>(json); totalList.AddRange(tmpArray); page += count; if (tmpArray.Length != count) { break; } } while (tmpArray.Length != 0); if (totalList.Count == 0) { return(new CommonMessageResponse("惊了,你竟然会没坑!", messageObj, true)); } Random rnd = new Random(); Beatmapsets beatmap = totalList[rnd.Next(totalList.Count)]; var cqMusic = new CustomMusic("https://osu.ppy.sh/s/" + beatmap.Id, $"https://b.ppy.sh/preview/{beatmap.Id}.mp3", beatmap.Title, $"{beatmap.Artist}\r\n({beatmap.FavouriteCount} fav)", $"https://b.ppy.sh/thumb/{beatmap.Id}l.jpg"); return(new CommonMessageResponse(cqMusic.ToString(), messageObj)); }
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 }
public override CommonMessageResponse Message_Received(CommonMessage messageObj) { string userName, userId; if (OsuId == null) { BllUserRole bllUserRole = new BllUserRole(); List <TblUserRole> userInfo = bllUserRole.GetUserRoleByQq(long.Parse(messageObj.UserId)); if (userInfo.Count == 0) { return(new CommonMessageResponse(LoliReply.IdNotBound, messageObj, true)); } userId = userInfo[0].UserId.ToString(); userName = userInfo[0].CurrentUname; } else { int userNum = OldSiteApi.GetUser(OsuId, out var userObj); if (userNum == 0) { return(new CommonMessageResponse(LoliReply.IdNotFound, messageObj, true)); } if (userNum > 1) { // ignored } userId = userObj.user_id; userName = userObj.username; } var jsonString = HttpClientUtil.HttpGet("https://syrin.me/pp+/u/" + userId); if (jsonString == null) { return(new CommonMessageResponse("PP+获取超时,请重试…", messageObj, true)); } StringFinder sf = new StringFinder(jsonString); sf.FindNext("<div class=\"performance-table\">", false); sf.FindNext("</div>"); string innerText = sf.Cut().Trim('\n').Trim('\r'); HtmlTable htmlTable = new HtmlTable(innerText); string[,] array = htmlTable.GetArray(); Dictionary <string, int> dValue = new Dictionary <string, int>(); for (var i = 0; i < array.GetLength(0); i++) { for (var j = 0; j < array.GetLength(1); j += 2) { string key = array[i, j].Trim(':').Replace("Aim (", "").Replace(")", ""); int value = int.Parse(array[i, j + 1].Replace(",", "").Trim('p')); dValue.Add(key, value); } } var cqImg = new FileImage(Draw(userName, dValue)).ToString(); return(new CommonMessageResponse(cqImg, messageObj)); }
public static void Query() { while (MessageQueue.Count != 0) { if (!MessageQueue.TryDequeue(out var messageObj)) { continue; } var cmd = messageObj.Command; const long cabbageId = 1020640876; string uname; if (cmd == "statme" || cmd == "bpme" || cmd == "mybp" || cmd == "costme" || cmd == "mycost") { BllUserRole bllUserRole = new BllUserRole(); List <TblUserRole> userInfo = bllUserRole.GetUserRoleByQq(long.Parse(messageObj.UserId)); if (userInfo.Count == 0) { CoolQDispatcher.SendMessage(new CommonMessageResponse(LoliReply.IdNotBound, messageObj, true)); } uname = userInfo[0].CurrentUname; } else { uname = messageObj.ArgString; } using (Session session = new Session(25000, new Identity(cabbageId, MessageType.Private), cabbageId)) { CoolQDispatcher.SendMessage( new CommonMessageResponse($"!{cmd.Replace("my", "").Replace("me", "")} {uname}", new Identity(cabbageId, MessageType.Private))); try { CommonMessage result = session.GetMessage(); session.Timeout = 600; CommonMessage result2 = null; try { result2 = session.GetMessage(); } catch { // ignored } ImageInfo[] imgList = CqCode.GetImageInfo(result.Message) ?? CqCode.GetImageInfo(result2?.Message); if (imgList == null) { CoolQDispatcher.SendMessage(new CommonMessageResponse(result.Message, messageObj)); if (result2 != null) { CoolQDispatcher.SendMessage(new CommonMessageResponse(result2.Message, messageObj)); } continue; } //throw new IndexOutOfRangeException("查询失败:" + result.Message); var message = CqCode.DecodeToString(result.Message); 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; } CoolQDispatcher.SendMessage( new CommonMessageResponse(message + "\r\n(查询由白菜支持)", messageObj)); } catch (IndexOutOfRangeException e) { string msg = e.Message; CoolQDispatcher.SendMessage(new CommonMessageResponse(msg, messageObj, true)); } catch (TimeoutException) { string msg = "查询失败,白菜没有搭理人家.."; CoolQDispatcher.SendMessage(new CommonMessageResponse(msg, messageObj, true)); } catch (Exception ex) { string msg = "查询失败,未知错误。"; Logger.Exception(ex); CoolQDispatcher.SendMessage(new CommonMessageResponse(msg, messageObj, true)); } // catch } // using } // while } //void
public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope) { var routeMsg = scope.RouteMessage; string userName, userId; OldSiteApiClient client = new OldSiteApiClient(); if (UserName == null) { BllUserRole bllUserRole = new BllUserRole(); List <TableUserRole> userInfo = bllUserRole.GetUserRoleByQq(long.Parse(routeMsg.UserId)); if (userInfo.Count == 0) { return(routeMsg.ToSource(DefaultReply.IdNotBound, true)); } userId = userInfo[0].UserId.ToString(); userName = userInfo[0].CurrentUname; } else { int userNum = client.GetUser(UserComponent.FromUserName(UserName), out var userObj); if (userNum == 0) { return(routeMsg.ToSource(DefaultReply.IdNotFound, true)); } if (userNum > 1) { // ignored } userId = userObj.UserId.ToString(); userName = userObj.UserName; } var jsonString = HttpClient.HttpGet("https://syrin.me/pp+/u/" + userId); if (jsonString == null) { return(routeMsg .ToSource("PP+获取超时,请重试…", true) .ForceToSend()); } StringFinder sf = new StringFinder(jsonString); sf.FindNext("<div class=\"performance-table\">", false); sf.FindNext("</div>"); string innerText = sf.Cut().Trim('\n').Trim('\r'); HtmlTable htmlTable = new HtmlTable(innerText); string[,] array = htmlTable.GetArray(); Dictionary <string, int> dValue = new Dictionary <string, int>(); for (var i = 0; i < array.GetLength(0); i++) { for (var j = 0; j < array.GetLength(1); j += 2) { string key = array[i, j].Trim(':').Replace("Aim (", "").Replace(")", ""); int value = int.Parse(array[i, j + 1].Replace(",", "").Trim('p')); dValue.Add(key, value); } } var cqImg = new FileImage(Draw(userName, dValue)).ToString(); return(routeMsg .ToSource(cqImg) .ForceToSend()); }
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 override CommonMessageResponse Message_Received(CommonMessage messageObj) { string id; string uname; if (OsuId == null) { BllUserRole bllUserRole = new BllUserRole(); List <TblUserRole> userInfo = bllUserRole.GetUserRoleByQq(long.Parse(messageObj.UserId)); if (userInfo.Count == 0) { return(new CommonMessageResponse(LoliReply.IdNotBound, messageObj, true)); } id = userInfo[0].UserId.ToString(); uname = userInfo[0].CurrentUname; } else { int userNum = OldSiteApi.GetUser(OsuId, out var userObj); if (userNum == 0) { return(new CommonMessageResponse(LoliReply.IdNotFound, messageObj, true)); } if (userNum > 1) { // ignored } id = userObj.user_id; uname = userObj.username; } List <KudosuInfo> totalList = new List <KudosuInfo>(); List <KudosuInfo> tmpList; int page = 0; const int count = 20; do { string json = HttpClientUtil.HttpGet("https://osu.ppy.sh/users/" + id + "/kudosu?offset=" + page + "&limit=" + count); Logger.Debug("GET JSON"); tmpList = JsonConvert.DeserializeObject <List <KudosuInfo> >(json); totalList.AddRange(tmpList); page += count; if (totalList.Count != 0) { continue; } return(new CommonMessageResponse("此人一张图都没摸过……", messageObj, true)); } while (tmpList.Count != 0); List <KdInfo> kdInfoList = new List <KdInfo>(); int pastMonth = -1; KdInfo info = null; totalList.Reverse(); foreach (var item in totalList) { if (item.Created_At.Month != pastMonth) { if (pastMonth != -1) { kdInfoList.Add(info); } info = new KdInfo { Time = item.Created_At }; pastMonth = item.Created_At.Month; } if (info != null) { info.Count++; } } if (info != null) { kdInfoList.Add(info); } var cqImg = new FileImage(Draw(kdInfoList, uname)).ToString(); return(new CommonMessageResponse(cqImg, messageObj)); }
public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope) { var routeMsg = scope.RouteMessage; string id; string uname; OldSiteApiClient client = new OldSiteApiClient(); if (UserName == null) { BllUserRole bllUserRole = new BllUserRole(); List <TableUserRole> userInfo = bllUserRole.GetUserRoleByQq(long.Parse(routeMsg.UserId)); if (userInfo.Count == 0) { return(routeMsg.ToSource(DefaultReply.IdNotBound, true)); } id = userInfo[0].UserId.ToString(); uname = userInfo[0].CurrentUname; } else { int userNum = client.GetUser(UserComponent.FromUserName(UserName), out var userObj); if (userNum == 0) { return(routeMsg.ToSource(DefaultReply.IdNotFound, true)); } if (userNum > 1) { // ignored } id = userObj.UserId.ToString(); uname = userObj.UserName; } List <KudosuInfo> totalList = new List <KudosuInfo>(); List <KudosuInfo> tmpList; int page = 0; const int count = 20; do { string json = HttpClient.HttpGet("https://osu.ppy.sh/users/" + id + "/kudosu?offset=" + page + "&limit=" + count); Logger.Debug("GET JSON"); tmpList = JsonConvert.DeserializeObject <List <KudosuInfo> >(json); totalList.AddRange(tmpList); page += count; if (totalList.Count != 0) { continue; } return(routeMsg.ToSource("此人一张图都没摸过……", true)); } while (tmpList.Count != 0); List <KdInfo> kdInfoList = new List <KdInfo>(); int pastMonth = -1; KdInfo info = null; totalList.Reverse(); foreach (var item in totalList) { if (item.Created_At.Month != pastMonth) { if (pastMonth != -1) { kdInfoList.Add(info); } info = new KdInfo { Time = item.Created_At }; pastMonth = item.Created_At.Month; } if (info != null) { info.Count++; } } if (info != null) { kdInfoList.Add(info); } var cqImg = new FileImage(Draw(kdInfoList, uname)).ToString(); return(routeMsg.ToSource(cqImg)); }