Ejemplo n.º 1
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.");
            }

            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);
        }
Ejemplo n.º 2
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);
        }