diff --git a/src/main/java/net/pingex/dcf/commands/AnnotatedCommand.java b/src/main/java/net/pingex/dcf/commands/AnnotatedCommand.java index 1e914ba..5ed3cf4 100644 --- a/src/main/java/net/pingex/dcf/commands/AnnotatedCommand.java +++ b/src/main/java/net/pingex/dcf/commands/AnnotatedCommand.java @@ -1,5 +1,6 @@ package net.pingex.dcf.commands; +import net.pingex.dcf.commands.options.ScopeOption; import net.pingex.dcf.permissions.DefaultPermission; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -46,5 +47,5 @@ public @interface AnnotatedCommand /** * Tells where the command should run, ie. PM or guild chat, or both */ - CommandScope scope() default CommandScope.NOWHERE; + ScopeOption.CommandScope scope() default ScopeOption.CommandScope.NOWHERE; } diff --git a/src/main/java/net/pingex/dcf/commands/Command.java b/src/main/java/net/pingex/dcf/commands/Command.java index 59f04cc..8b70e14 100644 --- a/src/main/java/net/pingex/dcf/commands/Command.java +++ b/src/main/java/net/pingex/dcf/commands/Command.java @@ -1,6 +1,7 @@ package net.pingex.dcf.commands; import net.pingex.dcf.commands.options.ICommandOption; +import net.pingex.dcf.commands.options.ScopeOption; import net.pingex.dcf.permissions.DefaultPermission; import sx.blah.discord.handle.impl.events.MessageReceivedEvent; import java.lang.reflect.Method; @@ -47,7 +48,7 @@ public abstract class Command implements ICommandExecutor /** * Tells where the command should run, ie. PM or guild chat, or both */ - private CommandScope commandScope; + private ScopeOption.CommandScope commandScope; /** * Contains all options for this command. @@ -65,7 +66,7 @@ public abstract class Command implements ICommandExecutor * @param commandScope Tells where the command should run, ie. PM or guild chat, or both * @param options Command options. */ - public Command(String name, List aliases, String description, boolean isEnabled, String usage, DefaultPermission defaultPermission, CommandScope commandScope, Set options) + public Command(String name, List aliases, String description, boolean isEnabled, String usage, DefaultPermission defaultPermission, ScopeOption.CommandScope commandScope, Set options) { this.name = name; this.aliases = aliases; @@ -87,7 +88,7 @@ public abstract class Command implements ICommandExecutor public static final boolean IS_ENABLED = true; public static final String USAGE = "No command usage provided."; public static final DefaultPermission DEFAULT_PERMISSION = DefaultPermission.EVERYONE; - public static final CommandScope COMMAND_SCOPE = CommandScope.NOWHERE; // NOWHERE is enforced as a default value to force devs to specify a real scope. + public static final ScopeOption.CommandScope COMMAND_SCOPE = ScopeOption.CommandScope.NOWHERE; // NOWHERE is enforced as a default value to force devs to specify a real scope. public static final Set OPTIONS = Collections.emptySet(); } @@ -129,7 +130,7 @@ public abstract class Command implements ICommandExecutor /** * Tells where the command should run, ie. PM or guild chat, or both */ - private CommandScope commandScope = Defaults.COMMAND_SCOPE; + private ScopeOption.CommandScope commandScope = Defaults.COMMAND_SCOPE; /** * Command options @@ -181,7 +182,7 @@ public abstract class Command implements ICommandExecutor return this; } - public Builder commandScope(CommandScope commandScope) + public Builder commandScope(ScopeOption.CommandScope commandScope) { this.commandScope = commandScope; return this; @@ -286,7 +287,7 @@ public abstract class Command implements ICommandExecutor return defaultPermission; } - public CommandScope getScope() + public ScopeOption.CommandScope getScope() { return commandScope; } diff --git a/src/main/java/net/pingex/dcf/commands/CommandScope.java b/src/main/java/net/pingex/dcf/commands/CommandScope.java deleted file mode 100644 index 885c776..0000000 --- a/src/main/java/net/pingex/dcf/commands/CommandScope.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.pingex.dcf.commands; - -import sx.blah.discord.handle.obj.IChannel; - -import java.util.function.Predicate; - -/** - * CommandScope allows devs to tell where Commands should run. - * ie. PM, guild chat, etc - */ -public enum CommandScope -{ - /** - * Allows only in a guild chat - */ - GUILD_CHAT(iChannel -> !iChannel.isPrivate()), - - /** - * Only via PM with the bot - */ - PRIVATE_MESSAGE(IChannel::isPrivate), - - /** - * Allows unconditionally - */ - ANYWHERE(iChannel -> true), - - /** - * Denies unconditionally - * Default value - */ - NOWHERE(iChannel -> false); - - private Predicate channel; - - CommandScope(Predicate channel) - { - this.channel = channel; - } - - public boolean test(IChannel iChannel) - { - return channel.test(iChannel); - } -} diff --git a/src/main/java/net/pingex/dcf/commands/InternalCommands.java b/src/main/java/net/pingex/dcf/commands/InternalCommands.java index 36e4563..4afec9e 100644 --- a/src/main/java/net/pingex/dcf/commands/InternalCommands.java +++ b/src/main/java/net/pingex/dcf/commands/InternalCommands.java @@ -1,6 +1,7 @@ package net.pingex.dcf.commands; import net.pingex.dcf.commands.options.ICommandOption; +import net.pingex.dcf.commands.options.ScopeOption; import net.pingex.dcf.core.Configuration; import net.pingex.dcf.permissions.DefaultPermission; import net.pingex.dcf.permissions.PermissionsHandler; @@ -33,7 +34,7 @@ public class InternalCommands implements IWithCommands private static final boolean IS_ENABLED = true; private static final String USAGE = "Page"; private static final DefaultPermission DEFAULT_PERMISSION = DefaultPermission.EVERYONE; - private static final CommandScope COMMAND_SCOPE = CommandScope.ANYWHERE; + private static final ScopeOption.CommandScope COMMAND_SCOPE = ScopeOption.CommandScope.ANYWHERE; private static final Set OPTIONS = Defaults.OPTIONS; /** @@ -116,7 +117,7 @@ public class InternalCommands implements IWithCommands private static final boolean IS_ENABLED = true; private static final String USAGE = "Command"; private static final DefaultPermission DEFAULT_PERMISSION = DefaultPermission.EVERYONE; - private static final CommandScope COMMAND_SCOPE = CommandScope.ANYWHERE; + private static final ScopeOption.CommandScope COMMAND_SCOPE = ScopeOption.CommandScope.ANYWHERE; private static final Set OPTIONS = Defaults.OPTIONS; static final UsageCommand INSTANCE = new UsageCommand(); diff --git a/src/main/java/net/pingex/dcf/commands/options/ScopeOption.java b/src/main/java/net/pingex/dcf/commands/options/ScopeOption.java new file mode 100644 index 0000000..ddb3730 --- /dev/null +++ b/src/main/java/net/pingex/dcf/commands/options/ScopeOption.java @@ -0,0 +1,74 @@ +package net.pingex.dcf.commands.options; + +import sx.blah.discord.handle.obj.IChannel; +import java.util.function.Predicate; + +/** + * This option allows to specify where the command should run. + */ +public class ScopeOption implements ICommandOption +{ + private CommandScope commandScope; + + public ScopeOption(CommandScope commandScope) + { + this.commandScope = commandScope; + } + + public CommandScope getCommandScope() + { + return commandScope; + } + + @Override + public String getOptionName() + { + return "Command scope"; + } + + @Override + public String getOptionDescription() + { + return "This option allows to specify where the command can be run."; + } + + /** + * CommandScope allows devs to tell where Commands should run. + * ie. PM, guild chat, etc + */ + public enum CommandScope + { + /** + * Allows only in a guild chat + */ + GUILD_CHAT(iChannel -> !iChannel.isPrivate()), + + /** + * Only via PM with the bot + */ + PRIVATE_MESSAGE(IChannel::isPrivate), + + /** + * Allows unconditionally + */ + ANYWHERE(iChannel -> true), + + /** + * Denies unconditionally + * Default value + */ + NOWHERE(iChannel -> false); + + private Predicate channel; + + CommandScope(Predicate channel) + { + this.channel = channel; + } + + public boolean test(IChannel iChannel) + { + return channel.test(iChannel); + } + } +}