Search in sources :

Example 6 with Command

use of ml.duncte123.skybot.objects.command.Command in project SkyBot by duncte123.

the class HelpCommand method executeCommand.

@SuppressWarnings("NullableProblems")
@Override
public void executeCommand(String invoke, String[] args, GuildMessageReceivedEvent event) {
    if (args.length > 0) {
        String toSearch = StringUtils.join(args, " ").toLowerCase().replaceFirst("(" + Pattern.quote(Settings.PREFIX) + "|" + Pattern.quote(Settings.OTHER_PREFIX) + "|" + Pattern.quote(getSettings(event.getGuild()).getCustomPrefix()) + ")", "");
        for (Command cmd : AirUtils.COMMAND_MANAGER.getCommands()) {
            if (cmd.getName().equals(toSearch)) {
                MessageUtils.sendMsg(event, "Command help for `" + cmd.getName() + "` :\n" + cmd.help(cmd.getName()) + (cmd.getAliases().length > 0 ? "\nAliases: " + StringUtils.join(cmd.getAliases(), ", ") : ""));
                return;
            } else {
                for (String alias : cmd.getAliases()) {
                    if (alias.equals(toSearch)) {
                        MessageUtils.sendMsg(event, "Command help for `" + cmd.getName() + "` :\n" + cmd.help(alias) + (cmd.getAliases().length > 0 ? "\nAliases: " + StringUtils.join(cmd.getAliases(), ", ") : ""));
                        return;
                    }
                }
            }
        }
        MessageUtils.sendMsg(event, "That command could not be found, try " + PREFIX + "help for a list of commands");
        return;
    }
    event.getAuthor().openPrivateChannel().queue(pc -> pc.sendMessage(HelpEmbeds.getCommandListWithPrefix(GuildSettingsUtils.getGuild(event.getGuild()).getCustomPrefix())).queue(msg -> MessageUtils.sendMsg(event, event.getMember().getAsMention() + " check your DM's"), // When sending fails, send to the channel
    err -> MessageUtils.sendMsg(event, (new MessageBuilder()).append("Message could not be delivered to dm's and has been send in this channel.").setEmbed(HelpEmbeds.getCommandListWithPrefix(GuildSettingsUtils.getGuild(event.getGuild()).getCustomPrefix())).build())), err -> MessageUtils.sendMsg(event, "ERROR: " + err.getMessage()));
}
Also used : Settings(ml.duncte123.skybot.Settings) HelpEmbeds(ml.duncte123.skybot.utils.HelpEmbeds) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Command(ml.duncte123.skybot.objects.command.Command) GuildSettingsUtils(ml.duncte123.skybot.utils.GuildSettingsUtils) MessageUtils(ml.duncte123.skybot.utils.MessageUtils) Pattern(java.util.regex.Pattern) StringUtils(org.apache.commons.lang3.StringUtils) AirUtils(ml.duncte123.skybot.utils.AirUtils) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) Command(ml.duncte123.skybot.objects.command.Command)

Example 7 with Command

use of ml.duncte123.skybot.objects.command.Command in project SkyBot by duncte123.

the class SkybotCommandTest method testCommandGetterForName.

@Test
public void testCommandGetterForName() {
    String key = "help";
    HelpCommand value = new HelpCommand();
    assertEquals("Retrieved command does not match stored command for same key (Name)", value, manager.getCommand(key));
}
Also used : HelpCommand(ml.duncte123.skybot.commands.uncategorized.HelpCommand) Test(org.junit.Test)

Example 8 with Command

use of ml.duncte123.skybot.objects.command.Command in project SkyBot by duncte123.

the class SkybotCommandTest method testCommandGetterForAlias.

@Test
public void testCommandGetterForAlias() {
    String key = "evaluate";
    EvalCommand value = new EvalCommand();
    assertEquals("Retrieved command does not match stored command for same key (Alias)", value, manager.getCommand(key));
}
Also used : EvalCommand(ml.duncte123.skybot.commands.essentials.eval.EvalCommand) Test(org.junit.Test)

Aggregations

Command (ml.duncte123.skybot.objects.command.Command)4 Pattern (java.util.regex.Pattern)2 EvalCommand (ml.duncte123.skybot.commands.essentials.eval.EvalCommand)2 GuildSettings (ml.duncte123.skybot.objects.guild.GuildSettings)2 Permission (net.dv8tion.jda.core.Permission)2 TextChannel (net.dv8tion.jda.core.entities.TextChannel)2 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)2 Test (org.junit.Test)2 LavalinkManager (fredboat.audio.player.LavalinkManager)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1 Consumer (java.util.function.Consumer)1