ottobot-v3/src/main/kotlin/nl/voidcorp/ottobot/commands/management/SetPrefixCommand.kt

34 lines
1.3 KiB
Kotlin

package nl.voidcorp.ottobot.commands.management
import nl.voidcorp.ottobot.command.*
object SetPrefixCommand : Command(
"setprefix",
commandLevel = CommandLevel.ADMIN,
group = CommandGroup.ADMIN,
location = CommandSource.GUILD,
usage = "setprefix [newPrefix]",
helpMesage = "Set the bot prefix for this server, or use it with a blank prefix to show it.\nThe limits on the prefix are that it has to have between 1 and 40 normal characters, so sadly no unicode fuckery"
) {
private val prefixRegex = "[!-~]{1,40}".toRegex()
override fun handle(event: CommandMessage): CommandResult {
if (event.params.drop(1).isEmpty()) {
event.reply("This servers prefix is set to `${CommandSettings.getPrefix(event.guild!!)}`")
} else {
val newPrefix = event.params.drop(1).first()
if (!prefixRegex.matches(newPrefix)) {
event.reply("This isn't a valid prefix, sorry...")
} else {
val oldPrefix = CommandSettings.getPrefix(event.guild!!)
CommandSettings.setPrefix(event.guild, newPrefix)
event.reply("The prefix has been changed from `$oldPrefix` to `$newPrefix`!")
}
}
return CommandResult.SUCCESS
}
}