Example #1
0
        public async Task UsrCmd(CommandOrCrInfo command, PermissionAction action, [Remainder] IGuildUser user)
        {
            await _service.AddPermissions(Context.Guild.Id, new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.User,
                PrimaryTargetId     = user.Id,
                SecondaryTarget     = SecondaryPermissionType.Command,
                SecondaryTargetName = command.Name.ToLowerInvariant(),
                State           = action.Value,
                IsCustomCommand = command.IsCustom,
            }).ConfigureAwait(false);

            if (action.Value)
            {
                await ReplyConfirmLocalizedAsync("ux_enable",
                                                 Format.Code(command.Name),
                                                 GetText("of_command"),
                                                 Format.Code(user.ToString())).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalizedAsync("ux_disable",
                                                 Format.Code(command.Name),
                                                 GetText("of_command"),
                                                 Format.Code(user.ToString())).ConfigureAwait(false);
            }
        }
Example #2
0
        public async Task AllSrvrMdls(PermissionAction action)
        {
            var newPerm = new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.Server,
                PrimaryTargetId     = 0,
                SecondaryTarget     = SecondaryPermissionType.AllModules,
                SecondaryTargetName = "*",
                State = action.Value,
            };

            var allowUser = new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.User,
                PrimaryTargetId     = Context.User.Id,
                SecondaryTarget     = SecondaryPermissionType.AllModules,
                SecondaryTargetName = "*",
                State = true,
            };

            await _service.AddPermissions(Context.Guild.Id,
                                          newPerm,
                                          allowUser);

            if (action.Value)
            {
                await ReplyConfirmLocalized("asm_enable").ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("asm_disable").ConfigureAwait(false);
            }
        }
Example #3
0
        public async Task ChnlCmd(IUserMessage imsg, Command command, PermissionAction action, [Remainder] ITextChannel chnl)
        {
            var channel = (ITextChannel)imsg.Channel;

            try
            {
                using (var uow = DbHandler.UnitOfWork())
                {
                    var newPerm = new Permission
                    {
                        PrimaryTarget       = PrimaryPermissionType.Channel,
                        PrimaryTargetId     = chnl.Id,
                        SecondaryTarget     = SecondaryPermissionType.Command,
                        SecondaryTargetName = command.Text.ToLowerInvariant(),
                        State = action.Value,
                    };
                    var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
                    Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
                    {
                        PermRole       = config.PermissionRole,
                        RootPermission = config.RootPermission,
                        Verbose        = config.VerbosePermissions
                    }, (id, old) => { old.RootPermission = config.RootPermission; return(old); });
                    await uow.CompleteAsync().ConfigureAwait(false);
                }
            }
            catch (Exception ex) {
                Console.WriteLine(ex);
            }
            await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command for `{chnl}` channel.").ConfigureAwait(false);
        }
Example #4
0
        public async Task AllRoleMdls(PermissionAction action, [Remainder] IRole role)
        {
            if (role == role.Guild.EveryoneRole)
            {
                return;
            }

            await _service.AddPermissions(Context.Guild.Id, new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.Role,
                PrimaryTargetId     = role.Id,
                SecondaryTarget     = SecondaryPermissionType.AllModules,
                SecondaryTargetName = "*",
                State = action.Value,
            });

            if (action.Value)
            {
                await ReplyConfirmLocalized("arm_enable",
                                            Format.Code(role.Name)).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("arm_disable",
                                            Format.Code(role.Name)).ConfigureAwait(false);
            }
        }
Example #5
0
        public async Task SrvrCmd(CommandOrCrInfo command, PermissionAction action)
        {
            await _service.AddPermissions(Context.Guild.Id, new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.Server,
                PrimaryTargetId     = 0,
                SecondaryTarget     = SecondaryPermissionType.Command,
                SecondaryTargetName = command.Name.ToLowerInvariant(),
                State           = action.Value,
                IsCustomCommand = command.IsCustom,
            }).ConfigureAwait(false);

            if (action.Value)
            {
                await ReplyConfirmLocalized("sx_enable",
                                            Format.Code(command.Name),
                                            GetText("of_command")).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("sx_disable",
                                            Format.Code(command.Name),
                                            GetText("of_command")).ConfigureAwait(false);
            }
        }
Example #6
0
        public async Task RoleCmd(CommandOrCrInfo command, PermissionAction action, [Leftover] IRole role)
        {
            if (role == role.Guild.EveryoneRole)
            {
                return;
            }

            await _service.AddPermissions(ctx.Guild.Id, new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.Role,
                PrimaryTargetId     = role.Id,
                SecondaryTarget     = SecondaryPermissionType.Command,
                SecondaryTargetName = command.Name.ToLowerInvariant(),
                State           = action.Value,
                IsCustomCommand = command.IsCustom,
            }).ConfigureAwait(false);

            if (action.Value)
            {
                await ReplyConfirmLocalizedAsync("rx_enable",
                                                 Format.Code(command.Name),
                                                 GetText("of_command"),
                                                 Format.Code(role.Name)).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalizedAsync("rx_disable",
                                                 Format.Code(command.Name),
                                                 GetText("of_command"),
                                                 Format.Code(role.Name)).ConfigureAwait(false);
            }
        }
Example #7
0
        public async Task SrvrCmd(IUserMessage imsg, Command command, PermissionAction action)
        {
            var channel = (ITextChannel)imsg.Channel;

            using (var uow = DbHandler.UnitOfWork())
            {
                var newPerm = new Permission
                {
                    PrimaryTarget       = PrimaryPermissionType.Server,
                    PrimaryTargetId     = 0,
                    SecondaryTarget     = SecondaryPermissionType.Command,
                    SecondaryTargetName = command.Text.ToLowerInvariant(),
                    State = action.Value,
                };
                var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
                Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
                {
                    PermRole       = config.PermissionRole,
                    RootPermission = config.RootPermission,
                    Verbose        = config.VerbosePermissions
                }, (id, old) => { old.RootPermission = config.RootPermission; return(old); });

                await uow.CompleteAsync().ConfigureAwait(false);
            }
            await channel.SendMessageAsync($"{(action.Value ? "✅ Allowed" : "🆗 Denied")} usage of `{command.Text}` command on this server.").ConfigureAwait(false);
        }
Example #8
0
        public async Task ChnlCmd(CommandOrCrInfo command, PermissionAction action, [Leftover] ITextChannel chnl)
        {
            await _service.AddPermissions(ctx.Guild.Id, new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.Channel,
                PrimaryTargetId     = chnl.Id,
                SecondaryTarget     = SecondaryPermissionType.Command,
                SecondaryTargetName = command.Name.ToLowerInvariant(),
                State           = action.Value,
                IsCustomCommand = command.IsCustom,
            }).ConfigureAwait(false);

            if (action.Value)
            {
                await ReplyConfirmLocalizedAsync("cx_enable",
                                                 Format.Code(command.Name),
                                                 GetText("of_command"),
                                                 Format.Code(chnl.Name)).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalizedAsync("cx_disable",
                                                 Format.Code(command.Name),
                                                 GetText("of_command"),
                                                 Format.Code(chnl.Name)).ConfigureAwait(false);
            }
        }
Example #9
0
        public async Task RoleMdl(ModuleOrCrInfo module, PermissionAction action, [Remainder] IRole role)
        {
            if (role == role.Guild.EveryoneRole)
            {
                return;
            }

            await _service.AddPermissions(Context.Guild.Id, new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.Role,
                PrimaryTargetId     = role.Id,
                SecondaryTarget     = SecondaryPermissionType.Module,
                SecondaryTargetName = module.Name.ToLowerInvariant(),
                State = action.Value,
            });


            if (action.Value)
            {
                await ReplyConfirmLocalized("rx_enable",
                                            Format.Code(module.Name),
                                            GetText("of_module"),
                                            Format.Code(role.Name)).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("rx_disable",
                                            Format.Code(module.Name),
                                            GetText("of_module"),
                                            Format.Code(role.Name)).ConfigureAwait(false);
            }
        }
Example #10
0
        public async Task UsrMdl(ModuleOrCrInfo module, PermissionAction action, [Remainder] IGuildUser user)
        {
            await _service.AddPermissions(Context.Guild.Id, new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.User,
                PrimaryTargetId     = user.Id,
                SecondaryTarget     = SecondaryPermissionType.Module,
                SecondaryTargetName = module.Name.ToLowerInvariant(),
                State = action.Value,
            });

            if (action.Value)
            {
                await ReplyConfirmLocalized("ux_enable",
                                            Format.Code(module.Name),
                                            GetText("of_module"),
                                            Format.Code(user.ToString())).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("ux_disable",
                                            Format.Code(module.Name),
                                            GetText("of_module"),
                                            Format.Code(user.ToString())).ConfigureAwait(false);
            }
        }
Example #11
0
        public async Task ChnlCmd(CommandOrCrInfo command, PermissionAction action, [Remainder] ITextChannel chnl)
        {
            await AddPermissions(Context.Guild.Id, new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.Channel,
                PrimaryTargetId     = (long)chnl.Id,
                SecondaryTarget     = SecondaryPermissionType.Command,
                SecondaryTargetName = command.Name.ToLowerInvariant(),
                State = action.Value,
            });

            if (action.Value)
            {
                await ReplyConfirmLocalized("cx_enable",
                                            Format.Code(command.Name),
                                            GetText("of_command"),
                                            Format.Code(chnl.Name)).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("cx_disable",
                                            Format.Code(command.Name),
                                            GetText("of_command"),
                                            Format.Code(chnl.Name)).ConfigureAwait(false);
            }
        }
Example #12
0
        public async Task AllSrvrMdls(PermissionAction action)
        {
            using (var uow = DbHandler.UnitOfWork())
            {
                var newPerm = new Permission
                {
                    PrimaryTarget       = PrimaryPermissionType.Server,
                    PrimaryTargetId     = 0,
                    SecondaryTarget     = SecondaryPermissionType.AllModules,
                    SecondaryTargetName = "*",
                    State = action.Value,
                };
                uow.GuildConfigs.SetNewRootPermission(Context.Guild.Id, newPerm);

                var allowUser = new Permission
                {
                    PrimaryTarget       = PrimaryPermissionType.User,
                    PrimaryTargetId     = Context.User.Id,
                    SecondaryTarget     = SecondaryPermissionType.AllModules,
                    SecondaryTargetName = "*",
                    State = true,
                };

                var config = uow.GuildConfigs.SetNewRootPermission(Context.Guild.Id, allowUser);
                Cache.AddOrUpdate(Context.Guild.Id, new PermissionCache()
                {
                    PermRole       = config.PermissionRole,
                    RootPermission = config.RootPermission,
                    Verbose        = config.VerbosePermissions
                }, (id, old) => { old.RootPermission = config.RootPermission; return(old); });
                await uow.CompleteAsync().ConfigureAwait(false);
            }
            await Context.Channel.SendConfirmAsync($"{(action.Value ? "✅ Allowed" : "🆗 Denied")} usage of `ALL MODULES` on this server.").ConfigureAwait(false);
        }
Example #13
0
 public async Task ChnlCmd(CommandInfo command, PermissionAction action, [Remainder] ITextChannel chnl)
 {
     try
     {
         using (var uow = DbHandler.UnitOfWork())
         {
             var newPerm = new Permission
             {
                 PrimaryTarget       = PrimaryPermissionType.Channel,
                 PrimaryTargetId     = chnl.Id,
                 SecondaryTarget     = SecondaryPermissionType.Command,
                 SecondaryTargetName = command.Aliases.First().ToLowerInvariant(),
                 State = action.Value,
             };
             var config = uow.GuildConfigs.SetNewRootPermission(Context.Guild.Id, newPerm);
             Cache.AddOrUpdate(Context.Guild.Id, new PermissionCache()
             {
                 PermRole       = config.PermissionRole,
                 RootPermission = config.RootPermission,
                 Verbose        = config.VerbosePermissions
             }, (id, old) => { old.RootPermission = config.RootPermission; return(old); });
             await uow.CompleteAsync().ConfigureAwait(false);
         }
     }
     catch (Exception ex) {
         _log.Error(ex);
     }
     await Context.Channel.SendConfirmAsync($"{(action.Value ? "✅ Allowed" : "🆗 Denied")} usage of `{command.Aliases.First()}` command for `{chnl}` channel.").ConfigureAwait(false);
 }
Example #14
0
        public async Task AllRoleMdls(PermissionAction action, [Remainder] IRole role)
        {
            if (role == role.Guild.EveryoneRole)
            {
                return;
            }

            using (var uow = DbHandler.UnitOfWork())
            {
                var newPerm = new Permission
                {
                    PrimaryTarget       = PrimaryPermissionType.Role,
                    PrimaryTargetId     = role.Id,
                    SecondaryTarget     = SecondaryPermissionType.AllModules,
                    SecondaryTargetName = "*",
                    State = action.Value,
                };
                var config = uow.GuildConfigs.SetNewRootPermission(Context.Guild.Id, newPerm);
                Cache.AddOrUpdate(Context.Guild.Id, new PermissionCache()
                {
                    PermRole       = config.PermissionRole,
                    RootPermission = config.RootPermission,
                    Verbose        = config.VerbosePermissions
                }, (id, old) => { old.RootPermission = config.RootPermission; return(old); });
                await uow.CompleteAsync().ConfigureAwait(false);
            }
            await Context.Channel.SendConfirmAsync($"{(action.Value ? "✅ Allowed" : "🆗 Denied")} usage of `ALL MODULES` for `{role}` role.").ConfigureAwait(false);
        }
Example #15
0
        public async Task ChnlMdl(ModuleOrCrInfo module, PermissionAction action, [Remainder] ITextChannel chnl)
        {
            await _service.AddPermissions(Context.Guild.Id, new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.Channel,
                PrimaryTargetId     = chnl.Id,
                SecondaryTarget     = SecondaryPermissionType.Module,
                SecondaryTargetName = module.Name.ToLowerInvariant(),
                State = action.Value,
            });

            if (action.Value)
            {
                await ReplyConfirmLocalized("cx_enable",
                                            Format.Code(module.Name),
                                            GetText("of_module"),
                                            Format.Code(chnl.Name)).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("cx_disable",
                                            Format.Code(module.Name),
                                            GetText("of_module"),
                                            Format.Code(chnl.Name)).ConfigureAwait(false);
            }
        }
Example #16
0
        public async Task AllUsrMdls(IUserMessage imsg, PermissionAction action, [Remainder] IUser user)
        {
            var channel = (ITextChannel)imsg.Channel;

            using (var uow = DbHandler.UnitOfWork())
            {
                var newPerm = new Permission
                {
                    PrimaryTarget       = PrimaryPermissionType.User,
                    PrimaryTargetId     = user.Id,
                    SecondaryTarget     = SecondaryPermissionType.AllModules,
                    SecondaryTargetName = "*",
                    State = action.Value,
                };
                var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
                Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
                {
                    PermRole       = config.PermissionRole,
                    RootPermission = config.RootPermission,
                    Verbose        = config.VerbosePermissions
                }, (id, old) => { old.RootPermission = config.RootPermission; return(old); });
                await uow.CompleteAsync().ConfigureAwait(false);
            }
            await channel.SendMessageAsync($"{(action.Value ? "✅ Allowed" : "🆗 Denied")} usage of `ALL MODULES` for `{user}` user.").ConfigureAwait(false);
        }
Example #17
0
        public async Task ChnlMdl(IUserMessage imsg, Module module, PermissionAction action, [Remainder] ITextChannel chnl)
        {
            var channel = (ITextChannel)imsg.Channel;

            using (var uow = DbHandler.UnitOfWork())
            {
                var newPerm = new Permission
                {
                    PrimaryTarget       = PrimaryPermissionType.Channel,
                    PrimaryTargetId     = chnl.Id,
                    SecondaryTarget     = SecondaryPermissionType.Module,
                    SecondaryTargetName = module.Name.ToLowerInvariant(),
                    State = action.Value,
                };
                var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
                Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
                {
                    PermRole       = config.PermissionRole,
                    RootPermission = config.RootPermission,
                    Verbose        = config.VerbosePermissions
                }, (id, old) => { old.RootPermission = config.RootPermission; return(old); });
                await uow.CompleteAsync().ConfigureAwait(false);
            }
            await channel.SendMessageAsync($"{(action.Value ? "✅ Allowed" : "🆗 Denied")} usage of `{module.Name}` module for `{chnl}` channel.").ConfigureAwait(false);
        }
Example #18
0
        public async Task AllUsrMdls(PermissionAction action, [Remainder] IUser user)
        {
            using (var uow = DbHandler.UnitOfWork())
            {
                var newPerm = new Permission
                {
                    PrimaryTarget       = PrimaryPermissionType.User,
                    PrimaryTargetId     = user.Id,
                    SecondaryTarget     = SecondaryPermissionType.AllModules,
                    SecondaryTargetName = "*",
                    State = action.Value,
                };
                var config = uow.GuildConfigs.SetNewRootPermission(Context.Guild.Id, newPerm);
                Cache.AddOrUpdate(Context.Guild.Id, new PermissionCache()
                {
                    PermRole       = config.PermissionRole,
                    RootPermission = config.RootPermission,
                    Verbose        = config.VerbosePermissions
                }, (id, old) => { old.RootPermission = config.RootPermission; return(old); });
                await uow.CompleteAsync().ConfigureAwait(false);
            }

            if (action.Value)
            {
                await ReplyConfirmLocalized("aum_enable",
                                            Format.Code(user.ToString())).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("aum_disable",
                                            Format.Code(user.ToString())).ConfigureAwait(false);
            }
        }
Example #19
0
        public async Task SrvrMdl(ModuleInfo module, PermissionAction action)
        {
            using (var uow = DbHandler.UnitOfWork())
            {
                var newPerm = new Permission
                {
                    PrimaryTarget       = PrimaryPermissionType.Server,
                    PrimaryTargetId     = 0,
                    SecondaryTarget     = SecondaryPermissionType.Module,
                    SecondaryTargetName = module.Name.ToLowerInvariant(),
                    State = action.Value,
                };
                var config = uow.GuildConfigs.SetNewRootPermission(Context.Guild.Id, newPerm);
                Cache.AddOrUpdate(Context.Guild.Id, new PermissionCache()
                {
                    PermRole       = config.PermissionRole,
                    RootPermission = config.RootPermission,
                    Verbose        = config.VerbosePermissions
                }, (id, old) => { old.RootPermission = config.RootPermission; return(old); });
                await uow.CompleteAsync().ConfigureAwait(false);
            }

            if (action.Value)
            {
                await ReplyConfirmLocalized("sx_enable",
                                            Format.Code(module.Name),
                                            GetText("of_module")).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("sx_disable",
                                            Format.Code(module.Name),
                                            GetText("of_module")).ConfigureAwait(false);
            }
        }
Example #20
0
        public async Task Verbose(PermissionAction action)
        {
            using (var uow = DbHandler.UnitOfWork())
            {
                var config = uow.GuildConfigs.For(Context.Guild.Id, set => set);
                config.VerbosePermissions = action.Value;
                Cache.AddOrUpdate(Context.Guild.Id, new PermissionCache()
                {
                    PermRole       = config.PermissionRole,
                    RootPermission = Permission.GetDefaultRoot(),
                    Verbose        = config.VerbosePermissions
                }, (id, old) => { old.Verbose = config.VerbosePermissions; return(old); });
                await uow.CompleteAsync().ConfigureAwait(false);
            }

            await Context.Channel.SendConfirmAsync("ℹī¸ I will " + (action.Value ? "now" : "no longer") + " show permission warnings.").ConfigureAwait(false);
        }
Example #21
0
        public async Task Verbose(PermissionAction action)
        {
            using (var uow = _db.GetDbContext())
            {
                var config = uow.GuildConfigs.GcWithPermissionsv2For(ctx.Guild.Id);
                config.VerbosePermissions = action.Value;
                await uow.SaveChangesAsync();

                _service.UpdateCache(config);
            }
            if (action.Value)
            {
                await ReplyConfirmLocalizedAsync("verbose_true").ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalizedAsync("verbose_false").ConfigureAwait(false);
            }
        }
Example #22
0
        public async Task Verbose(IUserMessage msg, PermissionAction action)
        {
            var channel = (ITextChannel)msg.Channel;

            using (var uow = DbHandler.UnitOfWork())
            {
                var config = uow.GuildConfigs.For(channel.Guild.Id);
                config.VerbosePermissions = action.Value;
                Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
                {
                    PermRole = config.PermissionRole,
                    RootPermission = Permission.GetDefaultRoot(),
                    Verbose = config.VerbosePermissions
                }, (id, old) => { old.Verbose = config.VerbosePermissions; return old; });
                await uow.CompleteAsync().ConfigureAwait(false);
            }

            await channel.SendMessageAsync("ℹī¸ I will " + (action.Value ? "now" : "no longer") + " show permission warnings.").ConfigureAwait(false);
        }
Example #23
0
        public async Task Verbose(PermissionAction action)
        {
            using (var uow = _db.UnitOfWork)
            {
                var config = uow.GuildConfigs.GcWithPermissionsv2For(Context.Guild.Id);
                config.VerbosePermissions = action.Value;
                await uow.CompleteAsync().ConfigureAwait(false);

                _service.UpdateCache(config);
            }
            if (action.Value)
            {
                await ReplyConfirmLocalized("verbose_true").ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("verbose_false").ConfigureAwait(false);
            }
        }
Example #24
0
        public async Task Verbose(IUserMessage msg, PermissionAction action)
        {
            var channel = (ITextChannel)msg.Channel;

            using (var uow = DbHandler.UnitOfWork())
            {
                var config = uow.GuildConfigs.For(channel.Guild.Id);
                config.VerbosePermissions = action.Value;
                Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
                {
                    PermRole       = config.PermissionRole,
                    RootPermission = Permission.GetDefaultRoot(),
                    Verbose        = config.VerbosePermissions
                }, (id, old) => { old.Verbose = config.VerbosePermissions; return(old); });
                await uow.CompleteAsync().ConfigureAwait(false);
            }

            await channel.SendMessageAsync("I will " + (action.Value ? "now" : "no longer") + " show permission warnings.").ConfigureAwait(false);
        }
Example #25
0
        public async Task RoleCmd(CommandInfo command, PermissionAction action, [Remainder] IRole role)
        {
            if (role == role.Guild.EveryoneRole)
            {
                return;
            }

            using (var uow = DbHandler.UnitOfWork())
            {
                var newPerm = new Permission
                {
                    PrimaryTarget       = PrimaryPermissionType.Role,
                    PrimaryTargetId     = role.Id,
                    SecondaryTarget     = SecondaryPermissionType.Command,
                    SecondaryTargetName = command.Aliases.First().ToLowerInvariant(),
                    State = action.Value,
                };
                var config = uow.GuildConfigs.SetNewRootPermission(Context.Guild.Id, newPerm);
                Cache.AddOrUpdate(Context.Guild.Id, new PermissionCache()
                {
                    PermRole       = config.PermissionRole,
                    RootPermission = config.RootPermission,
                    Verbose        = config.VerbosePermissions
                }, (id, old) => { old.RootPermission = config.RootPermission; return(old); });
                await uow.CompleteAsync().ConfigureAwait(false);
            }

            if (action.Value)
            {
                await ReplyConfirmLocalized("rx_enable",
                                            Format.Code(command.Aliases.First()),
                                            GetText("of_command"),
                                            Format.Code(role.Name)).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("rx_disable",
                                            Format.Code(command.Aliases.First()),
                                            GetText("of_command"),
                                            Format.Code(role.Name)).ConfigureAwait(false);
            }
        }
Example #26
0
        public async Task AllChnlMdls(PermissionAction action, [Remainder] ITextChannel chnl)
        {
            await _service.AddPermissions(Context.Guild.Id, new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.Channel,
                PrimaryTargetId     = chnl.Id,
                SecondaryTarget     = SecondaryPermissionType.AllModules,
                SecondaryTargetName = "*",
                State = action.Value,
            });

            if (action.Value)
            {
                await ReplyConfirmLocalized("acm_enable",
                                            Format.Code(chnl.Name)).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("acm_disable",
                                            Format.Code(chnl.Name)).ConfigureAwait(false);
            }
        }
Example #27
0
        public async Task AllUsrMdls(PermissionAction action, [Remainder] IUser user)
        {
            await _service.AddPermissions(Context.Guild.Id, new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.User,
                PrimaryTargetId     = user.Id,
                SecondaryTarget     = SecondaryPermissionType.AllModules,
                SecondaryTargetName = "*",
                State = action.Value,
            });

            if (action.Value)
            {
                await ReplyConfirmLocalized("aum_enable",
                                            Format.Code(user.ToString())).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("aum_disable",
                                            Format.Code(user.ToString())).ConfigureAwait(false);
            }
        }
Example #28
0
 public async Task UsrMdl(ModuleInfo module, PermissionAction action, [Remainder] IGuildUser user)
 {
     using (var uow = DbHandler.UnitOfWork())
     {
         var newPerm = new Permission
         {
             PrimaryTarget       = PrimaryPermissionType.User,
             PrimaryTargetId     = user.Id,
             SecondaryTarget     = SecondaryPermissionType.Module,
             SecondaryTargetName = module.Name.ToLowerInvariant(),
             State = action.Value,
         };
         var config = uow.GuildConfigs.SetNewRootPermission(Context.Guild.Id, newPerm);
         Cache.AddOrUpdate(Context.Guild.Id, new PermissionCache()
         {
             PermRole       = config.PermissionRole,
             RootPermission = config.RootPermission,
             Verbose        = config.VerbosePermissions
         }, (id, old) => { old.RootPermission = config.RootPermission; return(old); });
         await uow.CompleteAsync().ConfigureAwait(false);
     }
     await Context.Channel.SendConfirmAsync($"{(action.Value ? "✅ Allowed" : "🆗 Denied")} usage of `{module.Name}` module for `{user}` user.").ConfigureAwait(false);
 }
Example #29
0
 public async Task Verbose(PermissionAction action)
 {
     using (var uow = DbHandler.UnitOfWork())
     {
         var config = uow.GuildConfigs.For(Context.Guild.Id, set => set);
         config.VerbosePermissions = action.Value;
         Cache.AddOrUpdate(Context.Guild.Id, new PermissionCache()
         {
             PermRole       = config.PermissionRole,
             RootPermission = Permission.GetDefaultRoot(),
             Verbose        = config.VerbosePermissions
         }, (id, old) => { old.Verbose = config.VerbosePermissions; return(old); });
         await uow.CompleteAsync().ConfigureAwait(false);
     }
     if (action.Value)
     {
         await ReplyConfirmLocalized("verbose_true").ConfigureAwait(false);
     }
     else
     {
         await ReplyConfirmLocalized("verbose_false").ConfigureAwait(false);
     }
 }
Example #30
0
        public async Task SrvrMdl(ModuleOrCrInfo module, PermissionAction action)
        {
            await _service.AddPermissions(Context.Guild.Id, new Permissionv2
            {
                PrimaryTarget       = PrimaryPermissionType.Server,
                PrimaryTargetId     = 0,
                SecondaryTarget     = SecondaryPermissionType.Module,
                SecondaryTargetName = module.Name.ToLowerInvariant(),
                State = action.Value,
            });

            if (action.Value)
            {
                await ReplyConfirmLocalized("sx_enable",
                                            Format.Code(module.Name),
                                            GetText("of_module")).ConfigureAwait(false);
            }
            else
            {
                await ReplyConfirmLocalized("sx_disable",
                                            Format.Code(module.Name),
                                            GetText("of_module")).ConfigureAwait(false);
            }
        }
Example #31
0
        public async Task AllSrvrMdls(IUserMessage imsg, PermissionAction action)
        {
            var channel = (ITextChannel)imsg.Channel;

            using (var uow = DbHandler.UnitOfWork())
            {
                var newPerm = new Permission
                {
                    PrimaryTarget = PrimaryPermissionType.Server,
                    PrimaryTargetId = 0,
                    SecondaryTarget = SecondaryPermissionType.AllModules,
                    SecondaryTargetName = "*",
                    State = action.Value,
                };
                uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);

                var allowUser = new Permission
                {
                    PrimaryTarget = PrimaryPermissionType.User,
                    PrimaryTargetId = imsg.Author.Id,
                    SecondaryTarget = SecondaryPermissionType.AllModules,
                    SecondaryTargetName = "*",
                    State = true,
                };

                var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, allowUser);
                Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
                {
                    PermRole = config.PermissionRole,
                    RootPermission = config.RootPermission,
                    Verbose = config.VerbosePermissions
                }, (id, old) => { old.RootPermission = config.RootPermission; return old; });
                await uow.CompleteAsync().ConfigureAwait(false);
            }
            await channel.SendMessageAsync($"{(action.Value ? "✅ Allowed" : "🆗 Denied")} usage of `ALL MODULES` on this server.").ConfigureAwait(false);
        }
Example #32
0
        public async Task SrvrCmd(IUserMessage imsg, Command command, PermissionAction action)
        {
            var channel = (ITextChannel)imsg.Channel;

            using (var uow = DbHandler.UnitOfWork())
            {
                var newPerm = new Permission
                {
                    PrimaryTarget = PrimaryPermissionType.Server,
                    PrimaryTargetId = 0,
                    SecondaryTarget = SecondaryPermissionType.Command,
                    SecondaryTargetName = command.Text.ToLowerInvariant(),
                    State = action.Value,
                };
                var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
                Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
                {
                    PermRole = config.PermissionRole,
                    RootPermission = config.RootPermission,
                    Verbose = config.VerbosePermissions
                }, (id, old) => { old.RootPermission = config.RootPermission; return old; });

                await uow.CompleteAsync().ConfigureAwait(false);
            }
            await channel.SendMessageAsync($"{(action.Value ? "✅ Allowed" : "🆗 Denied")} usage of `{command.Text}` command on this server.").ConfigureAwait(false);
        }
Example #33
0
        public async Task ChnlMdl(IUserMessage imsg, Module module, PermissionAction action, [Remainder] ITextChannel chnl)
        {
            var channel = (ITextChannel)imsg.Channel;

            using (var uow = DbHandler.UnitOfWork())
            {
                var newPerm = new Permission
                {
                    PrimaryTarget = PrimaryPermissionType.Channel,
                    PrimaryTargetId = chnl.Id,
                    SecondaryTarget = SecondaryPermissionType.Module,
                    SecondaryTargetName = module.Name.ToLowerInvariant(),
                    State = action.Value,
                };
                var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
                Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
                {
                    PermRole = config.PermissionRole,
                    RootPermission = config.RootPermission,
                    Verbose = config.VerbosePermissions
                }, (id, old) => { old.RootPermission = config.RootPermission; return old; });
                await uow.CompleteAsync().ConfigureAwait(false);
            }
            await channel.SendMessageAsync($"{(action.Value ? "✅ Allowed" : "🆗 Denied")} usage of `{module.Name}` module for `{chnl}` channel.").ConfigureAwait(false);
        }