27 lines
1.0 KiB
Kotlin
27 lines
1.0 KiB
Kotlin
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
|
||
}
|
||
|
||
} |