Example #1
0
        public async Task AddRole(IRole role, int level)
        {
            var config = LevelService.TryGetLevelConfig(Context.Guild.Id);

            if (config == null || !config.Enabled)
            {
                await ReplyAsync("You must enable leveling before editing it's settings.");

                return;
            }

            //Remove the role if it already exists in the rewards
            config.RewardRoles = config.RewardRoles.Where(x => x.RoleId != role.Id).ToList();

            if (config.RewardRoles.Any(x => x.LevelRequirement == level))
            {
                await ReplyAsync("There can only be one role per level.");

                return;
            }

            config.RewardRoles.Add(new LevelConfig.LevelReward
            {
                RoleId           = role.Id,
                LevelRequirement = level
            });
            LevelService.Database.Store(config, LevelConfig.DocumentName(Context.Guild.Id));
            await ReplyAsync($"Role Added");
        }
Example #2
0
        public async Task ToggleWhitelist()
        {
            var config = LevelService.GetOrCreateLevelConfig(Context.Guild.Id);

            config.RestrictionMode = LevelConfig.LevelRestrictionType.Whitelist;
            LevelService.Database.Store(config, LevelConfig.DocumentName(Context.Guild.Id));
            await ReplyAsync($"Leveling will now be restricted to channels added with the `addchannel` command");
        }
Example #3
0
        public async Task ToggleLevelingAsync()
        {
            var config = LevelService.GetOrCreateLevelConfig(Context.Guild.Id);

            config.Enabled = !config.Enabled;
            LevelService.Database.Store(config, LevelConfig.DocumentName(Context.Guild.Id));
            await ReplyAsync($"Leveling Enabled: {config.Enabled}");
        }
Example #4
0
        public LevelConfig GetOrCreateLevelConfig(ulong guildId)
        {
            var config = TryGetLevelConfig(guildId);

            if (config == null)
            {
                config = new LevelConfig(guildId);
                Database.Store(config, LevelConfig.DocumentName(guildId));
            }
            return(config);
        }
Example #5
0
        public async Task ToggleMultiRole()
        {
            var config = LevelService.TryGetLevelConfig(Context.Guild.Id);

            if (config == null || !config.Enabled)
            {
                await ReplyAsync("You must enable leveling before editing it's settings.");

                return;
            }

            config.MultiRole = !config.MultiRole;
            LevelService.Database.Store(config, LevelConfig.DocumentName(Context.Guild.Id));
            await ReplyAsync($"Multiple role rewards: {config.MultiRole}");
        }
Example #6
0
        public async Task ToggleLevelUpNotifications()
        {
            var config = LevelService.TryGetLevelConfig(Context.Guild.Id);

            if (config == null || !config.Enabled)
            {
                await ReplyAsync("You must enable leveling before editing it's settings.");

                return;
            }

            config.ReplyLevelUps = !config.ReplyLevelUps;
            LevelService.Database.Store(config, LevelConfig.DocumentName(Context.Guild.Id));
            await ReplyAsync($"Reply Level Ups: {config.ReplyLevelUps}");
        }
Example #7
0
        public async Task DisableLogChannel()
        {
            var config = LevelService.TryGetLevelConfig(Context.Guild.Id);

            if (config == null || !config.Enabled)
            {
                await ReplyAsync("You must enable leveling before editing it's settings.");

                return;
            }

            config.LogChannelId = 0;
            LevelService.Database.Store(config, LevelConfig.DocumentName(Context.Guild.Id));
            await ReplyAsync("Log channel disabled.");
        }
Example #8
0
        public async Task Enable()
        {
            var config = LevelService.TryGetLevelConfig(Context.Guild.Id);

            if (config == null || !config.Enabled)
            {
                await ReplyAsync("You must enable leveling before editing it's settings.");

                return;
            }

            config.LogChannelId = Context.Channel.Id;
            LevelService.Database.Store(config, LevelConfig.DocumentName(Context.Guild.Id));
            await ReplyAsync($"Level up events will be logged to: {Context.Channel.Name}");
        }
Example #9
0
        public async Task RemoveChannel()
        {
            var config = LevelService.GetOrCreateLevelConfig(Context.Guild.Id);

            if (config.RestrictionMode == LevelConfig.LevelRestrictionType.None)
            {
                await ReplyAsync("You must enable either the blacklist or whitelist to use this command.");

                return;
            }

            config.RestrictedChannels.Remove(Context.Channel.Id);
            LevelService.Database.Store(config, LevelConfig.DocumentName(Context.Guild.Id));
            await ReplyAsync($"This channel is now removed from the level {config.RestrictionMode}.");
        }
Example #10
0
        public async Task RemoveChannels()
        {
            var config = LevelService.GetOrCreateLevelConfig(Context.Guild.Id);

            if (config.RestrictionMode == LevelConfig.LevelRestrictionType.None)
            {
                await ReplyAsync("You must enable either the blacklist or whitelist to use this command.");

                return;
            }

            config.RestrictedChannels = new List <ulong>();
            LevelService.Database.Store(config, LevelConfig.DocumentName(Context.Guild.Id));
            await ReplyAsync($"Restricted channels have been cleared.");
        }
Example #11
0
        public async Task RemoveRole(ulong roleId)
        {
            var config = LevelService.TryGetLevelConfig(Context.Guild.Id);

            if (config == null || !config.Enabled)
            {
                await ReplyAsync("You must enable leveling before editing it's settings.");

                return;
            }

            //Remove the role if it already exists in the rewards
            config.RewardRoles = config.RewardRoles.Where(x => x.RoleId != roleId).ToList();
            LevelService.Database.Store(config, LevelConfig.DocumentName(Context.Guild.Id));
            await ReplyAsync($"Role Removed\nNOTE: Users who have this role will still keep it.");
        }
Example #12
0
        public LevelConfig TryGetLevelConfig(ulong guildId)
        {
            var config = Database.Load <LevelConfig>(LevelConfig.DocumentName(guildId));

            return(config);
        }