public async Task SetPrefix(string prefix) { var embed = new KaguyaEmbedBuilder(); if (prefix.Length > 5) { await ConsoleLogger.LogAsync("Command prefix was too long. Not set.", DataStorage.JsonStorage.LogLvl.DEBUG); embed.WithDescription("Your command prefix may not be longer than 5 characters."); embed.SetColor(EmbedColor.RED); await ReplyAsync(embed : embed.Build()); return; } Server server = await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id); server.CommandPrefix = prefix; await DatabaseQueries.UpdateAsync(server); embed.WithDescription($"Command prefix has been changed to `{prefix}`."); embed.WithFooter($"Use this command again without specifying a prefix to reset it."); embed.SetColor(EmbedColor.VIOLET); await ReplyAsync(embed : embed.Build()); }
public static async Task LinkParserMethod(SocketMessage s, ShardedCommandContext context) { User user = await DatabaseQueries.GetOrCreateUserAsync(context.User.Id); Server server = await DatabaseQueries.GetOrCreateServerAsync(context.Guild.Id); var embed = new KaguyaEmbedBuilder(); user.ActiveRateLimit++; if (user.IsBlacklisted) { return; } string link = $"{s}"; string mapId = link.Split('/').Last(); //Gets the map's ID from the link. if (mapId.Contains('?')) { mapId = mapId.Replace("?m=0", ""); } Beatmap mapData = await Client.GetBeatmapByIdAsync((long)mapId.AsUlong()); string status = ""; BeatmapState state = mapData.State; DateTimeOffset?approvedDate = mapData.ApprovedDate; status = state switch { // ReSharper disable PossibleInvalidOperationException BeatmapState.Graveyard | BeatmapState.WorkInProgress | BeatmapState.Pending => $"Last updated on {mapData.LastUpdate.Value.LocalDateTime.ToShortDateString()}", BeatmapState.Ranked => $"Ranked on {approvedDate.Value.LocalDateTime.ToShortDateString()}", BeatmapState.Approved => $"Approved on {approvedDate.Value.LocalDateTime.ToShortDateString()}", BeatmapState.Qualified => $"Qualified on {approvedDate.Value.LocalDateTime.ToShortDateString()}", BeatmapState.Loved => $"Loved 💙 on {approvedDate.Value.LocalDateTime.ToShortDateString()}", // ReSharper restore PossibleInvalidOperationException _ => status }; string lengthValue = mapData.TotalLength.ToString(@"mm\:ss"); PerformanceData pp95 = await mapData.GetPPAsync(95f); PerformanceData pp98 = await mapData.GetPPAsync(98f); PerformanceData pp99 = await mapData.GetPPAsync(99f); PerformanceData pp100 = await mapData.GetPPAsync(100f); embed.WithAuthor(author => { author.Name = $"{mapData.Title} by {mapData.Author}"; author.Url = $"https://osu.ppy.sh/b/{mapId}"; author.IconUrl = $"https://a.ppy.sh/{mapData.AuthorId}"; }); embed.WithDescription( $"**{mapData.Title} [{mapData.Difficulty}]** by **{mapData.Artist}**" + $"\n" + $"\n<:total_length:630131957598126120> **Total Length:** {lengthValue} <:bpm:630131958046785563> **BPM:** {mapData.Bpm:N1}" + $"\n**Star Rating:** `{mapData.StarRating:N2} ☆` **Maximum Combo:** `{mapData.MaxCombo:N0}x`" + $"\n**Download:** [[Beatmap]]({mapData.BeatmapUri}/download)" + $"[(without video)](https://osu.ppy.sh/d/{mapData.BeatmapUri}n)" + $"\n" + $"\n**CS:** `{mapData.CircleSize:N2} ` **AR:** `{mapData.ApproachRate:N2}` " + $"**OD:** `{mapData.OverallDifficulty:N2}` **HP:** `{mapData.HpDrain:N2}`" + $"\n" + $"\n**95% FC:** `{pp95.Pp:N0}pp` **98% FC:** `{pp98.Pp:N0}pp`" + $"\n**99% FC:** `{pp99.Pp:N0}pp` **100% FC (SS):** `{pp100.Pp:N0}pp`"); embed.WithFooter($"Status: {status} | 💙 Amount: {mapData.FavoriteCount:N0}"); await context.Channel.SendEmbedAsync(embed); await ConsoleLogger.LogAsync( $"osu! beatmap automatically parsed in guild {server.ServerId} by user {user.UserId}", LogLvl.DEBUG); user.OsuBeatmapsLinked++; await DatabaseQueries.UpdateAsync(user); } }
public async Task TopOsuPlays(int num = 5, [Remainder] string player = null) { DataStorage.DbData.Models.User user = await DatabaseQueries.GetOrCreateUserAsync(Context.User.Id); Server server = await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id); User osuUser; if (num < 1 || num > 7) { await SendBasicErrorEmbedAsync("Number of plays must be between 1 and 7."); return; } if (string.IsNullOrEmpty(player)) { osuUser = await OsuBase.Client.GetUserByUserIdAsync(user.OsuId, GameMode.Standard); if (osuUser.UserId == 0) { Embed.WithTitle($"osu! Top {num}"); Embed.WithDescription($"**{Context.User.Mention} Failed to acquire username. " + $"Please specify a player or set your osu! username with " + $"`{(await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id)).CommandPrefix}osuset`!**"); await ReplyAsync(embed : Embed.Build()); return; } } else { player = player.Replace(' ', '_'); osuUser = await OsuBase.Client.GetUserByUsernameAsync(player, GameMode.Standard); } if (osuUser == null) { throw new KaguyaSupportException($"Failed to download data for player. If no user was specified, " + $"you must set your osu! username or user ID via " + $"`{server.CommandPrefix}osuset <name/ID>`.\n\n" + $"If a username was specified, it's likely that the user does not exist or " + $"you are providing invalid data."); } IReadOnlyList <Score> playerBestObjectList = await OsuBase.Client.GetUserBestsByUserIdAsync(osuUser.UserId, GameMode.Standard, num); playerBestObjectList = playerBestObjectList.OrderByDescending(x => x.PerformancePoints).ToList().AsReadOnly(); User playerUserObject = await OsuBase.Client.GetUserByUserIdAsync(osuUser.UserId, GameMode.Standard); string s = num == 1 ? "" : "s"; Embed.WithAuthor(author => { author.Name = $"{playerUserObject.Username}'s Top {(num == 1 ? "" : num.ToString())} osu! Standard Play{s}"; author.IconUrl = $"https://osu.ppy.sh/images/flags/{playerUserObject.Country}.png"; }); Embed.WithTitle($"**Top {num} plays for {playerUserObject.Username}:**"); Embed.WithUrl($"https://osu.ppy.sh/u/{playerUserObject.UserId}"); int i = 0; string topPlayString = ""; foreach (Score playerBestObject in playerBestObjectList) { i++; Beatmap beatmap = await playerBestObject.GetBeatmapAsync(); PerformanceData pp = await beatmap.GetPPAsync(playerBestObject.Mods, (float)playerBestObject.Accuracy); Debug.Assert(playerBestObject.Date != null, "playerBestObject.Date != null"); topPlayString += $"\n{i}: ▸ **{OsuBase.OsuGradeEmote(playerBestObject.Rank)}" + $@"{playerBestObject.Mods.ToModeString(OsuBase.Client) .Replace("No Mode", "No Mod") .Replace("DTNC", "NC")}** ▸ " + $"{beatmap.BeatmapId} ▸ **[{beatmap.Title} " + $"[{beatmap.Difficulty}]](https://osu.ppy.sh/b/{beatmap.BeatmapId})** " + $"\n▸ **☆{beatmap.StarRating:N2}** ▸ **{playerBestObject.Accuracy:F}%** " + $"for **{pp.Pp:N}pp** " + $"\n▸ [Combo: {playerBestObject.MaxCombo}x / Max: {beatmap.MaxCombo}]" + $"\n▸ Play made {(DateTime.UtcNow - playerBestObject.Date.Value.DateTime).Humanize(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Year, precision: 3)} ago\n"; } Embed.WithDescription(topPlayString); await ReplyAsync(embed : Embed.Build()); }