ottobotv2/src/main/kotlin/nl/voidcorp/discord/commands/fun/WeatherCommand.kt

27 lines
1.0 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
import java.net.URLEncoder
@Service
class WeatherCommand : Command("weather", aliases = listOf("rain"), group = CommandGroup.FUN) {
override fun handle(event: CommandMessage): CommandResult {
val location =
if (event.params.drop(1).isEmpty()) {
"delft"
} else {
event.params.drop(1).joinToString(" ").replace("<@501009066479452170>", "woerden")
}
val url = URI("http://wttr.in/${URLEncoder.encode(location, "utf-8")}_Fpm.png").toURL().openStream()
event.message.channel.sendFile(url, "$location.png").content("Weather in ${location.replace("+", " ").replace("@here", "@hеre").replace("@everyone", "@еveryone") }").queue()
return CommandResult.SUCCESS
}
}