use of commands.model.Command in project KaellyBot by Kaysoro.
the class CommandPatternTest method testTwitterCommand.
public void testTwitterCommand() {
Command cmd = new TwitterCommand();
Pattern pattern = Pattern.compile("^" + Constants.prefixCommand + cmd.getName() + cmd.getPattern() + "$");
assertTrue(pattern.matcher(Constants.prefixCommand + "twitter true").find());
assertTrue(pattern.matcher(Constants.prefixCommand + "twitter on").find());
assertTrue(pattern.matcher(Constants.prefixCommand + "twitter 0").find());
assertTrue(pattern.matcher(Constants.prefixCommand + "twitter false").find());
assertTrue(pattern.matcher(Constants.prefixCommand + "twitter off").find());
assertTrue(pattern.matcher(Constants.prefixCommand + "twitter 1").find());
assertFalse(pattern.matcher(Constants.prefixCommand + "twitter").find());
}
use of commands.model.Command in project KaellyBot by Kaysoro.
the class CommandPatternTest method testRandomCommand.
public void testRandomCommand() {
Command cmd = new RandomCommand();
Pattern pattern = Pattern.compile("^" + Constants.prefixCommand + cmd.getName() + cmd.getPattern() + "$");
assertTrue(pattern.matcher(Constants.prefixCommand + "rdm").find());
assertTrue(pattern.matcher(Constants.prefixCommand + "rdm 200").find());
assertTrue(pattern.matcher(Constants.prefixCommand + "rdm un deûx trôis").find());
assertFalse(pattern.matcher(Constants.prefixCommand + "rdm ").find());
}
use of commands.model.Command in project KaellyBot by Kaysoro.
the class CommandPatternTest method testItemCommand.
public void testItemCommand() {
Command cmd = new ItemCommand();
Pattern pattern = Pattern.compile("^" + Constants.prefixCommand + cmd.getName() + cmd.getPattern() + "$");
assertTrue(pattern.matcher(Constants.prefixCommand + "item test").find());
assertTrue(pattern.matcher(Constants.prefixCommand + "item tést test").find());
assertTrue(pattern.matcher(Constants.prefixCommand + "item -more tést test").find());
assertFalse(pattern.matcher(Constants.prefixCommand + "item").find());
}
use of commands.model.Command in project KaellyBot by Kaysoro.
the class CommandPatternTest method testSoundCommand.
public void testSoundCommand() {
Command cmd = new SoundCommand();
Pattern pattern = Pattern.compile("^" + Constants.prefixCommand + cmd.getName() + cmd.getPattern() + "$");
assertTrue(pattern.matcher(Constants.prefixCommand + "sound").find());
assertTrue(pattern.matcher(Constants.prefixCommand + "sound dofus").find());
}
use of commands.model.Command in project KaellyBot by Kaysoro.
the class HelpCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
String prefixe = getPrefixMdEscaped(message);
Language lg = Translator.getLanguageFrom(message.getChannel());
Matcher m = getMatcher(message);
m.find();
StringBuilder st = new StringBuilder();
boolean argumentFound = m.group(1) != null && m.group(1).replaceAll("^\\s+", "").length() > 0;
for (Command command : CommandManager.getCommands()) if (command.isPublic() && !command.isAdmin() && (message.getChannel().isPrivate() || !command.isForbidden(Guild.getGuild(message.getGuild())))) {
if (!argumentFound)
st.append(command.help(lg, prefixe)).append("\n");
else if (command.getName().equals(m.group(1).trim())) {
st.append(command.helpDetailed(lg, prefixe));
break;
}
}
if (argumentFound && st.length() == 0)
notFoundCmd.throwException(message, this, lg);
else
Message.sendText(message.getChannel(), st.toString());
}
return false;
}
Aggregations