Skip to content

Commit

Permalink
AsyncCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
devoxin committed Oct 15, 2018
1 parent a2084ec commit 8894da6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
buildscript {
ext.kotlin_stdlib = '1.2.71'
ext.kotlin_coroutines = '0.30.2'

repositories {
jcenter()
mavenCentral()
Expand All @@ -14,7 +17,7 @@ apply plugin: 'kotlin'
apply plugin: 'com.github.johnrengelman.shadow'

group 'me.devoxin'
version '1.0.0'
version '0.0.2'
sourceCompatibility = 1.8

repositories {
Expand All @@ -23,9 +26,11 @@ repositories {
}

dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_stdlib"
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines"
compile "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$kotlin_coroutines"
compile 'com.google.guava:guava:26.0-jre'
compileOnly 'net.dv8tion:JDA:3.8.0_436'
compileOnly 'net.dv8tion:JDA:3.8.1_438'
api 'org.slf4j:slf4j-api:1.7.25'
}

Expand Down
21 changes: 21 additions & 0 deletions src/main/kotlin/me/devoxin/flight/AsyncCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.devoxin.flight

import kotlinx.coroutines.experimental.GlobalScope
import kotlinx.coroutines.experimental.async

abstract class AsyncCommand : Command {

abstract suspend fun executeAsync(ctx: Context, args: Map<String, Any?>)

final override fun execute(ctx: Context, args: Map<String, Any?>) {
GlobalScope.async {
try {
executeAsync(ctx, args)
} catch (e: Throwable) {
val commandError = CommandError(e, this@AsyncCommand)
ctx.commandClient.eventListeners.forEach { it.onCommandError(ctx, commandError) }
}
}
}

}
2 changes: 1 addition & 1 deletion src/main/kotlin/me/devoxin/flight/CommandClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CommandClient(
private val prefixProvider: PrefixProvider,
private val useDefaultHelpCommand: Boolean,
private val ignoreBots: Boolean,
private val eventListeners: List<CommandClientAdapter>
val eventListeners: List<CommandClientAdapter>
) : ListenerAdapter() {

private val logger = LoggerFactory.getLogger(this.javaClass)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/me/devoxin/flight/FlightInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package me.devoxin.flight

object FlightInfo {

public val VERSION = "1.0.6"
public val VERSION = "0.0.2"

}

0 comments on commit 8894da6

Please sign in to comment.