Properly await future before checking their return code
This commit is contained in:
parent
7ebafc9958
commit
62bdb582de
|
@ -26,7 +26,7 @@ class Kagebot {
|
|||
Globals.config.features.welcome!!.let { welcome ->
|
||||
val message = event.user.sendMessage(welcome.embed)
|
||||
// If the user disabled direct messages, try the fallback (if defined)
|
||||
if (message.isCompletedExceptionally
|
||||
if (!Util.wasSuccessful(message)
|
||||
&& welcome.fallbackChannel != null
|
||||
&& welcome.fallbackMessage != null
|
||||
) {
|
||||
|
|
|
@ -6,6 +6,8 @@ import org.javacord.api.entity.channel.TextChannel
|
|||
import org.javacord.api.entity.message.MessageAuthor
|
||||
import org.javacord.api.entity.permission.Role
|
||||
import java.util.*
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.CompletionException
|
||||
|
||||
object Util {
|
||||
inline fun <T> T.doIf(condition: (T) -> Boolean, op: (T) -> T): T {
|
||||
|
@ -47,6 +49,15 @@ object Util {
|
|||
}
|
||||
}
|
||||
|
||||
fun <T> wasSuccessful(future: CompletableFuture<T>): Boolean {
|
||||
try {
|
||||
future.join()
|
||||
} catch (e: CompletionException) {
|
||||
// we don’t care about this error, but I don’t want to spam stdout
|
||||
}
|
||||
return !future.isCompletedExceptionally
|
||||
}
|
||||
|
||||
@Throws(IllegalArgumentException::class)
|
||||
fun findChannel(idOrName: String): TextChannel {
|
||||
return when {
|
||||
|
|
|
@ -62,7 +62,7 @@ class Redirect(rawRedirect: RawRedirect) {
|
|||
}
|
||||
}
|
||||
|
||||
if (target.sendMessage(embed).isCompletedExceptionally) {
|
||||
if (Util.wasSuccessful(target.sendMessage(embed))) {
|
||||
log.warning("Could not redirect message to channel $target")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ messageDeleted = "Your message was deleted because it contained a banned word or
|
|||
# If no fallback channel or message is specified, no fallback will be sent.
|
||||
[feature.welcome]
|
||||
enabled = true
|
||||
fallbackChannel = 555097559023222825
|
||||
fallbackChannel = "555097559023222825"
|
||||
fallbackMessage = "@@ I would like to greet you, but I can’t. :("
|
||||
# This is a list of pairs where the key is the title and the value the content of the paragraph.
|
||||
# Do not use empty strings to get empty headings or paragraphs. The discord API rejects those.
|
||||
|
|
Loading…
Reference in New Issue
Block a user