Exemplo n.º 1
0
Arquivo: Xp.cs Projeto: Neeef/serenity
        public async Task XpGlobalLeaderboard(int page = 1)
        {
            if (--page < 0)
            {
                return;
            }

            await Context.Channel.SendPaginatedConfirmAsync(_client, page, async (curPage) =>
            {
                var users = _service.GetUserXps(curPage);

                var embed = new EmbedBuilder()
                            .WithTitle(GetText("global_leaderboard"))
                            .WithOkColor();

                if (!users.Any())
                {
                    return(embed.WithDescription("-"));
                }
                else
                {
                    for (int i = 0; i < users.Length; i++)
                    {
                        var user = await Context.Guild.GetUserAsync(users[i].UserId).ConfigureAwait(false);
                        embed.AddField(
                            $"#{(i + 1 + curPage * 9)} {(user?.ToString() ?? users[i].UserId.ToString())}",
                            $"{GetText("level_x", LevelStats.FromXp(users[i].TotalXp).Level)} - {users[i].TotalXp}xp");
                    }

                    return(embed);
                }
            }, addPaginatedFooter : false);
        }
Exemplo n.º 2
0
        public async Task XpGlobalLeaderboard(int page = 1)
        {
            if (--page < 0 || page > 100)
            {
                return;
            }
            var users = _service.GetUserXps(page);

            var embed = new EmbedBuilder()
                        .WithTitle(GetText("global_leaderboard"))
                        .WithOkColor();

            if (!users.Any())
            {
                embed.WithDescription("-");
            }
            else
            {
                for (int i = 0; i < users.Length; i++)
                {
                    var user = users[i];
                    embed.AddField(
                        $"#{(i + 1 + page * 9)} {(user.ToString())}",
                        $"{GetText("level_x", LevelStats.FromXp(users[i].TotalXp).Level)} - {users[i].TotalXp}xp");
                }
            }

            await Context.Channel.EmbedAsync(embed);
        }
Exemplo n.º 3
0
 public FullUserStats(DiscordUser usr, UserXpStats fullGuildStats, LevelStats global,
                      LevelStats guild, int globalRanking, int guildRanking)
 {
     User           = usr;
     Global         = global;
     Guild          = guild;
     GlobalRanking  = globalRanking;
     GuildRanking   = guildRanking;
     FullGuildStats = fullGuildStats;
 }
Exemplo n.º 4
0
        public Task XpLeaderboard(int page = 1)
        {
            if (--page < 0 || page > 100)
            {
                return(Task.CompletedTask);
            }

            return(Context.SendPaginatedConfirmAsync(page, (curPage) =>
            {
                var users = _service.GetUserXps(Context.Guild.Id, curPage);

                var embed = new EmbedBuilder()
                            .WithTitle(GetText("server_leaderboard"))
                            .WithFooter(GetText("page", curPage + 1))
                            .WithOkColor();

                if (!users.Any())
                {
                    return embed.WithDescription("-");
                }
                else
                {
                    for (int i = 0; i < users.Length; i++)
                    {
                        var levelStats = LevelStats.FromXp(users[i].Xp + users[i].AwardedXp);
                        var user = ((SocketGuild)Context.Guild).GetUser(users[i].UserId);

                        var userXpData = users[i];

                        var awardStr = "";
                        if (userXpData.AwardedXp > 0)
                        {
                            awardStr = $"(+{userXpData.AwardedXp})";
                        }
                        else if (userXpData.AwardedXp < 0)
                        {
                            awardStr = $"({userXpData.AwardedXp.ToString()})";
                        }

                        embed.AddField(
                            $"#{(i + 1 + curPage * 9)} {(user?.ToString() ?? users[i].UserId.ToString())}",
                            $"{GetText("level_x", levelStats.Level)} - {levelStats.TotalXp}xp {awardStr}");
                    }
                    return embed;
                }
            }, 1000, 10, addPaginatedFooter: false));
        }
Exemplo n.º 5
0
            public async Task ClubInformation([Remainder] string clubName = null)
            {
                if (string.IsNullOrWhiteSpace(clubName))
                {
                    await ClubInformation(Context.User).ConfigureAwait(false);

                    return;
                }

                ClubInfo club;

                if (!_service.GetClubByName(clubName, out club))
                {
                    await ReplyErrorLocalized("club_not_exists").ConfigureAwait(false);

                    return;
                }

                var lvl = new LevelStats(club.Xp);

                await Context.Channel.SendPaginatedConfirmAsync(_client, 0, (page) =>
                {
                    var embed = new EmbedBuilder()
                                .WithOkColor()
                                .WithTitle($"{club.ToString()}")
                                .WithDescription(GetText("level_x", lvl.Level) + $" ({club.Xp} xp)")
                                .AddField("Owner", club.Owner.ToString(), true)
                                .AddField("Level Req.", club.MinimumLevelReq.ToString(), true)
                                .AddField("Members", string.Join("\n", club.Users
                                                                 .Skip(page * 10)
                                                                 .Take(10)), false);

                    if (Uri.IsWellFormedUriString(club.ImageUrl, UriKind.Absolute))
                    {
                        return(embed.WithThumbnailUrl(club.ImageUrl));
                    }

                    return(embed);
                }, club.Users.Count / 10);
            }
Exemplo n.º 6
0
            public async Task ClubInformation([Remainder] string clubName = null)
            {
                if (string.IsNullOrWhiteSpace(clubName))
                {
                    await ClubInformation(Context.User).ConfigureAwait(false);

                    return;
                }

                if (!_service.GetClubByName(clubName, out ClubInfo club))
                {
                    await ReplyErrorLocalized("club_not_exists").ConfigureAwait(false);

                    return;
                }

                var lvl = new LevelStats(club.Xp);

                await Context.SendPaginatedConfirmAsync(0, (page) =>
                {
                    var embed = new EmbedBuilder()
                                .WithOkColor()
                                .WithTitle($"{club.ToString()}")
                                .WithDescription(GetText("level_x", lvl.Level) + $" ({club.Xp} xp)")
                                .AddField("Description", string.IsNullOrWhiteSpace(club.Description) ? "-" : club.Description, false)
                                .AddField("Owner", club.Owner.ToString(), true)
                                .AddField("Level Req.", club.MinimumLevelReq.ToString(), true)
                                .AddField("Members", string.Join("\n", club.Users
                                                                 .OrderByDescending(x =>
                    {
                        var l = new LevelStats(x.TotalXp).Level;
                        if (club.OwnerId == x.Id)
                        {
                            return(int.MaxValue);
                        }
                        else if (x.IsClubAdmin)
                        {
                            return(int.MaxValue / 2 + l);
                        }
                        else
                        {
                            return(l);
                        }
                    })
                                                                 .Skip(page * 10)
                                                                 .Take(10)
                                                                 .Select(x =>
                    {
                        var l      = new LevelStats(x.TotalXp);
                        var lvlStr = Format.Bold($" 『{l.Level}』");
                        if (club.OwnerId == x.Id)
                        {
                            return(x.ToString() + "🌟" + lvlStr);
                        }
                        else if (x.IsClubAdmin)
                        {
                            return(x.ToString() + "⭐" + lvlStr);
                        }
                        return(x.ToString() + lvlStr);
                    })), false);

                    if (Uri.IsWellFormedUriString(club.ImageUrl, UriKind.Absolute))
                    {
                        return(embed.WithThumbnailUrl(club.ImageUrl));
                    }

                    return(embed);
                }, club.Users.Count, 10).ConfigureAwait(false);
            }
Exemplo n.º 7
0
            public async Task ClubInformation([Remainder] string clubName = null)
            {
                if (string.IsNullOrWhiteSpace(clubName))
                {
                    await ClubInformation(Context.User).ConfigureAwait(false);

                    return;
                }

                if (!_service.GetClubByName(clubName, out ClubInfo club))
                {
                    await ReplyErrorLocalized("club_not_exists").ConfigureAwait(false);

                    return;
                }

                var lvl   = new LevelStats(club.Xp);
                var users = club.Users
                            .OrderByDescending(x =>
                {
                    var l = x.TotalXp - x.ClubXp;
                    if (club.OwnerId == x.Id)
                    {
                        return(int.MaxValue);
                    }
                    else if (x.IsClubAdmin)
                    {
                        return(int.MaxValue / 2 + l);
                    }
                    else
                    {
                        return(l);
                    }
                });

                var maxAmount = 500000;

                if (club.roleId != 0)
                {
                    maxAmount = 1000000;
                }

                var progress = _service.GetStorageProgress(club.Currency, maxAmount);

                await Context.SendPaginatedConfirmAsync(0, (page) =>
                {
                    var embed = new EmbedBuilder()
                                .WithOkColor()
                                .WithTitle($"{club.Name}")
                                .WithDescription(GetText("level_x", lvl.Level) + $" ({club.Xp} xp)")
                                .AddField(GetText("description"), string.IsNullOrWhiteSpace(club.Description) ? "-" : club.Description, false)
                                .AddField(GetText("owner_and_role"), $" ▹<@{club.Owner.UserId}>\n" + (club.roleId != 0 ? $"▹<@&{club.roleId}>" : "У клуба нет роли"), true)
                                .AddField(GetText("storage"), $" **{club.Currency}/{maxAmount}** :cherry_blossom:\n{progress}", true)
                                .AddField(GetText("members", club.Users.Count), string.Join("\n", users
                                                                                            .Skip(page * 10)
                                                                                            .Take(10)
                                                                                            .Select(x =>
                    {
                        var l      = new LevelStats(x.TotalXp);
                        var user   = x as IUser;
                        var lvlStr = Format.Bold($" ⟪{x.TotalXp - x.ClubXp} xp⟫");
                        if (club.OwnerId == x.Id)
                        {
                            return(x.ToString() + "🌟" + lvlStr);
                        }
                        else if (x.IsClubAdmin)
                        {
                            return(x.ToString() + "⭐" + lvlStr);
                        }
                        return(x.ToString() + lvlStr);
                    })), false);

                    if (Uri.IsWellFormedUriString(club.ImageUrl, UriKind.Absolute))
                    {
                        return(embed.WithThumbnailUrl(club.ImageUrl));
                    }

                    return(embed);
                }, club.Users.Count, 10).ConfigureAwait(false);
            }
Exemplo n.º 8
0
        public async Task XpLeaderboard(int page = 1, params string[] args)
        {
            if (--page < 0 || page > 100)
            {
                return;
            }

            var(opts, _) = OptionsParser.ParseFrom(new LbOpts(), args);

            await Context.Channel.TriggerTypingAsync();

            var socketGuild             = ((SocketGuild)ctx.Guild);
            List <UserXpStats> allUsers = new List <UserXpStats>();

            if (opts.Clean)
            {
                await Context.Channel.TriggerTypingAsync().ConfigureAwait(false);

                await _tracker.EnsureUsersDownloadedAsync(ctx.Guild).ConfigureAwait(false);

                allUsers = _service.GetTopUserXps(ctx.Guild.Id, 1000)
                           .Where(user => !(socketGuild.GetUser(user.UserId) is null))
                           .ToList();
            }

            await ctx.SendPaginatedConfirmAsync(page, (curPage) =>
            {
                var embed = new EmbedBuilder()
                            .WithTitle(GetText("server_leaderboard"))
                            .WithOkColor();

                List <UserXpStats> users;
                if (opts.Clean)
                {
                    users = allUsers.Skip(curPage * 9).Take(9).ToList();
                }
                else
                {
                    users = _service.GetUserXps(ctx.Guild.Id, curPage);
                }

                if (!users.Any())
                {
                    return(embed.WithDescription("-"));
                }
                else
                {
                    for (int i = 0; i < users.Count; i++)
                    {
                        var levelStats = new LevelStats(users[i].Xp + users[i].AwardedXp);
                        var user       = ((SocketGuild)ctx.Guild).GetUser(users[i].UserId);

                        var userXpData = users[i];

                        var awardStr = "";
                        if (userXpData.AwardedXp > 0)
                        {
                            awardStr = $"(+{userXpData.AwardedXp})";
                        }
                        else if (userXpData.AwardedXp < 0)
                        {
                            awardStr = $"({userXpData.AwardedXp})";
                        }

                        embed.AddField(
                            $"#{(i + 1 + curPage * 9)} {(user?.ToString() ?? users[i].UserId.ToString())}",
                            $"{GetText("level_x", levelStats.Level)} - {levelStats.TotalXp}xp {awardStr}");
                    }
                    return(embed);
                }
            }, 900, 9, addPaginatedFooter : false);
        }