Search in sources :

Example 6 with Command

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());
}
Also used : Pattern(java.util.regex.Pattern) Command(commands.model.Command)

Example 7 with Command

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());
}
Also used : Pattern(java.util.regex.Pattern) Command(commands.model.Command)

Example 8 with Command

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());
}
Also used : Pattern(java.util.regex.Pattern) Command(commands.model.Command)

Example 9 with Command

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());
}
Also used : Pattern(java.util.regex.Pattern) Command(commands.model.Command)

Example 10 with Command

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;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) AbstractCommand(commands.model.AbstractCommand) Command(commands.model.Command)

Aggregations

Command (commands.model.Command)32 Pattern (java.util.regex.Pattern)28 AbstractCommand (commands.model.AbstractCommand)4 Language (enums.Language)4 Matcher (java.util.regex.Matcher)4 ArrayList (java.util.ArrayList)2 AboutCommand (commands.classic.AboutCommand)1 CommandForbidden (data.CommandForbidden)1 Guild (data.Guild)1