Exemple #1
0
        public async Task Command(int level, [Remainder] SocketRole role)
        {
            const int PREMIUM_LIMIT = Int32.MaxValue;
            const int REG_LIMIT     = 3;

            Server server = await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id);

            int limit = server.IsPremium ? PREMIUM_LIMIT : REG_LIMIT;

            if (level < 1)
            {
                await SendBasicErrorEmbedAsync("The `level` parameter must be at least `1`.");

                return;
            }

            if (level > 100000)
            {
                await SendBasicErrorEmbedAsync($"The maximum level for a role reward is `{100000:N0}`");

                return;
            }

            if (server.RoleRewards.Count() == limit)
            {
                string limitStr     = server.IsPremium ? $"Your premium limit: {PREMIUM_LIMIT:N0}." : $"Your non-premium limit: {REG_LIMIT}.";
                string baseLimitStr = "You have reached your limit of allowed " +
                                      $"concurrent role rewards. Please delete one " +
                                      $"if you still wish to create this reward.\n\n {limitStr}";

                if (server.IsPremium)
                {
                    throw new KaguyaSupportException(baseLimitStr);
                }
                else
                {
                    throw new KaguyaPremiumException($"More than {REG_LIMIT} role rewards.\n" + baseLimitStr);
                }
            }

            var rr = new ServerRoleReward
            {
                ServerId = Context.Guild.Id,
                RoleId   = role.Id,
                Level    = level,
                Server   = server
            };

            await DatabaseQueries.InsertIfNotExistsAsync(rr);

            var embed = new KaguyaEmbedBuilder
            {
                Title       = $"Kaguya Role Rewards",
                Description = $"{Context.User.Mention} Whenever a user reaches " +
                              $"`Server Level {level}`, I will now reward them with {role.Mention}."
            };

            await SendEmbedAsync(embed);
        }
Exemple #2
0
        public async Task Command([Remainder] string arg)
        {
            Server server = await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id);

            SocketRole role  = null;
            int        level = 0;

            if (arg.ToLower() == "clear")
            {
                await DatabaseQueries.DeleteAllForServerAsync <ServerRoleReward>(server.ServerId);
                await SendBasicSuccessEmbedAsync($"Successfully cleared this server's role-reward configuration(s).");

                return;
            }

            if (arg.AsInteger(false) == 0 && arg.AsUlong(false) == 0)
            {
                role = Context.Guild.Roles.First(x => x.Name.ToLower() == arg.ToLower());
            }

            if (arg.AsUlong(false) != 0 && arg.AsInteger(false) > 100000)
            {
                role = Context.Guild.Roles.First(x => x.Id == arg.AsUlong());
            }

            if (arg.AsInteger(false) != 0 && arg.AsInteger(false) <= 100000)
            {
                level = arg.AsInteger();
            }

            if (role == null && level == 0 && server.RoleRewards.Any(x => x.RoleId != arg.AsUlong()))
            {
                await SendBasicErrorEmbedAsync("You did not reply with a proper level or role name/ID.");

                return;
            }

            if (role != null && level == 0 || server.RoleRewards.Any(x => x.RoleId == arg.AsUlong()))
            {
                ServerRoleReward toRemove = role == null
                    ? server.RoleRewards.ToList().First(x => x.RoleId == arg.AsUlong())
                    : server.RoleRewards.First(x => x.RoleId == role.Id);

                if (toRemove == null)
                {
                    throw new KaguyaSupportException("The specified role could not be found in this server's " +
                                                     "role rewards list.");
                }

                await DatabaseQueries.DeleteAsync(toRemove);
                await SendBasicSuccessEmbedAsync($"{Context.User.Mention} Successfully removed role " +
                                                 $"{(role == null ? $"`{toRemove.RoleId}`" : role.Mention)} at `level " +
                                                 $"{toRemove.Level}` from this server's role rewards.");

                return;
            }

            if (role == null && level != 0)
            {
                List <ServerRoleReward> toRemove = server.RoleRewards.Where(x => x.Level == level).ToList();
                if (toRemove.Count != 0)
                {
                    await DatabaseQueries.DeleteAsync(toRemove);

                    await SendBasicSuccessEmbedAsync($"{Context.User.Mention} Successfully deleted " +
                                                     $"all roles for the server that were given " +
                                                     $"at `level {level:N0}`.");

                    return;
                }

                throw new KaguyaSupportException($"There are no role rewards for this server at `level {level:N0}`");
            }

            throw new KaguyaSupportException("There was nothing to remove.");
        }