forked from QuiltMC/cozy-discord
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change log parsing & add auto archival of threads
As is tradition, completely untested. When will this strategy start backfiring again?
- Loading branch information
Showing
8 changed files
with
177 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/org/quiltmc/community/logs/WrongLocationMessageSender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.quiltmc.community.logs | ||
|
||
import com.kotlindiscord.kord.extensions.checks.channelFor | ||
import com.kotlindiscord.kord.extensions.checks.guildFor | ||
import dev.kord.core.behavior.channel.asChannelOfOrNull | ||
import dev.kord.core.entity.channel.TextChannel | ||
import dev.kord.core.event.Event | ||
import org.quiltmc.community.LOG_PARSING_CONFINEMENT | ||
import org.quiltmc.community.cozy.modules.logs.data.Log | ||
import org.quiltmc.community.cozy.modules.logs.data.Order | ||
import org.quiltmc.community.cozy.modules.logs.types.LogParser | ||
|
||
class WrongLocationMessageSender : LogParser() { | ||
override val identifier: String = "wrong-location-message-sender" | ||
override val order = Order(Int.MAX_VALUE) // be the last parser to run (to destroy the log if necessary) | ||
|
||
override suspend fun predicate(log: Log, event: Event): Boolean { | ||
val channel = channelFor(event)?.asChannelOfOrNull<TextChannel>() ?: return false | ||
val guild = guildFor(event) ?: return false | ||
val allowedChannels = LOG_PARSING_CONFINEMENT[guild.id] ?: return false | ||
if (channel.id in allowedChannels) return false | ||
|
||
channel.createMessage( | ||
"This log was sent in wrong location. No parsing will be done.\n" + | ||
if (allowedChannels.size > 1) { | ||
"Please use one of ${allowedChannels.joinToString(", ") { "<#$it>" }} to parse logs." | ||
} else { | ||
"Please use <#${allowedChannels.single()}> to parse logs." | ||
} | ||
) | ||
return false | ||
} | ||
|
||
override suspend fun process(log: Log) = Unit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters