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()));
}
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));
}
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));
}
Aggregations