Exemple #1
0
        public async Task LeaderboardsAsync(EventContext e)
        {
            LeaderboardsOptions options = new LeaderboardsOptions();

            ArgObject argument = e.Arguments.FirstOrDefault();

            switch (argument?.Argument.ToLower() ?? "")
            {
            case "commands":
            case "cmds":
            {
                options.type = LeaderboardsType.COMMANDS;
                argument     = argument?.Next();
            }
            break;

            case "currency":
            case "mekos":
            case "money":
            case "bal":
            {
                options.type = LeaderboardsType.CURRENCY;
                argument     = argument?.Next();
            }
            break;

            case "rep":
            case "reputation":
            {
                options.type = LeaderboardsType.REPUTATION;
                argument     = argument?.Next();
            }
            break;

            case "pasta":
            case "pastas":
            {
                options.type = LeaderboardsType.PASTA;
                argument     = argument?.Next();
            }
            break;

            case "experience":
            case "exp":
            {
                options.type = LeaderboardsType.EXPERIENCE;
                argument     = argument?.Next();
            }
            break;

            case "guild":
            case "guilds":
            {
                options.type = LeaderboardsType.GUILDS;
                argument     = argument?.Next();
            }
            break;


            default:
            {
                options.type = LeaderboardsType.EXPERIENCE;
            }
            break;
            }

            if (argument?.Argument.ToLower() == "local")
            {
                if (options.type != LeaderboardsType.PASTA)
                {
                    options.guildId = e.Guild.Id;
                }
                argument = argument.Next();
            }

            if (argument != null)
            {
                IDiscordUser user = await argument.GetUserAsync(e.Guild);

                if (user != null)
                {
                    options.mentionedUserId = user.Id;
                    argument = argument.Next();
                }
            }

            if ((argument?.AsInt() ?? 0) != 0)
            {
                options.pageNumber = argument.AsInt().Value - 1;
                argument           = argument?.Next();
            }

            using (var context = new MikiContext())
            {
                int p = Math.Max(options.pageNumber - 1, 0);

                LeaderboardsObject obj = await Global.MikiApi.GetPagedLeaderboardsAsync(options);

                Utils.RenderLeaderboards(Utils.Embed, obj.items, obj.currentPage * 10)
                .SetFooter(Locale.GetString(e.Channel.Id, "page_index",
                                            obj.currentPage + 1, Math.Ceiling((double)obj.totalItems / 10)), "")
                .SetAuthor(
                    "Leaderboards: " + options.type + " (click me!)",
                    null,
                    Global.MikiApi.BuildLeaderboardsUrl(options)
                    )
                .ToEmbed().QueueToChannel(e.Channel);
            }
        }
Exemple #2
0
        public async Task LeaderboardsAsync(CommandContext e)
        {
            LeaderboardsOptions options = new LeaderboardsOptions();

            e.Arguments.Peek(out string argument);

            switch (argument?.ToLower() ?? "")
            {
            case "commands":
            case "cmds":
            {
                options.Type = LeaderboardsType.COMMANDS;
                e.Arguments.Skip();
            }
            break;

            case "currency":
            case "mekos":
            case "money":
            case "bal":
            {
                options.Type = LeaderboardsType.CURRENCY;
                e.Arguments.Skip();
            }
            break;

            case "rep":
            case "reputation":
            {
                options.Type = LeaderboardsType.REPUTATION;
                e.Arguments.Skip();
            }
            break;

            case "pasta":
            case "pastas":
            {
                options.Type = LeaderboardsType.PASTA;
                e.Arguments.Skip();
            }
            break;

            case "experience":
            case "exp":
            {
                options.Type = LeaderboardsType.EXPERIENCE;
                e.Arguments.Skip();
            }
            break;

            case "guild":
            case "guilds":
            {
                options.Type = LeaderboardsType.GUILDS;
                e.Arguments.Skip();
            }
            break;

            default:
            {
                options.Type = LeaderboardsType.EXPERIENCE;
            }
            break;
            }

            if (e.Arguments.Peek(out string localArg))
            {
                if (localArg.ToLower() == "local")
                {
                    if (options.Type != LeaderboardsType.PASTA)
                    {
                        options.GuildId = e.Guild.Id;
                    }
                    e.Arguments.Skip();
                }
            }

            if (e.Arguments.Peek(out int index))
            {
                options.Offset = Math.Max(0, index - 1) * 12;
                e.Arguments.Skip();
            }

            options.Amount = 12;

            var api = e.GetService <MikiApiClient>();

            LeaderboardsObject obj = await api.GetPagedLeaderboardsAsync(options);

            await Utils.RenderLeaderboards(new EmbedBuilder(), obj.items, obj.currentPage * 12)
            .SetFooter(
                e.Locale.GetString("page_index", obj.currentPage + 1, Math.Ceiling((double)obj.totalPages / 10)),
                ""
                )
            .SetAuthor(
                "Leaderboards: " + options.Type + " (click me!)",
                null,
                api.BuildLeaderboardsUrl(options)
                )
            .ToEmbed()
            .QueueToChannelAsync(e.Channel);
        }
Exemple #3
0
        public async Task LeaderboardsAsync(EventContext e)
        {
            LeaderboardsOptions options = new LeaderboardsOptions();

            ArgObject argument = e.Arguments.FirstOrDefault();

            switch (argument?.Argument.ToLower() ?? "")
            {
            case "commands":
            case "cmds":
            {
                options.Type = LeaderboardsType.COMMANDS;
                argument     = argument?.Next();
            }
            break;

            case "currency":
            case "mekos":
            case "money":
            case "bal":
            {
                options.Type = LeaderboardsType.CURRENCY;
                argument     = argument?.Next();
            }
            break;

            case "rep":
            case "reputation":
            {
                options.Type = LeaderboardsType.REPUTATION;
                argument     = argument?.Next();
            }
            break;

            case "pasta":
            case "pastas":
            {
                options.Type = LeaderboardsType.PASTA;
                argument     = argument?.Next();
            }
            break;

            case "experience":
            case "exp":
            {
                options.Type = LeaderboardsType.EXPERIENCE;
                argument     = argument?.Next();
            }
            break;

            case "guild":
            case "guilds":
            {
                options.Type = LeaderboardsType.GUILDS;
                argument     = argument?.Next();
            }
            break;

            default:
            {
                options.Type = LeaderboardsType.EXPERIENCE;
            }
            break;
            }

            if (argument?.Argument.ToLower() == "local")
            {
                if (options.Type != LeaderboardsType.PASTA)
                {
                    options.GuildId = e.Guild.Id;
                }
                argument = argument.Next();
            }

            if ((argument?.TakeInt() ?? 0) != 0)
            {
                options.Offset = Math.Max(0, argument.TakeInt().Value - 1) * 12;
                argument       = argument?.Next();
            }

            options.Amount = 12;

            using (var context = new MikiContext())
            {
                int p = Math.Max(options.Offset - 1, 0);

                using (var api = new MikiApi(Global.Config.MikiApiBaseUrl, Global.Config.MikiApiKey))
                {
                    LeaderboardsObject obj = await api.GetPagedLeaderboardsAsync(options);

                    Utils.RenderLeaderboards(new EmbedBuilder(), obj.items, obj.currentPage * 12)
                    .SetFooter(
                        e.Locale.GetString("page_index", obj.currentPage + 1, Math.Ceiling((double)obj.totalPages / 10)),
                        ""
                        )
                    .SetAuthor(
                        "Leaderboards: " + options.Type + " (click me!)",
                        null,
                        api.BuildLeaderboardsUrl(options)
                        )
                    .ToEmbed()
                    .QueueToChannel(e.Channel);
                }
            }
        }
Exemple #4
0
        /*[Command(Name = "setrolelevel")]
         * public async Task SetRoleLevelAsync(EventContext e)
         * {
         *      using (var context = new MikiContext())
         *      {
         *              Locale locale = new Locale(e.Channel.Id.ToDbLong());
         *
         *              List<string> allArgs = new List<string>();
         *              allArgs.AddRange(e.arguments.Split(' '));
         *              if (allArgs.Count >= 2)
         *              {
         *                      int levelrequirement = int.Parse(allArgs[allArgs.Count - 1]);
         *                      allArgs.RemoveAt(allArgs.Count - 1);
         *                      IDiscordRole role = e.Guild.Roles
         *                              .Find(r => r.Name.ToLower() == string.Join(" ", allArgs).TrimEnd(' ').TrimStart(' ').ToLower());
         *
         *                      if (role == null)
         *                      {
         *                              e.ErrorEmbed(e.GetResource("error_role_not_found"))
         *                                      .QueueToChannel(e.Channel);
         *                              return;
         *                      }
         *
         *                      LevelRole lr = await context.LevelRoles.FindAsync(e.Guild.Id.ToDbLong(), role.Id.ToDbLong());
         *                      if (lr == null)
         *                      {
         *                              lr = context.LevelRoles.Add(new LevelRole()
         *                              {
         *                                      GuildId = e.Guild.Id.ToDbLong(),
         *                                      RoleId = role.Id.ToDbLong(),
         *                                      RequiredLevel = levelrequirement
         *                              }).Entity;
         *
         *                              IDiscordEmbed embed = Utils.Embed;
         *                              embed.Title = "Added Role!";
         *                              embed.Description = $"I'll give someone the role {role.Name} when he/she reaches level {levelrequirement}!";
         *
         *                              IDiscordUser currentUser = await e.GetCurrentUserAsync();
         *
         *                              if (!currentUser.HasPermissions(e.Channel, DiscordGuildPermission.ManageRoles))
         *                              {
         *                                      embed.AddInlineField(e.GetResource("miki_warning"), e.GetResource("setrolelevel_error_no_permissions", $"`{e.GetResource("permission_manage_roles")}`"));
         *                              }
         *
         *                              embed.QueueToChannel(e.Channel);
         *                      }
         *                      else
         *                      {
         *                              lr.RequiredLevel = levelrequirement;
         *
         *                              IDiscordEmbed embed = Utils.Embed;
         *                              embed.Title = "Updated Role!";
         *                              embed.Description = $"I'll give someone the role {role.Name} when he/she reaches level {levelrequirement}!";
         *                              embed.QueueToChannel(e.Channel);
         *                      }
         *                      await context.SaveChangesAsync();
         *              }
         *              else
         *              {
         *                      e.ErrorEmbed("Make sure to fill out both the role and the level when creating this!")
         *                              .QueueToChannel(e.Channel);
         *              }
         *      }
         * }*/

        //[Command(Name = "mybadges")]
        //public async Task MyBadgesAsync(EventContext e)
        //{
        //	int page = 0;
        //	using (var context = new MikiContext())
        //	{
        //		User u = await context.Users.FindAsync(e.Author.Id.ToDbLong());

        //		string output = string.Join<long>(" ", u.BadgesOwned.Select(x => x.Id).ToList());

        //		await e.Channel.SendMessage(output.DefaultIfEmpty("none, yet!"));
        //	}
        //}

        public async Task ShowLeaderboardsAsync(IDiscordMessage mContext, LeaderboardsOptions leaderboardOptions)
        {
            using (var context = new MikiContext())
            {
                Locale locale = new Locale(mContext.Channel.Id);

                int p = Math.Max(leaderboardOptions.pageNumber - 1, 0);

                if (Global.MikiApi == null)
                {
                    IDiscordEmbed embed = Utils.Embed
                                          .SetColor(1.0f, 0.6f, 0.4f);

                    switch (leaderboardOptions.type)
                    {
                    case LeaderboardsType.COMMANDS:
                    {
                        embed.Title = locale.GetString("miki_module_accounts_leaderboards_commands_header");
                        if (leaderboardOptions.mentionedUserId != 0)
                        {
                            long mentionedId = leaderboardOptions.mentionedUserId.ToDbLong();

                            var mentionedUser = await context.Users.FindAsync(mentionedId);

                            p = (int)Math.Ceiling((double)(((await mentionedUser.GetGlobalCommandsRankAsync()) - 1) / 12));
                        }
                        List <User> output = await context.Users
                                             .OrderByDescending(x => x.Total_Commands)
                                             .Skip(12 * p)
                                             .Take(12)
                                             .ToListAsync();

                        for (int i = 0; i < output.Count; i++)
                        {
                            string nameToOutput = leaderboardOptions.mentionedUserId != 0 ? string.Join("", output[i].Name.Take(16)) : "~" + string.Join("", output[i].Name.Take(16)) + "~";
                            embed.AddInlineField($"#{i + (12 * p) + 1}: {nameToOutput}", $"{output[i].Total_Commands} commands used!");
                        }
                    }
                    break;

                    case LeaderboardsType.CURRENCY:
                    {
                        embed.Title = locale.GetString("miki_module_accounts_leaderboards_mekos_header");
                        if (leaderboardOptions.mentionedUserId != 0)
                        {
                            long mentionedId   = leaderboardOptions.mentionedUserId.ToDbLong();
                            var  mentionedUser = await context.Users.FindAsync(mentionedId);

                            p = (int)Math.Ceiling((double)(((await mentionedUser.GetGlobalMekosRankAsync()) - 1) / 12));
                        }
                        List <User> output = await context.Users
                                             .OrderByDescending(x => x.Currency)
                                             .Skip(12 * p)
                                             .Take(12)
                                             .ToListAsync();

                        for (int i = 0; i < output.Count; i++)
                        {
                            embed.AddInlineField($"#{i + (12 * p) + 1}: {string.Join("", output[i].Name.Take(16))}",
                                                 $"{output[i].Currency} mekos!");
                        }
                    }
                    break;

                    case LeaderboardsType.EXPERIENCE:
                    {
                        embed.Title = locale.GetString("miki_module_accounts_leaderboards_header");
                        if (leaderboardOptions.mentionedUserId != 0)
                        {
                            long mentionedId   = leaderboardOptions.mentionedUserId.ToDbLong();
                            var  mentionedUser = await context.Users.FindAsync(mentionedId);

                            p = (int)Math.Ceiling((double)(((await mentionedUser.GetGlobalRankAsync()) - 1) / 12));
                        }
                        List <User> output = await context.Users
                                             .OrderByDescending(x => x.Total_Experience)
                                             .Skip(12 * p)
                                             .Take(12)
                                             .ToListAsync();

                        for (int i = 0; i < output.Count; i++)
                        {
                            embed.AddInlineField($"#{i + (12 * p) + 1}: {string.Join("", output[i].Name.Take(16))}",
                                                 $"{output[i].Total_Experience} experience!");
                        }
                    }
                    break;

                    case LeaderboardsType.REPUTATION:
                    {
                        embed.Title = locale.GetString("miki_module_accounts_leaderboards_reputation_header");
                        if (leaderboardOptions.mentionedUserId != 0)
                        {
                            long mentionedId   = leaderboardOptions.mentionedUserId.ToDbLong();
                            var  mentionedUser = await context.Users.FindAsync(mentionedId);

                            p = (int)Math.Ceiling((double)(((await mentionedUser.GetGlobalReputationRankAsync()) - 1) / 12));
                        }
                        List <User> output = await context.Users
                                             .OrderByDescending(x => x.Reputation)
                                             .Skip(12 * p)
                                             .Take(12)
                                             .ToListAsync();

                        for (int i = 0; i < output.Count; i++)
                        {
                            embed.AddInlineField($"#{i + (12 * p) + 1}: {string.Join("", output[i].Name.Take(16))}",
                                                 $"{output[i].Reputation} reputation!");
                        }
                    }
                    break;

                    case LeaderboardsType.PASTA:
                    {
                        List <GlobalPasta> leaderboards = await context.Pastas
                                                          .OrderByDescending(x => x.Score)
                                                          .Skip(12 * p)
                                                          .Take(12)
                                                          .ToListAsync();

                        embed.SetTitle(locale.GetString("toppasta_title"));

                        foreach (GlobalPasta t in leaderboards)
                        {
                            int amount = t.Score;
                            embed.AddInlineField(t.Id, (t == leaderboards.First() ? "💖 " + amount : (amount < 0 ? "💔 " : "� ") + amount));
                        }
                    }
                    break;
                    }


                    embed.SetFooter(locale.GetString("page_index", p + 1, Math.Ceiling(context.Users.Count() / 12f)), "")
                    .QueueToChannel(mContext.Channel);
                }
                else
                {
                    LeaderboardsObject obj = await Global.MikiApi.GetPagedLeaderboardsAsync(leaderboardOptions);

                    Utils.RenderLeaderboards(Utils.Embed, obj.items, obj.currentPage * 10)
                    .SetFooter(locale.GetString("page_index", p + 1, Math.Ceiling((double)obj.totalItems / 10)), "")
                    .SetTitle($"Leaderboards: {leaderboardOptions.type.ToString()}")
                    .QueueToChannel(mContext.Channel);
                }
            }
        }