/// <summary>
 /// Checks if the <paramref name="command"/> has the sufficient permission to be executed.
 /// </summary>
 /// <param name="context">The context of the command.</param>
 /// <param name="command">The command being executed.</param>
 /// <param name="services">The service collection used for dependency injection.</param>
 public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context,
                                                                 CommandInfo command, IServiceProvider services)
 {
     if (context.Channel is ITextChannel text && !text.IsNsfw)
     {
         return(Task.FromResult(PreconditionResult.FromSuccess()));
     }
     return(Task.FromResult(PreconditionAttributeResult.FromError("This command may only be invoked in a SFW channel.", this)));
 }
Пример #2
0
        public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context,
                                                                        ParameterInfo parameter, object value, IServiceProvider services)
        {
            string s = value.ToString();

            if (Constants.Any(c => string.Compare(c, s, IgnoreCase) == 0))
            {
                return(Task.FromResult(PreconditionResult.FromSuccess()));
            }
            return(Task.FromResult(PreconditionAttributeResult.FromError("The parameter does not match one of the required constants", this)));
        }
Пример #3
0
 /// <summary>
 /// Checks if the <paramref name="command"/> has the sufficient permission to be executed.
 /// </summary>
 /// <param name="context">The context of the command.</param>
 /// <param name="command">The command being executed.</param>
 /// <param name="services">The service collection used for dependency injection.</param>
 public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context,
                                                                 CommandInfo command, IServiceProvider services)
 {
     if (!context.User.IsBot)
     {
         return(Task.FromResult(PreconditionResult.FromSuccess()));
     }
     if (Allow)
     {
         return(Task.FromResult(PreconditionResult.FromSuccess()));
     }
     return(Task.FromResult(PreconditionAttributeResult.FromError("Bots cannot use this command", this)));
 }
Пример #4
0
        /// <summary>
        /// Checks if the <paramref name="command"/> has the sufficient permission to be executed.
        /// </summary>
        /// <param name="context">The context of the command.</param>
        /// <param name="command">The command being executed.</param>
        /// <param name="services">The service collection used for dependency injection.</param>
        public override async Task <PreconditionResult> CheckPermissionsAsync(ICommandContext contextBase,
                                                                              CommandInfo command, IServiceProvider services)
        {
            IDiscordBotCommandContext context = (IDiscordBotCommandContext)contextBase;
            var ownerResult = await base.CheckPermissionsAsync(context, command, services).ConfigureAwait(false);

            if (ownerResult.IsSuccess)
            {
                return(PreconditionResult.FromSuccess());
            }
            string[] owners = context.Config.GetArray("ids:discord:superuseres");
            if (owners.Any(id => ulong.Parse(id) == context.User.Id))
            {
                return(PreconditionResult.FromSuccess());
            }
            return(PreconditionAttributeResult.FromError("You are not registed as a superuser of this bot", this));
        }
Пример #5
0
        /// <summary>
        /// Checks if the <paramref name="cmd"/> has the sufficient permission to be executed.
        /// </summary>
        /// <param name="context">The context of the command.</param>
        /// <param name="cmd">The command being executed.</param>
        /// <param name="services">The service collection used for dependency injection.</param>
        public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext contextBase,
                                                                        CommandInfo cmd, IServiceProvider services)
        {
            IDiscordBotCommandContext context = (IDiscordBotCommandContext)contextBase;

            if (context.ManageContext == null)
            {
                return(Task.FromResult(PreconditionAttributeResult.FromError("Not a bot manager", this)));
            }

            CommandDetails command = context.Commands.CommandSet.FindCommand(cmd.GetDetailsName());
            ulong          roleId  = context.ManageContext.ManagerRoleId;

            if (roleId == 0 || !(context.User is IGuildUser guildUser && guildUser.RoleIds.Contains(roleId)))
            {
                return(Task.FromResult(PreconditionAttributeResult.FromError("Not a bot manager", this)));
            }

            return(Task.FromResult(PreconditionResult.FromSuccess()));
        }
Пример #6
0
        /// <summary>
        /// Checks if the <paramref name="cmd"/> has the sufficient permission to be executed.
        /// </summary>
        /// <param name="context">The context of the command.</param>
        /// <param name="cmd">The command being executed.</param>
        /// <param name="services">The service collection used for dependency injection.</param>
        public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext contextBase,
                                                                        CommandInfo cmd, IServiceProvider services)
        {
            IDiscordBotCommandContext context = (IDiscordBotCommandContext)contextBase;

            if (context.LockContext == null)
            {
                return(Task.FromResult(PreconditionResult.FromSuccess()));
            }

            CommandDetails command = context.Commands.CommandSet.FindCommand(cmd.GetDetailsName());

            //IContextingService locking = services.GetService<IContextingService>();
            if (command.IsLocked(context.LockContext))
            {
                return(Task.FromResult(PreconditionAttributeResult.FromError("The command is locked", this)));
            }

            return(Task.FromResult(PreconditionResult.FromSuccess()));
        }