Only break from command match loop after successfully executing a command
This means you can have multiple commands with the same or overlappings triggers, and the bot will execute the first the user has access to.
This commit is contained in:
parent
e3219c7800
commit
f871d2a381
|
@ -27,8 +27,9 @@ object Kagebot {
|
||||||
}
|
}
|
||||||
for (command in Config.commands) {
|
for (command in Config.commands) {
|
||||||
if (command.matches(readableMessageContent)) {
|
if (command.matches(readableMessageContent)) {
|
||||||
command.execute(this)
|
if (command.execute(this)) {
|
||||||
break
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,13 +39,13 @@ class Command(cmd: RawCommand) {
|
||||||
|
|
||||||
fun isAllowed(message: MessageCreateEvent) = permissions?.isAllowed(message) ?: true
|
fun isAllowed(message: MessageCreateEvent) = permissions?.isAllowed(message) ?: true
|
||||||
|
|
||||||
fun execute(message: MessageCreateEvent) {
|
fun execute(message: MessageCreateEvent): Boolean {
|
||||||
if (permissions?.isAllowed(message) == false) {
|
if (permissions?.isAllowed(message) == false) {
|
||||||
if (Config.localization.permissionDenied.isNotBlank()) {
|
if (Config.localization.permissionDenied.isNotBlank()) {
|
||||||
message.channel.sendMessage(Config.localization.permissionDenied)
|
message.channel.sendMessage(Config.localization.permissionDenied)
|
||||||
}
|
}
|
||||||
Log.info("Denying command ${this.trigger} to user ${message.messageAuthor.discriminatedName} (ID: ${message.messageAuthor.id})")
|
Log.info("Denying command ${this.trigger} to user ${message.messageAuthor.discriminatedName} (ID: ${message.messageAuthor.id})")
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
Log.info("Executing command ${this.trigger} triggered by user ${message.messageAuthor.discriminatedName} (ID: ${message.messageAuthor.id})")
|
Log.info("Executing command ${this.trigger} triggered by user ${message.messageAuthor.discriminatedName} (ID: ${message.messageAuthor.id})")
|
||||||
Globals.commandCounter.incrementAndGet()
|
Globals.commandCounter.incrementAndGet()
|
||||||
|
@ -57,6 +57,7 @@ class Command(cmd: RawCommand) {
|
||||||
MessageUtil.sendEmbed(message.channel, embed)
|
MessageUtil.sendEmbed(message.channel, embed)
|
||||||
}
|
}
|
||||||
this.feature?.handle(message)
|
this.feature?.handle(message)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun matches(msg: String) = this.matchType.matches(msg, this)
|
fun matches(msg: String) = this.matchType.matches(msg, this)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user