Beispiel #1
0
        public bool AddPermission(IRole role, string command)
        {
            if (!ModulePermissionRole.ContainsKey(role.Id))
            {
                ModulePermissionRole.Add(role.Id, new List <PermissionModule>());
            }

            var module = PermissionModule.GetModuleByCommand(command);

            if (ModulePermissionRole[role.Id].All(x => x.Module != module || x.GuildId != role.Guild.Id))
            {
                ModulePermissionRole[role.Id].Add(new PermissionModule(module, role.Guild.Id));
            }

            return(ModulePermissionRole[role.Id].First(x => x.Module == module && x.GuildId == role.Guild.Id).AddCommand(command));
        }
Beispiel #2
0
        public bool AddPermission(IUser user, string command, SocketGuild guild = null)
        {
            if (!ModulePermissionUser.ContainsKey(user.Id))
            {
                ModulePermissionUser.Add(user.Id, new List <PermissionModule>());
            }

            var module = PermissionModule.GetModuleByCommand(command);

            if (ModulePermissionUser[user.Id].All(x => x.Module != module || x.GuildId != guild?.Id))
            {
                ModulePermissionUser[user.Id].Add(new PermissionModule(module, guild?.Id));
            }

            return(ModulePermissionUser[user.Id].First(x => x.Module == module && x.GuildId == guild?.Id).AddCommand(command));
        }
Beispiel #3
0
        public bool DeletePermission(IRole role, string command)
        {
            if (!ModulePermissionRole.ContainsKey(role.Id))
            {
                return(false);
            }

            var module = PermissionModule.GetModuleByCommand(command);

            if (ModulePermissionRole[role.Id].All(x => x.Module != module || x.GuildId != role.Guild.Id))
            {
                return(false);
            }

            var ret = ModulePermissionRole[role.Id].First(x => x.Module == module && x.GuildId == role.Guild.Id).DeleteCommand(command);

            if (ModulePermissionRole[role.Id].First(x => x.Module == module && x.GuildId == role.Guild.Id).Commands.Count == 0)
            {
                ModulePermissionRole.Remove(role.Id);
            }

            return(ret);
        }
Beispiel #4
0
        public bool DeletePermission(IUser user, string command, SocketGuild guild = null)
        {
            if (!ModulePermissionUser.ContainsKey(user.Id))
            {
                return(false);
            }

            var module = PermissionModule.GetModuleByCommand(command);

            if (ModulePermissionUser[user.Id].All(x => x.Module != module || x.GuildId != guild?.Id))
            {
                return(false);
            }

            var ret = ModulePermissionUser[user.Id].First(x => x.Module == module && x.GuildId == guild?.Id).DeleteCommand(command);

            if (ModulePermissionUser[user.Id].First(x => x.Module == module && x.GuildId == guild?.Id).Commands.Count == 0)
            {
                ModulePermissionUser.Remove(user.Id);
            }

            return(ret);
        }