Пример #1
0
        public override Task <bool> ExecuteCheckAsync(CommandContext context, bool help)
        {
            GuildSettingsContext settingsContext = (GuildSettingsContext)context.Services.GetService(typeof(GuildSettingsContext));

            if (settingsContext == null)
            {
                return(Task.FromResult(true));
            }
            bool  result  = true;
            var   command = context.Command;
            ulong guildId = context.GetGuild().Id;

            while (command != null)
            {
                result  = !settingsContext.IsCommandDisabled(guildId, command.QualifiedName);
                command = result ? command.Parent : null;
            }

            if (result)
            {
                var userRestrictions = settingsContext.GetUserRestriction(guildId, context.User.Id);
                if (userRestrictions?.RestrictedCommands != null)
                {
                    result = userRestrictions.FindCommandRestriction(context.Command.QualifiedName) == null;
                }
            }
            return(Task.FromResult(result || help));
        }
Пример #2
0
            public async Task EnableCommandFor(CommandContext context, string userName, [RemainingText] string commandName)
            {
                var guild         = context.GetGuild();
                var nameFragments = commandName.Split(".");
                var user          = guild.FindMember(userName);

                if (user == null)
                {
                    await context.RespondAsync($"Can not find the user '{userName}'.");

                    return;
                }

                CommandRestriction restriction = _context.GetUserRestriction(guild.Id, user.Id)?.FindCommandRestriction(commandName);

                if (restriction == null)
                {
                    await context.RespondAsync("The user is already allowed to use this command.");

                    return;
                }
                string botMessage = $"Re-enable command `{restriction.CommandName}` for {user.Username}?";

                await context.CreateConfirmation(
                    botMessage,
                    async() => {
                    this._context.RemoveRestrictionForUser(
                        guild.Id,
                        user.Id,
                        restriction
                        );
                    await context.RespondAsync($"Re-enabled `{restriction.CommandName}` for {user.Username}?.");
                },
                    async() => {
                    await context.RespondAsync("Action aborted. No settings changed.");
                }
                    );
            }