feat!: improved MessageUtil

Signed-off-by: moonleay <contact@moonleay.net>
This commit is contained in:
moonleay 2023-12-19 10:28:49 +01:00
parent b2c43e2c04
commit fc7edc0d0d
Signed by: moonleay
GPG key ID: 82667543CCD715FB

View file

@ -18,10 +18,7 @@
package net.moonleay.lilJudd.util package net.moonleay.lilJudd.util
import com.kotlindiscord.kord.extensions.commands.Arguments import dev.kord.core.behavior.UserBehavior
import com.kotlindiscord.kord.extensions.commands.application.slash.PublicSlashCommandContext
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.types.respond
import dev.kord.core.entity.Embed import dev.kord.core.entity.Embed
import dev.kord.rest.builder.message.EmbedBuilder import dev.kord.rest.builder.message.EmbedBuilder
import java.time.LocalDateTime import java.time.LocalDateTime
@ -30,44 +27,9 @@ import java.time.format.DateTimeFormatter
object MessageUtil { object MessageUtil {
private val dtf: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy @ HH:mm:ss") private val dtf: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy @ HH:mm:ss")
///Send an embedded message as a reply suspend fun getFooter(u: UserBehavior? = null): String {
suspend fun sendEmbedForPublicSlashCommand( val now: LocalDateTime = LocalDateTime.now()
ctx: PublicSlashCommandContext<Arguments, ModalForm>, return ">" + dtf.format(now) + " - ${u?.asUser()?.username ?: "Automated Message"}"
color: EmbedColor,
title: String,
description: String
) {
ctx.respond {
embeds.add(
getEmbed(
color,
title,
description,
ctx.user.asUser().username + "#" + ctx.user.asUser().discriminator
)
)
}
}
///Send an embedded message with an image as a reply
suspend fun sendEmbedForPublicSlashCommandWithImage(
ctx: PublicSlashCommandContext<Arguments, ModalForm>,
color: EmbedColor,
title: String,
description: String,
thumbnailUrl: String
) {
ctx.respond {
embeds.add(
getEmbedWithImage(
color,
title,
description,
ctx.user.asUser().username + "#" + ctx.user.asUser().discriminator,
thumbnailUrl
)
)
}
} }
///Get a cloned embedded message ///Get a cloned embedded message
@ -101,20 +63,6 @@ object MessageUtil {
return ebb return ebb
} }
fun getEmbedWithTableWithFooter(
color: EmbedColor,
title: String,
description: String,
values: Map<String, List<String>>?,
footer: String
): EmbedBuilder {
val ebb = getEmbedWithTable(color, title, description, values)
ebb.footer = EmbedBuilder.Footer()
ebb.footer!!.text = ">m.id/$footer"
return ebb
}
///Get an embedded msg with image, title and description
fun getEmbedWithTable( fun getEmbedWithTable(
color: EmbedColor, color: EmbedColor,
title: String, title: String,
@ -136,7 +84,6 @@ object MessageUtil {
return ebb return ebb
} }
///Get an embedded msg with title and description ///Get an embedded msg with title and description
fun getEmbedSmall( fun getEmbedSmall(
color: EmbedColor, color: EmbedColor,
@ -164,17 +111,4 @@ object MessageUtil {
return ebb return ebb
} }
///Get an embedded msg with image, title, description and a src
fun getEmbedWithImage(
color: EmbedColor,
title: String,
description: String,
source: String,
thumbnailUrl: String
): EmbedBuilder {
val ebb = getEmbed(color, title, description, source)
ebb.thumbnail = EmbedBuilder.Thumbnail()
ebb.thumbnail!!.url = thumbnailUrl
return ebb
}
} }