Ejemplo n.º 1
0
        public static int Tries(int mode, int userid, int beatmapid)
        {
            int count = 0;

            var recentBuilder = new OsuUserRecentBuilder()
            {
                Mode   = mode,
                Limit  = "20",
                UserId = userid
            };

            var result = recentBuilder.Execute(true);

            foreach (var recent in result)
            {
                if (beatmapid == recent.beatmap_id)
                {
                    count++;
                }
                else
                {
                    break;
                }
            }

            return(count);
        }
Ejemplo n.º 2
0
        public async Task GetUserRecent(string osuId, bool findWithUsername, bool dUser = false, ulong dUserId = 0)
        {
            try
            {
                CakeUser databaseUser = !dUser
                    ? await GetDatabaseEntityAsync(Module.Context.User.Id)
                    : await GetDatabaseEntityAsync(dUserId);

                var info = "";

                if (osuId.IsNullOrEmpty())
                {
                    osuId            = databaseUser.OsuId.ToString();
                    findWithUsername = false;
                }

                var user = GetJsonUser(osuId, findWithUsername, databaseUser.OsuMode);

                var recentBuilder = new OsuUserRecentBuilder
                {
                    Mode   = databaseUser.OsuMode,
                    Limit  = "1",
                    UserId = user.user_id
                };
                var recent = OsuTimeConverter.ConvertScorableDate(user.country, recentBuilder.Execute());

                var retryCount = 0;

                if (recent.Count == 0)
                {
                    throw new CakeException($"`No recent play(s) has been found for {user.username}`");
                }

                for (var i = 0; i < recent.Count; i++)
                {
                    var t = recent[i];

                    retryCount = OsuCheckRetries.Tries(databaseUser.OsuMode, t.user_id, t.Beatmap.beatmap_id);
                    info       = $"**{t.rounded_score} ♢ " +
                                 $"{t.rank.LevelEmotes()} ♢ {t.maxcombo}x*({ t.Beatmap.max_combo}x)*** {OsuMods.Modnames(Convert.ToInt32(t.enabled_mods))} \n " +
                                 $"{OsuEmoteCodes.Emote300} {t.count300} ♢ {OsuEmoteCodes.Emote100} {t.count100} ♢ {OsuEmoteCodes.Emote50} {t.count50} ♢ {OsuEmoteCodes.EmoteX} {t.countmiss} ♢ {Math.Round(t.calculated_accuracy, 2)}%\n";

                    if (t.rank == "F")
                    {
                        info += $"{Math.Round(t.completion, 2)}% completed ♢ if completed **{Math.Round(t.pp, 2)} PP**\n";
                    }
                    else
                    {
                        if (!t.choked)
                        {
                            info += $"**{Math.Round(t.pp, 2)} PP**\n\n";
                        }
                        else
                        {
                            info += $"**{Math.Round(t.pp, 2)} PP** ♢ {Math.Round(t.nochokepp, 2)} PP if FC ({Math.Round(t.nochokeaccuracy, 2)}%)\n\n";
                        }
                    }
                }

                await SendEmbedAsync(Embeds.OsuModuleEmbeds.ReturnUserRecent(user, recent[0].Beatmap, recent[0], info, databaseUser.OsuMode, retryCount));

                if (recent[0].Beatmap.beatmap_id != 0)
                {
                    OsuModule.SetMapId(recent[0].Beatmap.beatmap_id);
                }
            }
            catch (CakeException e)
            {
                await SendMessageAsync(e.Message);
            }
            catch (Exception e)
            {
                _logger.LogError(e);
            }
        }