Maybe fix channel errors when someone sends a non command message starting with the prefix in a non bot channel
This commit is contained in:
parent
32a2782b16
commit
709e1a5226
|
@ -11,7 +11,6 @@ import nl.voidcorp.discord.command.CommandSettings
|
||||||
import nl.voidcorp.discord.creator
|
import nl.voidcorp.discord.creator
|
||||||
import nl.voidcorp.discord.logger
|
import nl.voidcorp.discord.logger
|
||||||
import nl.voidcorp.discord.storage.GuildRepo
|
import nl.voidcorp.discord.storage.GuildRepo
|
||||||
import nl.voidcorp.discord.storage.GuildStore
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@ -38,46 +37,53 @@ class CommandListener(
|
||||||
|
|
||||||
|
|
||||||
if (!event.message.contentRaw.startsWith(prefix) or (event.message.contentRaw.length == prefix.length)) return
|
if (!event.message.contentRaw.startsWith(prefix) or (event.message.contentRaw.length == prefix.length)) return
|
||||||
|
val isGuild = event.isFromGuild
|
||||||
val res = commands.map { it to it.onCommand(event, prefix) }.filter { it.second != CommandResult.NOPE }
|
val res = commands.map { it to it.onCommand(event, prefix) }.filter { it.second != CommandResult.NOPE }
|
||||||
if (res.size > 1) {
|
when {
|
||||||
val mb =
|
res.size > 1 -> {
|
||||||
MessageBuilder("Well this is awkward... It seems that multiple actions are bound to this command... ")
|
val mb =
|
||||||
.append("Report this error to the staff of the server or ")
|
MessageBuilder("Well this is awkward... It seems that multiple actions are bound to this command... ")
|
||||||
val member = event.guild.getMemberById(creator)
|
.append("Report this error to the staff of the server or ")
|
||||||
if (member != null)
|
val member = event.guild.getMemberById(creator)
|
||||||
mb.append(member)
|
if (member != null)
|
||||||
else {
|
mb.append(member)
|
||||||
mb.append("J00LZ#9386")
|
else {
|
||||||
}
|
mb.append("J00LZ#9386")
|
||||||
|
}
|
||||||
|
|
||||||
|
event.channel.sendMessage(mb.append(" since this shouldn't happen...").build()).queue()
|
||||||
|
|
||||||
event.channel.sendMessage(mb.append(" since this shouldn't happen...").build()).queue()
|
|
||||||
} else if (res.isEmpty()) {
|
|
||||||
event.channel.sendMessage("I don't seem to know this command...").queue()
|
|
||||||
} else {
|
|
||||||
val (command, result) = res[0]
|
|
||||||
when (result) {
|
|
||||||
CommandResult.SUCCESS -> Unit
|
|
||||||
CommandResult.ERROR -> CommandMessage(
|
|
||||||
event,
|
|
||||||
emptyList()
|
|
||||||
).reply(MessageBuilder("There was an error executing this command").build())
|
|
||||||
CommandResult.PERMISSIONS -> CommandMessage(event, emptyList()).reply(
|
|
||||||
"Sorry, but you don't seem to have the needed permissions to execute this command..."
|
|
||||||
)
|
|
||||||
CommandResult.NOPE -> logger.warn("The command ${command.name} somehow responded with a nope?")
|
|
||||||
CommandResult.PARAMETERS -> CommandMessage(event, emptyList()).reply(
|
|
||||||
"Sorry, but you are missing some parameters: `${command.usage}`"
|
|
||||||
)
|
|
||||||
CommandResult.CHANNEL -> CommandMessage(event, emptyList()).reply(
|
|
||||||
"It seems this is not a channel where bots are allowed for you..."
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
res.isNotEmpty() -> {
|
||||||
|
val (command, result) = res[0]
|
||||||
|
when (result) {
|
||||||
|
CommandResult.CHANNEL -> CommandMessage(event, emptyList()).reply(
|
||||||
|
"It seems this is not a channel where bots are allowed for you..."
|
||||||
|
)
|
||||||
|
CommandResult.PERMISSIONS -> CommandMessage(event, emptyList()).reply(
|
||||||
|
"Sorry, but you don't seem to have the needed permissions to execute this command..."
|
||||||
|
)
|
||||||
|
CommandResult.SUCCESS -> Unit
|
||||||
|
CommandResult.ERROR -> CommandMessage(
|
||||||
|
event,
|
||||||
|
emptyList()
|
||||||
|
).reply(MessageBuilder("There was an error executing this command").build())
|
||||||
|
|
||||||
|
CommandResult.NOPE -> logger.warn("The command ${command.name} somehow responded with a nope?")
|
||||||
|
CommandResult.PARAMETERS -> CommandMessage(event, emptyList()).reply(
|
||||||
|
"Sorry, but you are missing some parameters: `${command.usage}`"
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
isGuild -> Unit
|
||||||
|
else -> event.channel.sendMessage("I don't seem to know this command...").queue()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// override fun onMessageUpdate(event: MessageUpdateEvent) =
|
// override fun onMessageUpdate(event: MessageUpdateEvent) =
|
||||||
// onMessageReceived(MessageReceivedEvent(event.jda, event.messageIdLong, event.message))
|
// onMessageReceived(MessageReceivedEvent(event.jda, event.messageIdLong, event.message))
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue