me.jakejmattson.kutils.internal.utils.Responder.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of KUtils Show documentation
Show all versions of KUtils Show documentation
A Discord bot framework for Kotlin.
@file:Suppress("unused")
package me.jakejmattson.kutils.internal.utils
import kotlinx.coroutines.*
import me.jakejmattson.kutils.api.dsl.embed.*
import me.jakejmattson.kutils.api.extensions.stdlib.sanitiseMentions
import net.dv8tion.jda.api.entities.*
internal interface Responder {
val channel: MessageChannel
fun respond(message: String) = unsafeRespond(message.sanitiseMentions())
fun respond(embed: MessageEmbed) = channel.sendMessage(embed).queue()
fun respond(construct: EmbedDSLHandle.() -> Unit) = respond(embed(construct))
fun respond(message: String, construct: EmbedDSLHandle.() -> Unit) = channel.sendMessage(message).embed(embed(construct)).queue()
fun respondTimed(message: String, millis: Long = 5000) {
require(millis >= 0) { "RespondTimed: Delay cannot be negative." }
channel.sendMessage(message.sanitiseMentions()).queue {
GlobalScope.launch {
delay(millis)
it.delete().queue()
}
}
}
fun respondTimed(embed: MessageEmbed, millis: Long = 5000) {
require(millis >= 0) { "RespondTimed: Delay cannot be negative." }
channel.sendMessage(embed).queue {
GlobalScope.launch {
delay(millis)
it.delete().queue()
}
}
}
fun unsafeRespond(message: String) {
require(message.isNotEmpty()) { "Cannot send an empty message." }
message.chunked(2000).forEach { channel.sendMessage(it).queue() }
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy