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.");
            }

            List <OsuPlay> recentPlays = OsuApi.GetUserRecent(_osuUser.Name, _osuMode, 1, true);

            if (recentPlays == null)
            {
                return("" + _osuUser.Name + " has not played in the last 24 hours");
            }

            OsuPlay recentPlay = recentPlays[0];

            EmbedBuilder embed = new EmbedBuilder()
            {
                Title       = "Most recent play by **" + _osuUser.Name + "** in osu!" + _osuMode,
                Description = "[" + recentPlay.Beatmap.Artist + " - " + recentPlay.Beatmap.Title + " \\[" + recentPlay.Beatmap.DifficultyName + "\\]](https://osu.ppy.sh/beatmaps/" + recentPlay.Beatmap.BeatmapID + ")\n" +
                              "Map status: " + OsuApi.BeatmapStatusEmotes[recentPlay.Beatmap.Status].ToString() + " " + recentPlay.Beatmap.Status.ToString(),
                ThumbnailUrl = "https://b.ppy.sh/thumb/" + recentPlay.Beatmap.BeatmapSetID + "l.jpg",
                Fields       = new List <EmbedFieldBuilder>()
                {
                    new EmbedFieldBuilder()
                    {
                        Name  = "Beatmap Information",
                        Value = "(" + Mathf.Round(recentPlay.Beatmap.Starrating ?? 0, 2) + "*) CS" + Mathf.Round(recentPlay.Beatmap.MapStats.CS, 2) + " • AR" + Mathf.Round(recentPlay.Beatmap.MapStats.AR, 2) + " • OD" + Mathf.Round(recentPlay.Beatmap.MapStats.OD, 2) + " • HP" + Mathf.Round(recentPlay.Beatmap.MapStats.HP, 2) + "\n" +
                                "Mapped by [" + recentPlay.Beatmap.Mapper + "](https://osu.ppy.sh/users/" + recentPlay.Beatmap.MapperID + ")",
                        IsInline = false
                    },
                    new EmbedFieldBuilder()
                    {
                        Name  = "Play Information",
                        Value = OsuRanks.GetEmojiFromRank(recentPlay.Rank).ToString() + " " + Mathf.Round(recentPlay.Accuracy, 2) + "% **+" + ("" + ((OsuModsShort)recentPlay.Mods).ModParser() + "").Replace(", ", "") + "** • **" + Mathf.Round(recentPlay.Performance.CurrentValue, 2) + "pp** " + recentPlay.MaxCombo + "x/" + recentPlay.Beatmap.MaxCombo + "x " + ((recentPlay.IsFullcombo == "1"?"":"(For FC: **" + Mathf.Round(recentPlay.Performance.CurrentValueIfFC, 2) + "pp**)")) + "\n" +
                                "[" + recentPlay.C300 + "/" + recentPlay.C100 + "/" + recentPlay.C50 + "/" + recentPlay.CMiss + "] • " + recentPlay.Score.FormatNumber(),
                        IsInline = false
                    }
                },
                Footer = new EmbedFooterBuilder()
                {
                    Text = "Played " + DateTime.Parse(recentPlay.DateAchieved).Humanize(),
                }
            };

            return(embed);
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        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);
        }