예제 #1
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));
        }
예제 #2
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()));
        }
예제 #3
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()));
        }
		/// <summary>
		/// Performs additional checks to see if the command is allowed to be processed.
		/// </summary>
		/// <param name="context">The context of the command.</param>
		/// <returns>True if the command can be processed.</returns>
		protected virtual Task<bool> AllowCommandAsync(IDiscordBotCommandContext context) {
			return Task.FromResult(true);
		}