コード例 #1
0
ファイル: Permissions.cs プロジェクト: twistedshep/Shinoa-Bot
        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);
            }
        }
コード例 #2
0
ファイル: Permissions.cs プロジェクト: tepup/LinBot
        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);
            }
        }
コード例 #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);
        }
コード例 #4
0
ファイル: Permissions.cs プロジェクト: tepup/LinBot
        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);
            }
        }
コード例 #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);
            }
        }
コード例 #6
0
ファイル: Permissions.cs プロジェクト: tsujon12/Nadeko
        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);
            }
        }
コード例 #7
0
ファイル: Permissions.cs プロジェクト: thomasruiz/NadekoBot
        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);
        }
コード例 #8
0
ファイル: Permissions.cs プロジェクト: tsujon12/Nadeko
        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);
            }
        }
コード例 #9
0
ファイル: Permissions.cs プロジェクト: tepup/LinBot
        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);
            }
        }
コード例 #10
0
ファイル: Permissions.cs プロジェクト: tepup/LinBot
        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);
            }
        }
コード例 #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);
            }
        }
コード例 #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);
        }
コード例 #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);
 }
コード例 #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);
        }
コード例 #15
0
ファイル: Permissions.cs プロジェクト: tepup/LinBot
        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);
            }
        }
コード例 #16
0
ファイル: Permissions.cs プロジェクト: thomasruiz/NadekoBot
        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);
        }
コード例 #17
0
ファイル: Permissions.cs プロジェクト: thomasruiz/NadekoBot
        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);
        }
コード例 #18
0
ファイル: Permissions.cs プロジェクト: JDLHiguera/YokoV2
        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);
            }
        }
コード例 #19
0
ファイル: Permissions.cs プロジェクト: JDLHiguera/YokoV2
        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);
            }
        }
コード例 #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);
        }
コード例 #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);
            }
        }
コード例 #22
0
ファイル: Permissions.cs プロジェクト: Chewsterchew/NadekoBot
        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);
        }
コード例 #23
0
ファイル: Permissions.cs プロジェクト: tepup/LinBot
        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);
            }
        }
コード例 #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);
        }
コード例 #25
0
ファイル: Permissions.cs プロジェクト: JDLHiguera/YokoV2
        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);
            }
        }
コード例 #26
0
ファイル: Permissions.cs プロジェクト: tepup/LinBot
        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);
            }
        }
コード例 #27
0
ファイル: Permissions.cs プロジェクト: tepup/LinBot
        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);
            }
        }
コード例 #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);
 }
コード例 #29
0
ファイル: Permissions.cs プロジェクト: JDLHiguera/YokoV2
 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);
     }
 }
コード例 #30
0
ファイル: Permissions.cs プロジェクト: tepup/LinBot
        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);
            }
        }
コード例 #31
0
ファイル: Permissions.cs プロジェクト: Chewsterchew/NadekoBot
        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);
        }
コード例 #32
0
ファイル: Permissions.cs プロジェクト: Chewsterchew/NadekoBot
        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);
        }
コード例 #33
0
ファイル: Permissions.cs プロジェクト: Chewsterchew/NadekoBot
        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);
        }