public async Task DatabaseAsync([Remainder] IUser user) { var userDb = await DbContext.Users.FirstOrDefaultAsync(x => x.UserId == user.Id); if (userDb is null) { await ReplyErrorAsync(Localization.BotUserNotInDatabase); return; } var mutualGuilds = user is CachedUser cachedUser ? cachedUser.MutualGuilds.Count : 0; var embed = new LocalEmbedBuilder() .WithColor(RiasUtilities.ConfirmColor) .WithAuthor(user) .AddField(GetText(Localization.CommonId), user.Id, true) .AddField(GetText(Localization.GamblingCurrency), $"{userDb.Currency} {Credentials.Currency}", true) .AddField(GetText(Localization.XpGlobalLevel), RiasUtilities.XpToLevel(userDb.Xp, 30), true) .AddField(GetText(Localization.XpGlobalXp), userDb.Xp, true) .AddField(GetText(Localization.BotIsBlacklisted), userDb.IsBlacklisted, true) .AddField(GetText(Localization.BotIsBanned), userDb.IsBanned, true) .AddField(GetText(Localization.BotMutualGuilds), mutualGuilds, true) .WithImageUrl(user.GetAvatarUrl()); await ReplyAsync(embed); }
public async Task DatabaseAsync([Remainder] DiscordUser user) { var userDb = await DbContext.Users.FirstOrDefaultAsync(x => x.UserId == user.Id); if (userDb is null) { await ReplyErrorAsync(Localization.BotUserNotInDatabase, user.FullName()); return; } var mutualGuilds = user is DiscordMember cachedUser?cachedUser.GetMutualGuilds(RiasBot).Count() : 0; #if RELEASE var currency = GetText(Localization.GamblingCurrency); #else var currency = GetText(Localization.GamblingHearts); #endif var embed = new DiscordEmbedBuilder() .WithColor(RiasUtilities.ConfirmColor) .WithAuthor(user.FullName(), user.GetAvatarUrl(ImageFormat.Auto)) .AddField(GetText(Localization.CommonId), user.Id.ToString(), true) .AddField(currency, $"{userDb.Currency} {Configuration.Currency}", true) .AddField(GetText(Localization.XpGlobalLevel), RiasUtilities.XpToLevel(userDb.Xp, 30).ToString(), true) .AddField(GetText(Localization.XpGlobalXp), userDb.Xp.ToString(), true) .AddField(GetText(Localization.BotIsBanned), userDb.IsBanned.ToString(), true) .AddField(GetText(Localization.BotMutualGuilds), mutualGuilds.ToString(), true) .WithImageUrl(user.GetAvatarUrl(ImageFormat.Auto)); await ReplyAsync(embed); }
public async Task XpLeaderboardAsync(int page = 1) { page--; if (page < 0) { page = 0; } var membersXp = (await DbContext.GetOrderedListAsync <MembersEntity, int>(x => x.GuildId == Context.Guild !.Id, y => y.Xp, true)) .Where(x => Context.Guild !.Members.ContainsKey(x.MemberId)) .ToList(); var xpLeaderboard = membersXp.Skip(page * 15) .Take(15) .ToList(); if (xpLeaderboard.Count == 0) { await ReplyErrorAsync(Localization.XpGuildLeaderboardEmpty); return; } var description = new StringBuilder(); var index = page * 15; foreach (var userDb in xpLeaderboard) { try { var member = await Context.Guild !.GetMemberAsync(userDb.MemberId); description.Append($"{++index}. **{member.FullName()}**: " + $"`{GetText(Localization.XpLevelX, RiasUtilities.XpToLevel(userDb.Xp, XpService.XpThreshold))} " + $"({userDb.Xp} {GetText(Localization.XpXp).ToLowerInvariant()})`\n"); } catch { // ignored } } var embed = new DiscordEmbedBuilder { Color = RiasUtilities.ConfirmColor, Title = GetText(Localization.XpGuildLeaderboard), Description = description.ToString(), Footer = new DiscordEmbedBuilder.EmbedFooter { IconUrl = Context.User.GetAvatarUrl(ImageFormat.Auto), Text = $"{Context.User.FullName()} • #{membersXp.FindIndex(x => x.MemberId == Context.User.Id) + 1}" } }; await ReplyAsync(embed); }
public async Task XpLeaderboardAsync(int page = 1) { page--; if (page < 0) { page = 0; } var xpLeaderboard = (await DbContext.GetOrderedListAsync <GuildUsersEntity, int>(x => x.GuildId == Context.Guild !.Id, y => y.Xp, true)) .Where(x => Context.Guild !.GetMember(x.UserId) != null) .Skip(page * 15) .Take(15) .ToList(); if (xpLeaderboard.Count == 0) { await ReplyErrorAsync(Localization.XpGuildLeaderboardEmpty); return; } var embed = new LocalEmbedBuilder { Color = RiasUtilities.ConfirmColor, Title = GetText(Localization.XpGuildLeaderboard) }; var index = page * 15; foreach (var userDb in xpLeaderboard) { embed.AddField($"{++index}. {Context.Guild!.GetMember(userDb.UserId)}", $"{GetText(Localization.XpLevelX, RiasUtilities.XpToLevel(userDb.Xp, XpService.XpThreshold))} | {GetText(Localization.XpXp)} {userDb.Xp}", true); } await ReplyAsync(embed); }
public async Task GlobalXpLeaderboardAsync(int page = 1) { page--; if (page < 0) { page = 0; } var xpLeaderboard = await DbContext.GetOrderedListAsync <UsersEntity, int>(x => x.Xp, true, (page * 15)..((page + 1) * 15)); if (xpLeaderboard.Count == 0) { await ReplyErrorAsync(Localization.XpLeaderboardEmpty); return; } var embed = new LocalEmbedBuilder { Color = RiasUtilities.ConfirmColor, Title = GetText(Localization.XpLeaderboard) }; var index = page * 15; foreach (var userDb in xpLeaderboard) { var user = (IUser)RiasBot.GetUser(userDb.UserId) ?? await RiasBot.GetUserAsync(userDb.UserId); embed.AddField($"{++index}. {user}", $"{GetText(Localization.XpLevelX, RiasUtilities.XpToLevel(userDb.Xp, XpService.XpThreshold))} | {GetText(Localization.XpXp)} {userDb.Xp}", true); } await ReplyAsync(embed); }