29 lines
1.0 KiB
Kotlin
29 lines
1.0 KiB
Kotlin
package nl.voidcorp.ottobot.commands.`fun`
|
||
|
||
import nl.voidcorp.ottobot.command.Command
|
||
import nl.voidcorp.ottobot.command.CommandGroup
|
||
import nl.voidcorp.ottobot.command.CommandMessage
|
||
import nl.voidcorp.ottobot.command.CommandResult
|
||
import java.net.URI
|
||
import java.net.URLEncoder
|
||
|
||
object 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
|
||
}
|
||
|
||
} |