Ejemplo n.º 1
0
        public async Task SetExp(EventContext e)
        {
            ArgObject arg = e.Arguments.FirstOrDefault();

            IDiscordUser user = await arg.GetUserAsync(e.Guild);

            arg = arg.Next();

            int amount = arg?.AsInt() ?? 0;

            using (var context = new MikiContext())
            {
                LocalExperience u = await LocalExperience.GetAsync(context, e.Guild.Id.ToDbLong(), user);

                if (u == null)
                {
                    return;
                }
                u.Experience = amount;
                await context.SaveChangesAsync();

                await Global.RedisClient.UpsertAsync($"user:{e.Guild.Id}:{e.Author.Id}:exp", u.Experience);

                e.Channel.QueueMessageAsync(":ok_hand:");
            }
        }
Ejemplo n.º 2
0
        public async Task ShipAsync(EventContext e)
        {
            ArgObject o = e.Arguments.First().TakeUntilEnd();

            IDiscordGuildUser user = await o.GetUserAsync(e.Guild);

            // TODO: implement UserNullException
            if (user == null)
            {
                return;
            }

            if (!await Global.RedisClient.ExistsAsync($"user:{e.Author.Id}:avatar:synced"))
            {
                await Utils.SyncAvatarAsync(e.Author);
            }

            if (!await Global.RedisClient.ExistsAsync($"user:{user.Id}:avatar:synced"))
            {
                await Utils.SyncAvatarAsync(user);
            }

            Random r = new Random((int)((e.Author.Id + user.Id + (ulong)DateTime.Now.DayOfYear) % int.MaxValue));

            int value = r.Next(0, 100);

            Stream s = await imageClient.GetStreamAsync($"/api/ship?me={e.Author.Id}&other={user.Id}&value={value}");

            await e.Channel.SendFileAsync(s, "meme.png");
        }
Ejemplo n.º 3
0
        public async Task WhoIsAsync(EventContext e)
        {
            ArgObject arg = e.Arguments.Join();

            if (arg == null)
            {
                throw new ArgumentNullException();
            }

            IGuildUser user = await arg.GetUserAsync(e.Guild);

            if (user == null)
            {
                user = e.Author as IGuildUser;
            }

            var embed = e.CreateEmbedBuilder();

            embed.WithTitle("whois_title", user.Username);
            embed.embedBuilder.WithColor(0.5f, 0f, 1.0f);

            embed.embedBuilder.ImageUrl = user.GetAvatarUrl();

            var roles = e.Guild.Roles.Where(x => user.RoleIds.Contains(x.Id) && x.Color.RawValue != Color.Default.RawValue).OrderByDescending(x => x.Position);

            Color c = roles.FirstOrDefault()?.Color ?? Color.Default;

            StringBuilder builder = new StringBuilder();

            builder.AppendLine($"User Id      : **{user.Id}**");
            builder.AppendLine($"Username: **{user.Username}#{user.Discriminator} {(string.IsNullOrEmpty(user.Nickname) ? "" : $"({user.Nickname})")}**");
Ejemplo n.º 4
0
        public async Task KickAsync(EventContext e)
        {
            IGuildUser currentUser = await e.Guild.GetCurrentUserAsync();

            ArgObject arg = e.Arguments.FirstOrDefault();

            if (currentUser.GuildPermissions.Has(GuildPermission.KickMembers))
            {
                IGuildUser bannedUser = null;
                bannedUser = await arg?.GetUserAsync(e.Guild) ?? null;

                if (bannedUser == null)
                {
                    e.ErrorEmbed(e.GetResource("ban_error_user_null"))
                    .Build().QueueToChannel(e.Channel);
                    return;
                }

                if ((bannedUser as SocketGuildUser).Hierarchy >= (e.Author as SocketGuildUser).Hierarchy)
                {
                    e.ErrorEmbed(e.GetResource("permission_error_low", "kick")).Build()
                    .QueueToChannel(e.Channel);
                    return;
                }

                if ((bannedUser as SocketGuildUser).Hierarchy >= (currentUser as SocketGuildUser).Hierarchy)
                {
                    e.ErrorEmbed(e.GetResource("permission_error_low", "kick")).Build()
                    .QueueToChannel(e.Channel);
                    return;
                }

                arg = arg.Next();

                string reason = arg.TakeUntilEnd().Argument;

                EmbedBuilder embed = new EmbedBuilder();
                embed.Title       = e.GetResource("miki_module_admin_kick_header");
                embed.Description = e.GetResource("miki_module_admin_kick_description", new object[] { e.Guild.Name });

                if (!string.IsNullOrWhiteSpace(reason))
                {
                    embed.AddInlineField(e.GetResource("miki_module_admin_kick_reason"), reason);
                }

                embed.AddInlineField(e.GetResource("miki_module_admin_kick_by"), e.Author.Username + "#" + e.Author.Discriminator);

                embed.Color = new Color(1, 1, 0);

                await embed.Build().SendToUser(bannedUser);

                await bannedUser.KickAsync(reason);
            }
            else
            {
                e.ErrorEmbed(e.GetResource("permission_needed_error", $"`{e.GetResource("permission_kick_members")}`"))
                .Build().QueueToChannel(e.Channel);
            }
        }
Ejemplo n.º 5
0
        public async Task WhoIsAsync(EventContext e)
        {
            ArgObject arg = e.Arguments.Join();

            if (arg == null)
            {
                throw new ArgumentNullException();
            }

            IDiscordGuildUser user = await arg.GetUserAsync(e.Guild);

            //if (user == null)
            //{
            //	user = e.Author as IGuildUser;
            //}

            var embed = e.CreateEmbedBuilder();

            embed.WithTitle("whois_title", user.Username);
            embed.EmbedBuilder.SetColor(0.5f, 0f, 1.0f);

            embed.EmbedBuilder.ImageUrl = user.GetAvatarUrl();

            var roles = (await e.Guild.GetRolesAsync()).Where(x => user.RoleIds.Contains(x.Id) && x.Color.Value != 0).OrderByDescending(x => x.Position);

            Color c = roles.FirstOrDefault()?.Color ?? new Color(0);

            StringBuilder builder = new StringBuilder();

            builder.AppendLine($"User Id      : **{user.Id}**");
            builder.AppendLine(
                $"Username: **{user.Username}#{user.Discriminator} {(string.IsNullOrEmpty((user as IDiscordGuildUser).Nickname) ? "" : $"({(user as IDiscordGuildUser).Nickname})")}**");
            //builder.AppendLine($"Created at: **{user.CreatedAt.ToString()}**");
            builder.AppendLine($"Joined at   : **{user.JoinedAt.ToString()}**");
            builder.AppendLine($"Color Hex : **#{c.ToHexString()}**");

            embed.AddField(
                e.CreateResource("miki_module_whois_tag_personal"),
                new StringResource(builder.ToString())
                );

            string r = string.Join(" ", roles.Select(x => x.Name));

            if (string.IsNullOrEmpty(r))
            {
                r = "none (yet!)";
            }

            if (r.Length <= 1000)
            {
                embed.AddField(
                    e.CreateResource("miki_module_general_guildinfo_roles"),
                    new StringResource(r)
                    );
            }

            embed.Build().QueueToChannel(e.Channel);
        }
Ejemplo n.º 6
0
        public async Task EditExpAsync(EventContext e)
        {
            ArgObject arg = e.Arguments.FirstOrDefault();

            if (arg == null)
            {
                throw new ArgumentException();
            }

            IDiscordUser target = await arg.GetUserAsync(e.Guild);
        }
Ejemplo n.º 7
0
        public async Task SetMekos(EventContext e)
        {
            ArgObject arg = e.Arguments.FirstOrDefault();

            IDiscordUser user = await arg.GetUserAsync(e.Guild);

            arg = arg.Next();

            int amount = arg?.AsInt() ?? 0;

            using (var context = new MikiContext())
            {
                User u = await context.Users.FindAsync((long)user.Id);

                if (u == null)
                {
                    return;
                }
                u.Currency = amount;
                await context.SaveChangesAsync();

                e.Channel.QueueMessageAsync(":ok_hand:");
            }
        }
Ejemplo n.º 8
0
        public async Task AvatarAsync(EventContext e)
        {
            ArgObject arg = e.Arguments.FirstOrDefault();

            if (arg == null)
            {
                e.Channel.QueueMessageAsync(e.Author.GetAvatarUrl());
            }
            else
            {
                if (arg.Argument == "-s")
                {
                    e.Channel.QueueMessageAsync(e.Guild.IconUrl);
                    return;
                }

                IDiscordGuildUser user = await arg.GetUserAsync(e.Guild);

                if (user != null)
                {
                    e.Channel.QueueMessageAsync(user.GetAvatarUrl());
                }
            }
        }
Ejemplo n.º 9
0
        public async Task GiveMekosAsync(EventContext e)
        {
            if (e.Arguments.Count < 2)
            {
                e.ErrorEmbedResource("give_error_no_arg")
                .ToEmbed().QueueToChannel(e.Channel);
                return;
            }

            ArgObject arg = e.Arguments.FirstOrDefault();

            IDiscordUser user = null;

            if (arg != null)
            {
                user = await arg.GetUserAsync(e.Guild);
            }

            if (user == null)
            {
                e.ErrorEmbedResource("give_error_no_mention")
                .ToEmbed().QueueToChannel(e.Channel);
                return;
            }

            arg = arg.Next();

            int?amount = arg?.AsInt() ?? null;

            if (amount == null)
            {
                e.ErrorEmbedResource("give_error_amount_unparsable")
                .ToEmbed().QueueToChannel(e.Channel);
                return;
            }

            if (amount <= 0)
            {
                e.ErrorEmbedResource("give_error_min_mekos")
                .ToEmbed().QueueToChannel(e.Channel);
                return;
            }

            using (MikiContext context = new MikiContext())
            {
                User sender = await User.GetAsync(context, e.Author);

                User receiver = await User.GetAsync(context, user);

                if (amount.Value <= sender.Currency)
                {
                    await sender.AddCurrencyAsync(-amount.Value, e.Channel, sender);

                    await receiver.AddCurrencyAsync(amount.Value, e.Channel, sender);

                    new EmbedBuilder()
                    {
                        Title       = "🔸 transaction",
                        Description = e.GetResource("give_description", sender.Name, receiver.Name, amount.Value),
                        Color       = new Color(255, 140, 0),
                    }.ToEmbed().QueueToChannel(e.Channel);

                    await context.SaveChangesAsync();
                }
                else
                {
                    e.ErrorEmbedResource("user_error_insufficient_mekos")
                    .ToEmbed().QueueToChannel(e.Channel);
                }
            }
        }
Ejemplo n.º 10
0
        public async Task GiveReputationAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                User giver = await context.Users.FindAsync(e.Author.Id.ToDbLong());

                var repObject = Global.RedisClient.Get <ReputationObject>($"user:{giver.Id}:rep");

                if (repObject == null)
                {
                    repObject = new ReputationObject()
                    {
                        LastReputationGiven  = DateTime.Now,
                        ReputationPointsLeft = 3
                    };
                    await Global.RedisClient.AddAsync($"user:{giver.Id}:rep", repObject, new DateTimeOffset(DateTime.UtcNow.AddDays(1).Date));
                }

                ArgObject arg = e.Arguments.FirstOrDefault();

                if (arg == null)
                {
                    TimeSpan pointReset = (DateTime.Now.AddDays(1).Date - DateTime.Now);

                    new EmbedBuilder()
                    {
                        Title       = (e.GetResource("miki_module_accounts_rep_header")),
                        Description = (e.GetResource("miki_module_accounts_rep_description"))
                    }.AddInlineField(e.GetResource("miki_module_accounts_rep_total_received"), giver.Reputation.ToString())
                    .AddInlineField(e.GetResource("miki_module_accounts_rep_reset"), pointReset.ToTimeString(e.Channel.Id))
                    .AddInlineField(e.GetResource("miki_module_accounts_rep_remaining"), repObject.ReputationPointsLeft)
                    .ToEmbed().QueueToChannel(e.Channel);
                    return;
                }
                else
                {
                    Dictionary <IDiscordUser, int> usersMentioned = new Dictionary <IDiscordUser, int>();

                    EmbedBuilder embed = new EmbedBuilder();

                    int  totalAmountGiven = 0;
                    bool mentionedSelf    = false;

                    while (true || totalAmountGiven <= repObject.ReputationPointsLeft)
                    {
                        if (arg == null)
                        {
                            break;
                        }

                        IDiscordUser u = await arg.GetUserAsync(e.Guild);

                        int amount = 1;

                        if (u == null)
                        {
                            break;
                        }

                        arg = arg?.Next();

                        if ((arg?.AsInt() ?? -1) != -1)
                        {
                            amount = arg.AsInt().Value;
                            arg    = arg.Next();
                        }
                        else if (Utils.IsAll(arg))
                        {
                            amount = repObject.ReputationPointsLeft;
                            arg    = arg.Next();
                        }

                        if (u.Id == e.Author.Id)
                        {
                            mentionedSelf = true;
                            continue;
                        }

                        totalAmountGiven += amount;

                        if (usersMentioned.Keys.Where(x => x.Id == u.Id).Count() > 0)
                        {
                            usersMentioned[usersMentioned.Keys.Where(x => x.Id == u.Id).First()] += amount;
                        }
                        else
                        {
                            usersMentioned.Add(u, amount);
                        }
                    }

                    if (mentionedSelf)
                    {
                        embed.Footer = new EmbedFooter()
                        {
                            Text = e.GetResource("warning_mention_self"),
                        };
                    }

                    if (usersMentioned.Count == 0)
                    {
                        return;
                    }
                    else
                    {
                        if (totalAmountGiven <= 0)
                        {
                            e.ErrorEmbedResource("miki_module_accounts_rep_error_zero")
                            .ToEmbed().QueueToChannel(e.Channel);
                            return;
                        }

                        if (usersMentioned.Sum(x => x.Value) > repObject.ReputationPointsLeft)
                        {
                            e.ErrorEmbedResource("error_rep_limit", usersMentioned.Count, usersMentioned.Sum(x => x.Value), repObject.ReputationPointsLeft)
                            .ToEmbed().QueueToChannel(e.Channel);
                            return;
                        }
                    }

                    embed.Title       = (e.GetResource("miki_module_accounts_rep_header"));
                    embed.Description = (e.GetResource("rep_success"));

                    foreach (var user in usersMentioned)
                    {
                        User receiver = await User.GetAsync(context, user.Key);

                        receiver.Reputation += user.Value;

                        embed.AddInlineField(receiver.Name, string.Format("{0} => {1} (+{2})", receiver.Reputation - user.Value, receiver.Reputation, user.Value));
                    }

                    repObject.ReputationPointsLeft -= (short)(usersMentioned.Sum(x => x.Value));

                    await Global.RedisClient.AddAsync($"user:{giver.Id}:rep", repObject, new DateTimeOffset(DateTime.UtcNow.AddDays(1).Date));

                    embed.AddInlineField(e.GetResource("miki_module_accounts_rep_points_left"), repObject.ReputationPointsLeft)
                    .ToEmbed().QueueToChannel(e.Channel);

                    await context.SaveChangesAsync();
                }
            }
        }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
0
        public async Task MarryAsync(EventContext e)
        {
            long askerId    = 0;
            long receiverId = 0;

            ArgObject args = e.Arguments.FirstOrDefault();

            if (args == null)
            {
                return;
            }

            IDiscordGuildUser user = await args.GetUserAsync(e.Guild);

            if (user == null)
            {
                e.Channel.QueueMessageAsync("Couldn't find this person..");
                return;
            }

            if (user.Id == (await e.Guild.GetSelfAsync()).Id)
            {
                e.Channel.QueueMessageAsync("(´・ω・`)");
                return;
            }

            using (MikiContext context = new MikiContext())
            {
                User mentionedPerson = await User.GetAsync(context, user);

                User currentUser = await User.GetAsync(context, e.Author);

                askerId    = currentUser.Id;
                receiverId = mentionedPerson.Id;

                if (currentUser == null || mentionedPerson == null)
                {
                    e.ErrorEmbed(e.GetResource("miki_module_accounts_marry_error_null")).ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                if (mentionedPerson.Banned)
                {
                    e.ErrorEmbed("This person has been banned from Miki.").ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                if (mentionedPerson.Id == currentUser.Id)
                {
                    e.ErrorEmbed(e.GetResource("miki_module_accounts_marry_error_null")).ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                if (await Marriage.ExistsAsync(context, mentionedPerson.Id, currentUser.Id))
                {
                    e.ErrorEmbed(e.GetResource("miki_module_accounts_marry_error_exists")).ToEmbed().QueueToChannel(e.Channel);
                    return;
                }
            }

            await Marriage.ProposeAsync(askerId, receiverId);

            Utils.Embed
            .SetTitle("💍" + e.GetResource("miki_module_accounts_marry_text", $"**{e.Author.Username}**", $"**{user.Username}**"))
            .SetDescription(e.GetResource("miki_module_accounts_marry_text2", user.Username, e.Author.Username))
            .SetColor(0.4f, 0.4f, 0.8f)
            .SetThumbnail("https://i.imgur.com/TKZSKIp.png")
            .AddInlineField("✅ To accept", $">acceptmarriage @user")
            .AddInlineField("❌ To decline", $">declinemarriage @user")
            .SetFooter("Take your time though! This proposal won't disappear", "")
            .ToEmbed().QueueToChannel(e.Channel);
        }
Ejemplo n.º 13
0
        public async Task KickAsync(EventContext e)
        {
            IDiscordGuildUser currentUser = await e.Guild.GetSelfAsync();

            ArgObject arg = e.Arguments.FirstOrDefault();

            if ((await(e.Channel as IDiscordGuildChannel).GetPermissionsAsync(currentUser)).HasFlag(GuildPermission.KickMembers))
            {
                IDiscordGuildUser bannedUser = null;
                IDiscordGuildUser author     = await e.Guild.GetMemberAsync(e.Author.Id);

                bannedUser = await arg?.GetUserAsync(e.Guild) ?? null;

                if (bannedUser == null)
                {
                    e.ErrorEmbed(e.Locale.GetString("ban_error_user_null"))
                    .ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                if (await bannedUser.GetHierarchyAsync() >= await author.GetHierarchyAsync())
                {
                    e.ErrorEmbed(e.Locale.GetString("permission_error_low", "kick")).ToEmbed()
                    .QueueToChannel(e.Channel);
                    return;
                }

                if (await bannedUser.GetHierarchyAsync() >= await currentUser.GetHierarchyAsync())
                {
                    e.ErrorEmbed(e.Locale.GetString("permission_error_low", "kick")).ToEmbed()
                    .QueueToChannel(e.Channel);
                    return;
                }

                string reason = "";

                if (!arg.IsLast)
                {
                    arg = arg.Next();

                    reason = arg.TakeUntilEnd().Argument;
                }

                EmbedBuilder embed = new EmbedBuilder();
                embed.Title       = e.Locale.GetString("miki_module_admin_kick_header");
                embed.Description = e.Locale.GetString("miki_module_admin_kick_description", new object[] { e.Guild.Name });

                if (!string.IsNullOrWhiteSpace(reason))
                {
                    embed.AddField(e.Locale.GetString("miki_module_admin_kick_reason"), reason, true);
                }

                embed.AddField(e.Locale.GetString("miki_module_admin_kick_by"), e.Author.Username + "#" + e.Author.Discriminator, true);

                embed.Color = new Color(1, 1, 0);

                await embed.ToEmbed().SendToUser(bannedUser);

                await bannedUser.KickAsync(reason);
            }
            else
            {
                e.ErrorEmbed(e.Locale.GetString("permission_needed_error", $"`{e.Locale.GetString("permission_kick_members")}`"))
                .ToEmbed().QueueToChannel(e.Channel);
            }
        }
Ejemplo n.º 14
0
        public async Task FavouritePastaList(EventContext e, bool lovedPastas = true)
        {
            IUser targetUser   = e.Author;
            float totalPerPage = 25f;
            int   page         = 0;

            ArgObject arg = e.Arguments.FirstOrDefault();

            if (arg == null)
            {
                // TODO: error no user found
                return;
            }

            IUser user = await arg.GetUserAsync(e.Guild);

            if (user != null)
            {
                arg = arg.Next();
            }
            else
            {
                user = e.Author;
            }

            page = arg.AsInt() ?? 0;

            using (MikiContext context = new MikiContext())
            {
                long authorId = targetUser.Id.ToDbLong();
                IEnumerable <PastaVote> pastaVotes = context.Votes.Where(x => x.UserId == authorId && x.PositiveVote == lovedPastas);

                int maxPage = (int)Math.Floor(pastaVotes.Count() / totalPerPage);
                page = page > maxPage ? maxPage : page;
                page = page < 0 ? 0 : page;


                if (pastaVotes.Count() <= 0)
                {
                    string loveString  = (lovedPastas ? e.GetResource("miki_module_pasta_loved") : e.GetResource("miki_module_pasta_hated"));
                    string errorString = e.GetResource("miki_module_pasta_favlist_self_none", loveString);
                    if (e.message.MentionedUserIds.Count() >= 1)
                    {
                        errorString = e.GetResource("miki_module_pasta_favlist_mention_none", loveString);
                    }
                    Utils.ErrorEmbed(e, errorString).Build().QueueToChannel(e.Channel);
                    return;
                }

                EmbedBuilder     embed        = Utils.Embed;
                List <PastaVote> neededPastas = pastaVotes.Skip((int)totalPerPage * page).Take((int)totalPerPage).ToList();

                string resultString = string.Join(" ", neededPastas.Select(x => $"`{x.Id}`"));

                string useName = string.IsNullOrEmpty(targetUser.Username) ? targetUser.Username : targetUser.Username;
                embed.WithTitle($"{(lovedPastas ? e.GetResource("miki_module_pasta_loved_header") : e.GetResource("miki_module_pasta_hated_header"))} - {useName}");
                embed.WithDescription(resultString);
                embed.WithFooter(e.GetResource("page_index", page + 1, Math.Ceiling(pastaVotes.Count() / totalPerPage)), "");

                embed.Build().QueueToChannel(e.Channel);
            }
        }
Ejemplo n.º 15
0
        public async Task LeaderboardsAsync(EventContext e)
        {
            LeaderboardsOptions options = new LeaderboardsOptions();

            Args      args     = new Args(e.arguments);
            ArgObject argument = args.Get(0);

            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;

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

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

            // Null-conditional operators do not apply on async methods.
            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) != 0)
            {
                options.pageNumber = argument.AsInt();
                argument           = argument?.Next();
            }

            await ShowLeaderboardsAsync(e.message, options);
        }