From e8d1a978a2f0e4fbd34117ae0baf77c99dc61a21 Mon Sep 17 00:00:00 2001 From: Julius de Jeu Date: Sun, 9 Jun 2019 19:29:26 +0200 Subject: [PATCH] Add dog and cat command, aka the most important ones --- .../discord/commands/fun/CatCommand.kt | 19 +++++++++++++++++++ .../discord/commands/fun/DogCommand.kt | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/main/kotlin/nl/voidcorp/discord/commands/fun/CatCommand.kt create mode 100644 src/main/kotlin/nl/voidcorp/discord/commands/fun/DogCommand.kt diff --git a/src/main/kotlin/nl/voidcorp/discord/commands/fun/CatCommand.kt b/src/main/kotlin/nl/voidcorp/discord/commands/fun/CatCommand.kt new file mode 100644 index 0000000..b5262bd --- /dev/null +++ b/src/main/kotlin/nl/voidcorp/discord/commands/fun/CatCommand.kt @@ -0,0 +1,19 @@ +package nl.voidcorp.discord.commands.`fun` + +import nl.voidcorp.discord.command.Command +import nl.voidcorp.discord.command.CommandGroup +import nl.voidcorp.discord.command.CommandMessage +import nl.voidcorp.discord.command.CommandResult +import org.springframework.stereotype.Service +import java.net.URI + +@Service +class CatCommand : Command("cat", group = CommandGroup.FUN, allowAnywhere = true) { + var isgif = true + override fun handle(event: CommandMessage): CommandResult { + val url = URI("https://cataas.com/cat" + if (isgif) "/gif" else "").toURL().openStream() + event.message.channel.sendFile(url, if (isgif) "cat.gif" else "cat.png").content("i is cat").queue() + isgif = !isgif + return CommandResult.SUCCESS + } +} \ No newline at end of file diff --git a/src/main/kotlin/nl/voidcorp/discord/commands/fun/DogCommand.kt b/src/main/kotlin/nl/voidcorp/discord/commands/fun/DogCommand.kt new file mode 100644 index 0000000..db95f6b --- /dev/null +++ b/src/main/kotlin/nl/voidcorp/discord/commands/fun/DogCommand.kt @@ -0,0 +1,18 @@ +package nl.voidcorp.discord.commands.`fun` + +import nl.voidcorp.discord.command.Command +import nl.voidcorp.discord.command.CommandGroup +import nl.voidcorp.discord.command.CommandMessage +import nl.voidcorp.discord.command.CommandResult +import org.springframework.stereotype.Service +import java.net.URI + +@Service +class DogCommand : Command("dog", group = CommandGroup.FUN, allowAnywhere = true) { + override fun handle(event: CommandMessage): CommandResult { + val image = URI.create("https://random.dog/woof").toURL().readText() + val url = URI("https://random.dog/$image").toURL().openStream() + event.message.channel.sendFile(url, image).content("i is dog").queue() + return CommandResult.SUCCESS + } +} \ No newline at end of file