diff --git a/src/main/java/de/yjulian/merly/subsystem/command/CommandManagerImpl.java b/src/main/java/de/yjulian/merly/subsystem/command/CommandManagerImpl.java index 7f1fbda..a87f778 100644 --- a/src/main/java/de/yjulian/merly/subsystem/command/CommandManagerImpl.java +++ b/src/main/java/de/yjulian/merly/subsystem/command/CommandManagerImpl.java @@ -6,6 +6,7 @@ import de.yjulian.merly.bot.MerlyBot; import de.yjulian.merly.exceptions.CommandException; import de.yjulian.merly.subsystem.command.initial.HelpProviderCommand; +import de.yjulian.merly.subsystem.command.initial.CatPictureCommand; import net.dv8tion.jda.api.entities.*; import org.jetbrains.annotations.Nullable; @@ -77,6 +78,7 @@ private boolean checkType(Command command, CommandType type) { private void registerDefault() { addCommand(new HelpProviderCommand()); + addCommand(new CatPictureCommand()); } public AliasCommand applyAlias(String prefix) { diff --git a/src/main/java/de/yjulian/merly/subsystem/command/initial/CatPictureCommand.java b/src/main/java/de/yjulian/merly/subsystem/command/initial/CatPictureCommand.java new file mode 100644 index 0000000..9d6748e --- /dev/null +++ b/src/main/java/de/yjulian/merly/subsystem/command/initial/CatPictureCommand.java @@ -0,0 +1,36 @@ +package de.yjulian.merly.subsystem.command.initial; + +import de.yjulian.merly.subsystem.command.CommandArguments; +import de.yjulian.merly.subsystem.command.GenericCommand; +import de.yjulian.merly.subsystem.command.Help; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +/** + * Command that sends a random cat picture to the invoking channel. + */ +public class CatPictureCommand implements GenericCommand { + + private static final String API_URL = "https://cataas.com/cat"; + + @Override + public String prefix() { + return "cat"; + } + + @Override + public void onExecute(CommandArguments arguments) { + try (InputStream is = new URL(API_URL).openStream()) { + arguments.getMessageChannel().sendFile(is, "cat.jpg").queue(); + } catch (IOException e) { + arguments.getMessageChannel().sendMessage("Could not load cat image.").queue(); + } + } + + @Override + public Help helpProvider() { + return Help.Builder("Sends a random cat picture.").build(); + } +}