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) {
|
fun initialLoad(rawConfig: RawConfig) {
|
||||||
val systemConfig = rawConfig.system?.let(::SystemConfig)
|
val systemConfig = rawConfig.system?.let(::SystemConfig)
|
||||||
?: throw IllegalArgumentException("No [system] block in config.")
|
?: 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
|
Config.systemConfig = systemConfig
|
||||||
reloadLocalization(rawConfig)
|
reloadLocalization(rawConfig)
|
||||||
reloadFeatures(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(
|
constructor(rawLocalization: RawLocalization) : this(
|
||||||
permissionDenied = rawLocalization.permissionDenied
|
permissionDenied = rawLocalization.permissionDenied
|
||||||
?: throw IllegalArgumentException("No [localization.permissionDenied] defined"),
|
?: throw IllegalArgumentException("No [localization.permissionDenied] defined"),
|
||||||
redirectedMessage = rawLocalization.redirectedMessage
|
redirectedMessage = rawLocalization.redirectedMessage
|
||||||
?: throw IllegalArgumentException("No [localization.redirectMessage] defined"),
|
?: throw IllegalArgumentException("No [localization.redirectMessage] defined"),
|
||||||
messageDeleted = rawLocalization.messageDeleted
|
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 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
|
package moe.kageru.kagebot.features
|
||||||
|
|
||||||
import moe.kageru.kagebot.Log
|
import moe.kageru.kagebot.Log
|
||||||
|
import moe.kageru.kagebot.MessageUtil.sendEmbed
|
||||||
import moe.kageru.kagebot.Util.findRole
|
import moe.kageru.kagebot.Util.findRole
|
||||||
import moe.kageru.kagebot.Util.findUser
|
import moe.kageru.kagebot.Util.findUser
|
||||||
import moe.kageru.kagebot.Util.ifNotEmpty
|
import moe.kageru.kagebot.Util.ifNotEmpty
|
||||||
|
@ -39,6 +40,9 @@ class TimeoutFeature(raw: RawTimeoutFeature) : MessageFeature {
|
||||||
user.addRole(timeoutRole)
|
user.addRole(timeoutRole)
|
||||||
val releaseTime = Instant.now().plus(Duration.ofMinutes(time)).epochSecond
|
val releaseTime = Instant.now().plus(Duration.ofMinutes(time)).epochSecond
|
||||||
Dao.saveTimeout(releaseTime, listOf(user.id) + oldRoles)
|
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}")
|
Log.info("Removed roles ${oldRoles.joinToString()} from user ${user.discriminatedName}")
|
||||||
} ?: message.channel.sendMessage("Could not find user $target. Consider using the user ID.")
|
} ?: 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>
|
# results in <name> says <message>
|
||||||
redirectedMessage = "says"
|
redirectedMessage = "says"
|
||||||
messageDeleted = "Your message was deleted because it contained a banned word or phrase."
|
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 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.
|
# 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.systemConfig shouldNotBe null
|
||||||
Config.localization shouldNotBe null
|
Config.localization shouldNotBe null
|
||||||
Config.features shouldNotBe null
|
Config.features shouldNotBe null
|
||||||
Config.commands.size shouldBe 2
|
Config.commands.size shouldBe 3
|
||||||
}
|
}
|
||||||
|
|
||||||
"should parse test config via command" {
|
"should parse test config via command" {
|
||||||
|
@ -25,6 +25,7 @@ class ConfigTest : ShouldSpec({
|
||||||
permissionDenied = "$denied"
|
permissionDenied = "$denied"
|
||||||
redirectedMessage = "says"
|
redirectedMessage = "says"
|
||||||
messageDeleted = "dongered"
|
messageDeleted = "dongered"
|
||||||
|
timeout = "timeout"
|
||||||
|
|
||||||
[[command]]
|
[[command]]
|
||||||
response = "this command is broken"
|
response = "this command is broken"
|
||||||
|
|
|
@ -52,7 +52,7 @@ object TestUtil {
|
||||||
every { messageAuthor.isBotUser } returns isBot
|
every { messageAuthor.isBotUser } returns isBot
|
||||||
every { messageAuthor.isYourself } returns isBot
|
every { messageAuthor.isYourself } returns isBot
|
||||||
every { messageAuthor.isBotOwner } returns false
|
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 = ""
|
permissionDenied = ""
|
||||||
messageDeleted = "whatever"
|
messageDeleted = "whatever"
|
||||||
redirectedMessage = "asdja"
|
redirectedMessage = "asdja"
|
||||||
|
timeout = "asdasd"
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
) {
|
) {
|
||||||
mockMessage.process()
|
mockMessage.process()
|
||||||
|
|
|
@ -6,6 +6,7 @@ color = "#1793d0"
|
||||||
permissionDenied = "no permissions"
|
permissionDenied = "no permissions"
|
||||||
redirectedMessage = "says"
|
redirectedMessage = "says"
|
||||||
messageDeleted = "message dongered"
|
messageDeleted = "message dongered"
|
||||||
|
timeout = "timeout"
|
||||||
|
|
||||||
[feature.welcome]
|
[feature.welcome]
|
||||||
fallbackChannel = "123"
|
fallbackChannel = "123"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user