private void validateConditions(BaseCommand scope, CommandOperationContext operationContext) throws InvalidCommandArgument { validateConditions(scope.conditions, operationContext); if (scope.parentCommand != null) { validateConditions(scope.parentCommand, operationContext); } }
this.logger = Logger.getLogger(this.getClass().getSimpleName()); getCommandConditions().addCondition("owneronly", context -> { if (context.getIssuer().getEvent().getAuthor().getIdLong() != getBotOwnerId()) { throw new ConditionFailedException("Only the bot owner can use this command."); // TODO: MessageKey getCommandConditions().addCondition("guildonly", context -> { if (context.getIssuer().getEvent().getChannelType() != ChannelType.TEXT) { throw new ConditionFailedException("This command must be used in guild chat."); // TODO: MessageKey getCommandConditions().addCondition("privateonly", context -> { if (context.getIssuer().getEvent().getChannelType() != ChannelType.PRIVATE) { throw new ConditionFailedException("This command must be used in private chat."); // TODO: MessageKey getCommandConditions().addCondition("grouponly", context -> { if (context.getIssuer().getEvent().getChannelType() != ChannelType.GROUP) { throw new ConditionFailedException("This command must be used in group chat."); // TODO: MessageKey
void validateConditions(CommandOperationContext context) throws InvalidCommandArgument { RegisteredCommand cmd = context.getRegisteredCommand(); validateConditions(cmd.conditions, context); validateConditions(cmd.scope, context); }
void invoke(CommandIssuer sender, List<String> args, CommandOperationContext context) { if (!scope.canExecute(sender, this)) { return; } preCommand(); try { this.manager.conditions.validateConditions(context); Map<String, Object> passedArgs = resolveContexts(sender, args); if (passedArgs == null) return; method.invoke(scope, passedArgs.values().toArray()); } catch (Exception e) { handleException(sender, args, e); } postCommand(); } public void preCommand() {}
this.manager.conditions.validateConditions(context, value); passedArgs.put(parameterName, value); this.manager.conditions.validateConditions(context, paramValue); passedArgs.put(parameterName, paramValue);