From b3455e0b8dc831e2b5973284ce11dffb9e50f0f2 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sun, 2 Jul 2017 01:58:24 +0200 Subject: [PATCH] added tengwar command. View TengwarCommand.java for more info --- pom.xml | 15 +++-- src/main/java/handiebot/command/Commands.java | 2 + .../command/commands/misc/TengwarCommand.java | 57 +++++++++++++++++++ .../command/commands/misc/package-info.java | 5 ++ src/main/resources/Strings.properties | 2 + src/main/resources/Strings_nl.properties | 1 + 6 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 src/main/java/handiebot/command/commands/misc/TengwarCommand.java create mode 100644 src/main/java/handiebot/command/commands/misc/package-info.java diff --git a/pom.xml b/pom.xml index d92b279..aa9be7f 100644 --- a/pom.xml +++ b/pom.xml @@ -46,27 +46,32 @@ jar - - jcenter - http://jcenter.bintray.com - jitpack.io https://jitpack.io + + jcenter + http://jcenter.bintray.com + com.github.austinv11 Discord4J - 2.8.3 + 2.8.4 com.sedmelluq lavaplayer 1.2.39 + + com.github.andrewlalis + TengwarTranslatorLibrary + 1.1 + \ No newline at end of file diff --git a/src/main/java/handiebot/command/Commands.java b/src/main/java/handiebot/command/Commands.java index a50ea8a..19fa53f 100644 --- a/src/main/java/handiebot/command/Commands.java +++ b/src/main/java/handiebot/command/Commands.java @@ -2,6 +2,7 @@ package handiebot.command; import handiebot.command.commands.admin.QuitCommand; import handiebot.command.commands.admin.SetPrefixCommand; +import handiebot.command.commands.misc.TengwarCommand; import handiebot.command.commands.music.*; import handiebot.command.commands.support.HelpCommand; import handiebot.command.commands.support.InfoCommand; @@ -39,6 +40,7 @@ public class Commands { commands.add(new InfoCommand()); commands.add(new SetPrefixCommand()); commands.add(new QuitCommand()); + commands.add(new TengwarCommand()); } /** diff --git a/src/main/java/handiebot/command/commands/misc/TengwarCommand.java b/src/main/java/handiebot/command/commands/misc/TengwarCommand.java new file mode 100644 index 0000000..1983057 --- /dev/null +++ b/src/main/java/handiebot/command/commands/misc/TengwarCommand.java @@ -0,0 +1,57 @@ +package handiebot.command.commands.misc; + +import handiebot.command.CommandContext; +import handiebot.command.types.ContextCommand; +import net.agspace.TengwarImageGenerator; +import net.agspace.Translator; + +import java.io.FileNotFoundException; + +import static handiebot.HandieBot.resourceBundle; + +/** + * @author Andrew Lalis + */ +public class TengwarCommand extends ContextCommand { + + public TengwarCommand() { + super("tengwar", + " ", + resourceBundle.getString("commands.command.tengwar.description"), + 0); + } + + @Override + public void execute(CommandContext context) { + if (context.getArgs().length == 0){ + context.getChannel().sendMessage(this.getUsage(context.getGuild())); + } else if (context.getArgs().length >= 2){ + String input = readTextFromArgs(context.getArgs()); + if (context.getArgs()[0].equalsIgnoreCase("translateTo")){ + String result = Translator.translateToTengwar(input); + try { + context.getChannel().sendFile(TengwarImageGenerator.generateImage(result, + 500, + 24f, + false, + false, + System.getProperty("user.home")+"/.handiebot/tengwarTemp.png")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } else if (context.getArgs()[0].equalsIgnoreCase("translateFrom")){ + context.getChannel().sendMessage(Translator.translateToEnglish(input)); + } + } else { + context.getChannel().sendMessage(this.getUsage(context.getGuild())); + } + } + + private String readTextFromArgs(String[] args){ + StringBuilder sb = new StringBuilder(); + for (int i = 1; i < args.length; i++){ + sb.append(args[i]).append(' '); + } + return sb.toString().trim(); + } +} diff --git a/src/main/java/handiebot/command/commands/misc/package-info.java b/src/main/java/handiebot/command/commands/misc/package-info.java new file mode 100644 index 0000000..802c10a --- /dev/null +++ b/src/main/java/handiebot/command/commands/misc/package-info.java @@ -0,0 +1,5 @@ +/** + * @author Andrew Lalis + * Contains miscellaneous commands that do not belong in a group. + */ +package handiebot.command.commands.misc; \ No newline at end of file diff --git a/src/main/resources/Strings.properties b/src/main/resources/Strings.properties index d77710d..e8a6b01 100644 --- a/src/main/resources/Strings.properties +++ b/src/main/resources/Strings.properties @@ -90,6 +90,8 @@ commands.command.shuffle.description=Sets shuffling. commands.command.skip.description=Skips the current song. #Stop commands.command.stop.description=Stops playing music. +#Tengwar translator +commands.command.tengwar.description=Translates text to tengwar, or decodes tengwar text back into human readable form. #Music Player player.setRepeat=Set repeat to {0} player.setShuffle=Set shuffle to {0} diff --git a/src/main/resources/Strings_nl.properties b/src/main/resources/Strings_nl.properties index b26e43d..9e56840 100644 --- a/src/main/resources/Strings_nl.properties +++ b/src/main/resources/Strings_nl.properties @@ -99,4 +99,5 @@ trackSchedule.trackStarted=Started audio track: {0} trackSchedule.nowPlaying=Now playing: **{0}** {1}\ {2} player.playQueueEmpty=There's nothing in the queue to play. +commands.command.tengwar.description=Translates text to tengwar, or decodes tengwar text back into human readable form.