private IList <ApiScore> GetPlayerScores(string username, PlayMode gamemode, ScoreSaveConditions configuration) { Log(username, string.Format(GettingScores, 1)); var scoresFromCache = _scoreCache.FirstOrDefault(s => s.Key.Username == username & s.Key.PlayMode == gamemode).Value; if (scoresFromCache != null) { return(scoresFromCache); } List <ApiScore> egibleScores = new List <ApiScore>(); IList <ApiScore> scores; do { int i = 1; int Cooldown = 20; do { Log(username, string.Format(GettingScores, i)); scores = _osuApi.GetUserBest(username, (PlayMode)gamemode); } while (scores == null && i++ < 5); if (scores == null) { Log(username, string.Format(GettingUserFailed, i, Cooldown)); Thread.Sleep(Cooldown * 1000); } } while (scores == null); _scoreCache.Add(new UserModePair(username, gamemode), scores); foreach (var s in scores) { if (configuration.IsEgibleForSaving(s)) { egibleScores.Add(s); } } return(egibleScores); }
private IList <ApiScore> GetPlayerScores(string username, ScoreSaveConditions configuration) { Log(username, string.Format(GettingScores, 1)); if (_scoreCache.ContainsKey(username)) { return(_scoreCache[username]); } List <ApiScore> egibleScores = new List <ApiScore>(); IList <ApiScore> scores; do { int i = 1; int Cooldown = 20; do { Log(username, string.Format(GettingScores, i)); scores = _osuApi.GetUserBest(username, PlayMode.Osu); } while (scores == null && i++ < 5); if (scores == null) { Log(username, string.Format(GettingUserFailed, i, Cooldown)); Thread.Sleep(Cooldown * 1000); } } while (scores == null); _scoreCache.Add(username, scores); foreach (var s in scores) { if (configuration.IsEgibleForSaving(s)) { egibleScores.Add(s); } } return(egibleScores); }
public override object CommandHandler(SocketMessage socketMessage, string input, CommandArguments arguments) { ApplyMode(arguments); ApplyPlayer(socketMessage.Author.Id, input); //List<OsuUser> users = APIHelper<List<OsuUser>>.GetData(apiUrl + "get_user?u&k="+apiKey+"&u=" + username); if (_osuUser == null) { return("No user has been found."); } else { EmbedFieldBuilder topplayField = new EmbedFieldBuilder { Name = "Top plays", Value = "No top plays available", IsInline = false }; List <OsuPlay> topPlays = OsuApi.GetUserBest(_osuUser, _osuMode, 3, true); if (topPlays != null && topPlays.Count > 0) { string topPlayString = ""; int i = 0; topPlays.ForEach(play => { i++; string stringified = "**" + i + ". " + "[" + play.Beatmap.Title + " \\[" + play.Beatmap.DifficultyName + "\\]](https://osu.ppy.sh/beatmaps/" + play.Beatmap.BeatmapID + ") +" + ("" + ((OsuModsShort)play.Mods).ModParser() + "").Replace(", ", "") + "** (" + Mathf.Round(play.Beatmap.Starrating ?? 0, 1) + "\\*)\n" + OsuRanks.GetEmojiFromRank(play.Rank).ToString() + " • **" + Mathf.Round(play.Performance.CurrentValue).FormatNumber() + "pp** • " + Mathf.Round(play.Accuracy, 2) + "% • " + play.MaxCombo + (play.Beatmap.MaxCombo != null?"/" + play.Beatmap.MaxCombo:"x") + (play.IsFullcombo == "1" ? " FC" : "") + " • " + play.Score.FormatNumber() + "\n" + "Achieved " + DateTime.Parse(play.DateAchieved).Humanize(); topPlayString += stringified + "\n"; }); topplayField.Value = topPlayString; } EmbedBuilder embed = new EmbedBuilder() { Color = ParentManager.bot.BotColor, Title = "Profile of " + _osuUser.Name, ThumbnailUrl = "https://a.ppy.sh/" + _osuUser.ID, Description = "Showing osu!" + _osuMode + " statistics", Fields = new List <EmbedFieldBuilder>() { new EmbedFieldBuilder() { Name = "Rank", Value = _osuUser.Performance == 0 ? "No PP or inactive" : ("#" + _osuUser.Globalrank.FormatNumber() + " (:flag_" + _osuUser.CountryCode.ToLower() + ": #" + _osuUser.Countryrank.FormatNumber() + ")"), }, new EmbedFieldBuilder() { Name = "Performance", Value = Mathf.Round(_osuUser.Performance).FormatNumber() + "pp", IsInline = true }, new EmbedFieldBuilder() { Name = "Level", Value = Mathf.Floor(_osuUser.Level) + " (" + Mathf.Round((Mathf.Round(_osuUser.Level, 2) - Mathf.Floor(_osuUser.Level)) * 100) + "% to level " + (Mathf.Ceil(_osuUser.Level)) + ")", IsInline = true }, new EmbedFieldBuilder() { Name = "Ranked Score", Value = _osuUser.RankedScore.FormatNumber(), IsInline = true }, new EmbedFieldBuilder() { Name = "Playtime", Value = TimeSpan.FromSeconds(_osuUser.Playtime).Humanize(maxUnit: TimeUnit.Hour), IsInline = true }, new EmbedFieldBuilder() { Name = "Maps played", Value = _osuUser.Playcount.FormatNumber(), IsInline = true }, new EmbedFieldBuilder() { Name = "Total Score", Value = _osuUser.TotalScore.FormatNumber(), IsInline = true }, new EmbedFieldBuilder() { Name = "Ranks", Value = OsuRanks.GetEmojiFromRank("X") + " " + _osuUser.GetCountRankSS().FormatNumber() + " " + "• " + OsuRanks.GetEmojiFromRank("S") + " " + _osuUser.GetCountRankS().FormatNumber() + " " + "• " + OsuRanks.GetEmojiFromRank("A") + " " + _osuUser.GetCountRankA().FormatNumber(), IsInline = false }, topplayField }, Footer = new EmbedFooterBuilder() { Text = "User registered " + DateTime.Parse(_osuUser.Joindate).Humanize() } }; return(embed); } }
public override object CommandHandler(SocketMessage socketMessage, string input, CommandArguments arguments) { ApplyMode(arguments); ApplyPlayer(socketMessage.Author.Id, input); if (_osuUser == null) { return("No user has been found."); } bool getRecent = false; int limit = 3; if (arguments.Get("r") != null) { getRecent = true; } if (arguments.Get("l") != null || arguments.Get("limit") != null) { int.TryParse((arguments.Get("l") != null) ? arguments.Get("l") : arguments.Get("limit"), out limit); } if (limit < 3) { limit = 3; } if (limit > 5) { limit = 5; } List <OsuPlay> topPlays = OsuApi.GetUserBest(_osuUser, _osuMode, 100, false); if (topPlays.Count == 0) { return("This player has no top plays in osu!" + _osuMode); } if (topPlays.Count < limit) { limit = topPlays.Count; } List <KeyValuePair <int, OsuPlay> > resultPlays = null; if (getRecent) { resultPlays = topPlays.Select((x, i) => new KeyValuePair <int, OsuPlay>(i + 1, x)).OrderBy(i => ((DateTimeOffset)DateTime.Parse(i.Value.DateAchieved)).ToUnixTimeSeconds()).Reverse().Take(limit).ToList(); } else { resultPlays = topPlays.Select((x, i) => new KeyValuePair <int, OsuPlay>(i + 1, x)).Take(limit).ToList(); } EmbedFieldBuilder topPlaysField = new EmbedFieldBuilder() { Name = "\u200B", Value = "a", IsInline = false }; EmbedBuilder embed = new EmbedBuilder() { Color = ParentManager.bot.BotColor, Title = (getRecent ? "Most " + limit + " recent top plays" : "Top " + limit + " plays") + " from **" + _osuUser.Name + "**", ThumbnailUrl = "https://a.ppy.sh/" + _osuUser.ID, Description = "Plays on osu!" + _osuMode, Fields = new List <EmbedFieldBuilder>() { } }; foreach (KeyValuePair <int, OsuPlay> playPair in resultPlays) { int playIndex = playPair.Key; OsuPlay play = playPair.Value; play.Beatmap = OsuApi.GetBeatmap(play.MapID, play.Mods, play.Mode); EmbedFieldBuilder field = new EmbedFieldBuilder() { Name = "**" + playIndex + ". " + play.Beatmap.Title + " [" + play.Beatmap.DifficultyName + "] +" + (((OsuModsShort)play.Mods).ModParser() + "").Replace(", ", "") + "** (" + Mathf.Round((float)play.Beatmap.Starrating, 2) + "\\*)", Value = OsuRanks.GetEmojiFromRank(play.Rank).ToString() + " " + Mathf.Round(play.Accuracy, 2) + "% • **" + Mathf.Round(play.Performance.CurrentValue, 2) + "pp** " + play.MaxCombo + "x" + (play.Beatmap.MaxCombo != null?"/" + play.Beatmap.MaxCombo + "x":"") + " " + ((play.IsFullcombo == "1"?"":"(For FC: **" + Mathf.Round(play.Performance.CurrentValueIfFC, 2) + "pp**)")) + " • " + play.Score.FormatNumber() + "\n" + "Achieved " + DateTime.Parse(play.DateAchieved).Humanize() + " • [Map](https://osu.ppy.sh/beatmaps/" + play.Beatmap.BeatmapID + ")", IsInline = false }; embed.AddField(field); } return(embed); }