Skip to content

Commit

Permalink
add twitch cleanup command
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkyAI committed May 27, 2024
1 parent be9d011 commit f0a708f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
12 changes: 0 additions & 12 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
40 changes: 40 additions & 0 deletions src/main/kotlin/moe/nikky/twitch/TwitchExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
}
}
}
}

Expand Down

0 comments on commit f0a708f

Please sign in to comment.