feat: added FeedsExtension

This commit is contained in:
moonleay 2023-10-15 13:23:03 +02:00
parent 3654649f98
commit b8b878a54b

View file

@ -0,0 +1,40 @@
package net.moonleay.rssbot.extensions
import com.kotlindiscord.kord.extensions.commands.Arguments
import com.kotlindiscord.kord.extensions.commands.converters.impl.string
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand
import com.kotlindiscord.kord.extensions.types.respond
import net.moonleay.rssbot.data.database.repository.RSSRepository
import net.moonleay.rssbot.data.database.repository.SubscriptionRepository
import net.moonleay.rssbot.util.EmbedColor
import net.moonleay.rssbot.util.MessageUtil
class FeedsExtension : Extension() {
override val name = "feeds"
override val allowApplicationCommandInDMs: Boolean
get() = false
override suspend fun setup() {
ephemeralSlashCommand() {
name = "feeds"
description = "Show all active feeds for this channel"
this.action {
val user = this.user.asUser()
val subscriptions = SubscriptionRepository.getAllChannel(this.channel.id.value.toLong())
this.respond {
this.embeds.add(
MessageUtil.getEmbed(
EmbedColor.INFO,
"Feeds",
subscriptions.joinToString("\n") { it.feedName + " [[feed url](" + it.feedUrl + ")]" },
user.username
)
)
}
}
}
}
}