Send DM to user after timeout
This commit is contained in:
parent
8560c3d82e
commit
b4c2275670
|
@ -12,7 +12,8 @@ object ConfigParser {
|
|||
fun initialLoad(rawConfig: RawConfig) {
|
||||
val systemConfig = rawConfig.system?.let(::SystemConfig)
|
||||
?: throw IllegalArgumentException("No [system] block in config.")
|
||||
Config.server = Globals.api.getServerById(systemConfig.serverId).orElseThrow { IllegalArgumentException("Invalid server configured.") }
|
||||
Config.server = Globals.api.getServerById(systemConfig.serverId)
|
||||
.orElseThrow { IllegalArgumentException("Invalid server configured.") }
|
||||
Config.systemConfig = systemConfig
|
||||
reloadLocalization(rawConfig)
|
||||
reloadFeatures(rawConfig)
|
||||
|
@ -42,13 +43,21 @@ class SystemConfig(val serverId: String, val color: Color) {
|
|||
)
|
||||
}
|
||||
|
||||
class Localization(val permissionDenied: String, val redirectedMessage: String, val messageDeleted: String) {
|
||||
class Localization(
|
||||
val permissionDenied: String,
|
||||
val redirectedMessage: String,
|
||||
val messageDeleted: String,
|
||||
val timeout: String
|
||||
) {
|
||||
|
||||
constructor(rawLocalization: RawLocalization) : this(
|
||||
permissionDenied = rawLocalization.permissionDenied
|
||||
?: throw IllegalArgumentException("No [localization.permissionDenied] defined"),
|
||||
redirectedMessage = rawLocalization.redirectedMessage
|
||||
?: throw IllegalArgumentException("No [localization.redirectMessage] defined"),
|
||||
messageDeleted = rawLocalization.messageDeleted
|
||||
?: throw IllegalArgumentException("No [localization.messageDeleted] defined")
|
||||
?: throw IllegalArgumentException("No [localization.messageDeleted] defined"),
|
||||
timeout = rawLocalization.timeout
|
||||
?: throw IllegalArgumentException("No [localization.timeout] defined")
|
||||
)
|
||||
}
|
||||
|
|
|
@ -34,4 +34,9 @@ class RawConfig(
|
|||
}
|
||||
|
||||
class RawSystemConfig(val serverId: String?, val color: String?)
|
||||
class RawLocalization(val permissionDenied: String?, val redirectedMessage: String?, val messageDeleted: String?)
|
||||
class RawLocalization(
|
||||
val permissionDenied: String?,
|
||||
val redirectedMessage: String?,
|
||||
val messageDeleted: String?,
|
||||
val timeout: String?
|
||||
)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package moe.kageru.kagebot.features
|
||||
|
||||
import moe.kageru.kagebot.Log
|
||||
import moe.kageru.kagebot.MessageUtil.sendEmbed
|
||||
import moe.kageru.kagebot.Util.findRole
|
||||
import moe.kageru.kagebot.Util.findUser
|
||||
import moe.kageru.kagebot.Util.ifNotEmpty
|
||||
|
@ -39,6 +40,9 @@ class TimeoutFeature(raw: RawTimeoutFeature) : MessageFeature {
|
|||
user.addRole(timeoutRole)
|
||||
val releaseTime = Instant.now().plus(Duration.ofMinutes(time)).epochSecond
|
||||
Dao.saveTimeout(releaseTime, listOf(user.id) + oldRoles)
|
||||
user.sendEmbed {
|
||||
addField("Timeout", Config.localization.timeout.replace("@@", time.toString()))
|
||||
}
|
||||
Log.info("Removed roles ${oldRoles.joinToString()} from user ${user.discriminatedName}")
|
||||
} ?: message.channel.sendMessage("Could not find user $target. Consider using the user ID.")
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ permissionDenied = "You do not have permission to use this command."
|
|||
# results in <name> says <message>
|
||||
redirectedMessage = "says"
|
||||
messageDeleted = "Your message was deleted because it contained a banned word or phrase."
|
||||
# @@ will be replaced with the time
|
||||
timeout = "You have been timed out for @@ minutes"
|
||||
|
||||
# If this is enable, every new user will receive a welcome message.
|
||||
# If the user has disabled their DMs, the fallbackMessage will be sent in the fallbackChannel instead.
|
||||
|
|
|
@ -15,7 +15,7 @@ class ConfigTest : ShouldSpec({
|
|||
Config.systemConfig shouldNotBe null
|
||||
Config.localization shouldNotBe null
|
||||
Config.features shouldNotBe null
|
||||
Config.commands.size shouldBe 2
|
||||
Config.commands.size shouldBe 3
|
||||
}
|
||||
|
||||
"should parse test config via command" {
|
||||
|
@ -25,6 +25,7 @@ class ConfigTest : ShouldSpec({
|
|||
permissionDenied = "$denied"
|
||||
redirectedMessage = "says"
|
||||
messageDeleted = "dongered"
|
||||
timeout = "timeout"
|
||||
|
||||
[[command]]
|
||||
response = "this command is broken"
|
||||
|
|
|
@ -52,7 +52,7 @@ object TestUtil {
|
|||
every { messageAuthor.isBotUser } returns isBot
|
||||
every { messageAuthor.isYourself } returns isBot
|
||||
every { messageAuthor.isBotOwner } returns false
|
||||
every { messageAuthor.asUser() } returns Optional.of(messageableAuthor())
|
||||
every { messageAuthor.asUser() } returns Optional.of(messageableAuthor(replyEmbeds))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,6 +139,7 @@ class CommandTest : StringSpec({
|
|||
permissionDenied = ""
|
||||
messageDeleted = "whatever"
|
||||
redirectedMessage = "asdja"
|
||||
timeout = "asdasd"
|
||||
""".trimIndent()
|
||||
) {
|
||||
mockMessage.process()
|
||||
|
|
|
@ -6,6 +6,7 @@ color = "#1793d0"
|
|||
permissionDenied = "no permissions"
|
||||
redirectedMessage = "says"
|
||||
messageDeleted = "message dongered"
|
||||
timeout = "timeout"
|
||||
|
||||
[feature.welcome]
|
||||
fallbackChannel = "123"
|
||||
|
|
Loading…
Reference in New Issue
Block a user