Пример #1
0
        private Pages CreateScorePages(List <OsuScore> scores, string authorText, bool isLeaderboard = false)
        {
            EmbedBuilder embedBuilder = new EmbedBuilder();
            Pages        pages        = new Pages();

            int    count       = 0;
            string description = "";

            void CompileEmbed(bool isLastScore, OsuScore score, OsuScore firstScore)
            {
                string beatmapSetID = Utils.FindBeatmapsetID(BeatmapManager.GetBeatmap(firstScore.BeatmapID)).ToString();

                embedBuilder.WithThumbnailUrl(BanchoAPI.GetBeatmapImageUrl(beatmapSetID).ToString());

                embedBuilder.WithDescription(description);
                embedBuilder.WithAuthor(authorText, BanchoAPI.GetProfileImageUrl(firstScore.UserID.ToString()));

                embedBuilder.WithColor(new Color(Utils.GetRandomNumber(0, 255), Utils.GetRandomNumber(0, 255), Utils.GetRandomNumber(0, 255)));

                int currentScoreIndex = 0;

                currentScoreIndex = scores.IndexOf(score);

                if (isLastScore)
                {
                    currentScoreIndex++;
                }

                embedBuilder.WithFooter($"Viser {currentScoreIndex} af {scores.Count} Scores");

                pages.AddEmbed(embedBuilder.Build());
                embedBuilder = new EmbedBuilder();
                firstScore   = null;
                description  = "";
            }

            OsuScore firstScore = null;

            foreach (var score in scores)
            {
                if (firstScore is null)
                {
                    firstScore = score;
                }

                count++;

                string tempDesc = "";

                string isFCInfo = "";

                string placementText = "";

                bool isLastScore = scores.IndexOf(score) == scores.Count - 1;

                if (score.Placement > -1)
                {
                    placementText = $" `#{score.Placement}`";
                }

                if (((double)score.MaxCombo / score.MapMaxCombo) < 0.994)
                {
                    isFCInfo = $" ({score.PP_IF_FC.ToString("F2")}PP for {score.IF_FC_Accuracy.ToString("F2")}% FC)";
                }

                if (isLeaderboard)
                {
                    string leader = count == 1 ? ":crown: " : $"{count}. ";
                    tempDesc += $"**{leader} {score.Username} +{score.EnabledMods.ToFriendlyString()}** [{score.StarRating:F2}★]\n";
                }
                else
                {
                    tempDesc += $"**{count}.** [**{score.ArtistName} - {score.SongName} [{score.DifficultyName}]**]({BanchoAPI.GetBeatmapUrl(score.BeatmapID.ToString())}) **+{score.EnabledMods.ToFriendlyString()}** [{score.StarRating.ToString("F2")}★]\n";
                }

                tempDesc += $"▸ {Utils.GetEmoteForRankLetter(score.RankingLetter)} ▸ **{score.PP.ToString("F2")}PP**{placementText}{isFCInfo} ▸ {score.Accuracy.ToString("F2")}%\n";
                tempDesc += $"▸ {score.Score} ▸ x{score.MaxCombo}/{score.MapMaxCombo} ▸ [{score.Count300}/{score.Count100}/{score.Count50}/{score.CountMiss}]\n";
                tempDesc += $"▸ **CS:** {score.CS.ToString("F1")} **OD:** {score.OD.ToString("F1")} **AR:** {score.AR.ToString("F1")} **HP:** {score.HP.ToString("F1")} ▸ **BPM:** {score.BPM.ToString("F0")}\n";

                if (score.IsPass == false)
                {
                    tempDesc += $"▸ **Map Færdighed:** {score.CompletionPercentage.ToString("F2")}%\n";
                }

                tempDesc += $"▸ {Utils.FormatTime(DateTime.UtcNow - score.Date, true, 2)}\n";

                if (tempDesc.Length + description.Length >= 2048)
                {
                    CompileEmbed(isLastScore, score, firstScore);
                }

                description += tempDesc;

                if (isLastScore)
                {
                    CompileEmbed(isLastScore, score, firstScore);
                }
            }

            return(pages);
        }
Пример #2
0
            public void Update(OsuModule osuModule)
            {
                try
                {
                    List <BanchoAPI.BanchoBestScore> topPlays = osuModule.banchoAPI.GetBestPlays(Username, 100);
                    Logger.Log($"Polled {topPlays.Count} top plays from {Username}", LogLevel.Info);

                    if (topPlays.Count == 0)
                    {
                        return;
                    }

                    if (PrevTopPlays.Count == 0)
                    {
                        foreach (var item in topPlays)
                        {
                            PrevTopPlays.Add(item.ScoreID, item);
                        }
                        return;
                    }

                    List <(int placement, BanchoAPI.BanchoBestScore score)> diff = new();

                    for (int i = 0; i < topPlays.Count; i++)
                    {
                        var item = topPlays[i];
                        if (!PrevTopPlays.ContainsKey(item.ScoreID))
                        {
                            PrevTopPlays.Add(item.ScoreID, item);
                            diff.Add((i + 1, item));
                        }
                    }

                    if (diff.Count() == 0)
                    {
                        return;
                    }

                    List <OsuScore> scores = new List <OsuScore>();

                    foreach (var rup in diff)
                    {
                        OsuScore score = new OsuScore(BeatmapManager.GetBeatmap(rup.score.BeatmapID), rup.score);
                        score.Placement = rup.placement;

                        scores.Add(score);
                    }

                    for (int i = 0; i < Channels.Count; i++)
                    {
                        var channel = (CoreModule.Client.GetChannel(Channels[i]) as ISocketMessageChannel);

                        osuModule.RememberScores(channel.Id, scores);

                        Pages pages = osuModule.CreateScorePages(scores, $"New osu! {OsuGamemode.Standard} top plays from {Username}");

                        PagesHandler.SendPages(channel, pages);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log($"Exception when updating tracking for <{Username}>");
                    Logger.Log(ex.StackTrace, LogLevel.Error);
                }
            }