diff --git a/settings.gradle.kts b/settings.gradle.kts index 7e685d4..a2c3ae5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -25,17 +25,5 @@ develocity { } } } -// https://dev.to/jmfayard/the-one-gradle-trick-that-supersedes-all-the-others-5bpg -//gradleEnterprise { -// buildScan { -// // uncomment this to scan every gradle task -//// publishAlways() -// termsOfServiceUrl = "https://gradle.com/terms-of-service" -// termsOfServiceAgree = "yes" -// buildScanPublished { -// file("buildscan.log").appendText("${java.util.Date()} - $buildScanUri\n") -// } -// } -//} rootProject.name = "twitch-announcement-discordbot" \ No newline at end of file diff --git a/src/main/kotlin/moe/nikky/twitch/TwitchExtension.kt b/src/main/kotlin/moe/nikky/twitch/TwitchExtension.kt index e94caff..43905a5 100644 --- a/src/main/kotlin/moe/nikky/twitch/TwitchExtension.kt +++ b/src/main/kotlin/moe/nikky/twitch/TwitchExtension.kt @@ -659,6 +659,46 @@ class TwitchExtension() : Extension(), Klogging { } } } + ephemeralSubCommand() { + name = "cleanup" + description = "deletes old messages sent by the bot" + requireBotPermissions( +// Permission.ManageMessages, + ) + check { + with(configurationExtension) { requiresBotControl() } + } + action { + withLogContext(event, guild) { guild -> + val channel = event.interaction.channel.asChannel() + val before = Clock.System.now() - 7.days + + val twitchGuildConfig = guild.config().get() ?: TwitchGuildConfig() + + val isInConfig = twitchGuildConfig.configs.entries.any { + it.value.channelId == channel.id + } + + if(!isInConfig) relayError("current channel is not found in the twitch config") + + val messagesToDelete = channel.messages + .filter { + it.author?.id == this@TwitchExtension.kord.selfId + } + .filter { + val timestamp = it.editedTimestamp ?: it.timestamp + timestamp < before + } + .toList() + .sortedByDescending { it.timestamp } + + messagesToDelete.forEach { + channel.deleteMessage(it.id) + } + + } + } + } } }