Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading