Exemplo n.º 1
0
        /// <summary>
        /// Finds the command with the specified command info.
        /// </summary>
        /// <param name="cmd">The command info to search with.</param>
        /// <param name="context">The optional command context to search with permissions.</param>
        /// <returns>The located command, or null.</returns>
        public CommandDetails Find(CommandInfo cmd, ICommandContext context = null)
        {
            return(Find(cmd.GetDetailsName(), context));

            /*return Commands.Where(c => c.CommandInfos.Contains(cmd))
             *                         .Where(c => context == null || c.IsUsable(context))
             *                         .FirstOrDefault();*/
        }
Exemplo n.º 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()));
        }
Exemplo n.º 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()));
        }
 public static CommandDetails ResolveCommand <T>(this DiscordBotModule <T> module, CommandInfo cmd)
     where T : class, IDiscordBotCommandContext
 {
     return(module.ResolveCommand(cmd.GetDetailsName()));
 }
 public static CommandDetails ResolveCommand(this DiscordBotService service, CommandInfo cmd)
 {
     return(service.ResolveCommand(cmd.GetDetailsName()));
 }