New ScopeOption class for options framework.
Also moved the scope enum to ScopeOption class. Refactored every occurence of the scope enum in the project for transitionning purpose.keep-around/3c354c0f00ae6e9d0b7ccd747b995217fbd6c147
parent
f4fe2c5a6a
commit
ee2c6cb38c
@ -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<IChannel> channel;
|
|
||||||
|
|
||||||
CommandScope(Predicate<IChannel> channel)
|
|
||||||
{
|
|
||||||
this.channel = channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean test(IChannel iChannel)
|
|
||||||
{
|
|
||||||
return channel.test(iChannel);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<IChannel> channel;
|
||||||
|
|
||||||
|
CommandScope(Predicate<IChannel> channel)
|
||||||
|
{
|
||||||
|
this.channel = channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean test(IChannel iChannel)
|
||||||
|
{
|
||||||
|
return channel.test(iChannel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue