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 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 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 void OnInitialized(StartupConfig startup) { _userDic = LoadSettings <ConcurrentDictionary <long, List <CoolQIdentity> > >("userDictionary") ?? new ConcurrentDictionary <long, List <CoolQIdentity> >(); _todaySets = LoadSettings <List <SlimBeatmapsets> >("today") ?? new List <SlimBeatmapsets>(); _client = new OldSiteApiClient(); Task.Run(() => { // 扫描的频率,但未包括等待另一线程的时间,也就是>=这个间隔。 #if DEBUG const int sleepTime = 5000; #else const int sleepTime = 1000 * 60 * 20; #endif while (true) { // 由于其中会有很多阻塞 使用异步 Task asyncTask = new Task(() => { RemoveOverdueMapSets(); // 以mapper为单位的设计 foreach (var pair in _userDic) { try { long mapperId = pair.Key; List <CoolQIdentity> userList = pair.Value; if (pair.Value.Count == 0) { RemoveUnusefulMapper(mapperId); continue; } OsuBeatmapSet[] mapsets = GetBeatmapSets(new UserId(mapperId)); if (mapsets.Length <= 0) { continue; } foreach (var item in mapsets) { _todaySets.Add(new SlimBeatmapsets { CreatorId = mapperId, Id = item.Id, RankedDate = item.RankedDate, Status = item.Status, //SubmittedDate = item.SubmittedDate }); } SaveTodaySettings(); Logger.Debug($"{pair.Key}: Find {mapsets.Length} results."); PushNews(userList, mapsets); } catch (Exception ex) { Logger.Exception(ex); } } }); asyncTask.Start(); Thread.Sleep(sleepTime); Task.WaitAll(asyncTask); // 等待执行完毕 } }); }
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)); }