feat: added CleanUpExtension

This commit is contained in:
moonleay 2023-10-15 15:17:53 +02:00
parent 63e1d5b283
commit 39802598b2

View file

@ -0,0 +1,39 @@
package net.moonleay.rssbot.extensions
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand
import com.kotlindiscord.kord.extensions.types.respond
import kotlinx.coroutines.flow.filter
import net.moonleay.rssbot.Bot
import net.moonleay.rssbot.data.database.repository.SubscriptionRepository
import net.moonleay.rssbot.util.EmbedColor
import net.moonleay.rssbot.util.MessageUtil
class CleanUpExtension : Extension() {
override val name = "cleanup"
override val allowApplicationCommandInDMs: Boolean
get() = false
override suspend fun setup() {
ephemeralSlashCommand() {
name = "cleanup"
description = "Clean all messages from this bot in this channel"
this.action {
val user = this.user.asUser()
this.channel.messages.filter { it.author?.id == Bot.bot.kordRef.selfId }.collect { it.delete() }
this.respond {
this.embeds.add(
MessageUtil.getEmbed(
EmbedColor.INFO,
"Cleaned up",
"Cleaned up all messages from this bot in this channel",
user.username
)
)
}
}
}
}
}