@@ -2,6 +2,10 @@ package org.yttr.koncorda
22
33import com.typesafe.config.Config
44import com.typesafe.config.ConfigFactory
5+ import kotlinx.coroutines.CoroutineScope
6+ import kotlinx.coroutines.Dispatchers
7+ import kotlinx.coroutines.SupervisorJob
8+ import kotlinx.coroutines.launch
59import net.dv8tion.jda.api.JDABuilder
610import net.dv8tion.jda.api.events.message.MessageReceivedEvent
711import net.dv8tion.jda.api.hooks.ListenerAdapter
@@ -15,6 +19,9 @@ class Koncorda : ListenerAdapter() {
1519 private val discordToken = conf.getString(" koncorda.discord-token" )
1620 private val baseCommands = mutableListOf<Command .Branch >()
1721
22+ private val job = SupervisorJob ()
23+ private val scope = CoroutineScope (Dispatchers .Default + job)
24+
1825 /* *
1926 * Explicitly listed gateways intents, defaults to JDA defaults
2027 */
@@ -36,17 +43,20 @@ class Koncorda : ListenerAdapter() {
3643 // ignore improper messages
3744 if (event.isIgnorable) return
3845
39- // split the args
40- val args = event.message.contentStripped.trim().split(" " )
46+ scope.launch {
47+ // split the args
48+ val args = event.message.contentStripped.trim().split(" " )
4149
42- // find the command handler, if it exists
43- when (val baseCommand = allBaseCommands()[args.first()]) {
44- is Command .Leaf -> baseCommand
45- is Command .Branch -> baseCommand[args.drop(1 )]
46- else -> null
47- }?.let {
48- if (it.check(event)) it(event, args) else {
49- event.channel.sendMessage(" You are not allowed to use that command." ).queue()
50+ // find the command handler, if it exists
51+ when (val baseCommand = allBaseCommands()[args.first()]) {
52+ is Command .Leaf -> baseCommand
53+ is Command .Branch -> baseCommand[args.drop(1 )]
54+ else -> null
55+ }?.let {
56+ val call = it.createCall(event, args)
57+ if (it.check(call)) it.handle(call) else {
58+ event.channel.sendMessage(" You are not allowed to use that command." ).queue()
59+ }
5060 }
5161 }
5262 }
0 commit comments