Skip to content

Commit

Permalink
Command process system optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
ileukocyte committed Sep 11, 2022
1 parent 2f74ddb commit 235a6d9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ class ProcessesCommand : SlashOnlyCommand {

channel.sendMessage {
embeds += defaultEmbed(description, EmbedType.WARNING) {
text = "This message will self-delete in 5 seconds"
text = "This message will self-delete in 10 seconds"
}

process.users.mapNotNull { event.jda.getUserById(it)?.asMention }.joinToString()
.takeUnless { it.isEmpty() }
?.let { content += it }
}.queue({ it.delete().queueAfter(5, TimeUnit.SECONDS, null) {} }) {}
}.queue({ it.delete().queueAfter(10, TimeUnit.SECONDS, null) {} }) {}
}
}
else -> {
Expand Down Expand Up @@ -284,13 +284,13 @@ class ProcessesCommand : SlashOnlyCommand {

channel.sendMessage {
embeds += defaultEmbed(description, EmbedType.WARNING) {
text = "This message will self-delete in 5 seconds"
text = "This message will self-delete in 10 seconds"
}

process.users.mapNotNull { event.jda.getUserById(it)?.asMention }.joinToString()
.takeUnless { it.isEmpty() }
?.let { content += it }
}.queue({ it.delete().queueAfter(5, TimeUnit.SECONDS, null) {} }) {}
}.queue({ it.delete().queueAfter(10, TimeUnit.SECONDS, null) {} }) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ class SessionsCommand : SlashOnlyCommand {

channel.sendMessage {
embeds += defaultEmbed(description, WARNING) {
text = "This message will self-delete in 5 seconds"
text = "This message will self-delete in 10 seconds"
}

session.users.mapNotNull { event.jda.getUserById(it)?.asMention }.joinToString()
.takeUnless { it.isEmpty() }
?.let { content += it }
}.queue({ it.delete().queueAfter(5, TimeUnit.SECONDS, null) {} }) {}
}.queue({ it.delete().queueAfter(10, TimeUnit.SECONDS, null) {} }) {}
}
}
else -> {
Expand Down Expand Up @@ -294,13 +294,13 @@ class SessionsCommand : SlashOnlyCommand {

channel.sendMessage {
embeds += defaultEmbed(description, WARNING) {
text = "This message will self-delete in 5 seconds"
text = "This message will self-delete in 10 seconds"
}

session.users.mapNotNull { event.jda.getUserById(it)?.asMention }.joinToString()
.takeUnless { it.isEmpty() }
?.let { content += it }
}.queue({ it.delete().queueAfter(5, TimeUnit.SECONDS, null) {} }) {}
}.queue({ it.delete().queueAfter(10, TimeUnit.SECONDS, null) {} }) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ object EventHandler : ListenerAdapter() {
event.jda.getChannelById(GuildMessageChannel::class.java, process.channel)
?.sendMessage {
embeds += defaultEmbed(description, EmbedType.WARNING) {
text = "This message will self-delete in 5 seconds"
text = "This message will self-delete in 10 seconds"
}

process.users.mapNotNull { event.jda.getUserById(it)?.asMention }.joinToString()
.takeUnless { it.isEmpty() }
?.let { content += it }
}?.queue({ it.delete().queueAfter(5, TimeUnit.SECONDS, null) {} }) {}
}?.queue({ it.delete().queueAfter(10, TimeUnit.SECONDS, null) {} }) {}
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/io/ileukocyte/hibernum/utils/waiter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import arrow.fx.coroutines.onCancel

import io.ileukocyte.hibernum.commands.GenericCommand
import io.ileukocyte.hibernum.extensions.toSetSortedBy
import java.util.concurrent.ConcurrentHashMap

import java.util.concurrent.Executors.newFixedThreadPool
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -133,7 +134,7 @@ data class WaiterProcess internal constructor(

companion object {
@[JvmField PublishedApi]
internal val CURRENTLY_RUNNING = mutableMapOf<WaiterProcess, AwaitableEventListener<*>>()
internal val CURRENTLY_RUNNING = ConcurrentHashMap<WaiterProcess, AwaitableEventListener<*>>()
}
}

Expand All @@ -144,7 +145,7 @@ class AwaitableEventListener<E : GenericEvent>(
private val condition: suspend (E) -> Boolean,
) : EventListener {
init {
waiterProcess?.let { WaiterProcess.CURRENTLY_RUNNING += it to this }
waiterProcess?.let { WaiterProcess.CURRENTLY_RUNNING[it] = this }
}

fun kill(jda: JDA, completeWithNull: Boolean = false) {
Expand Down

0 comments on commit 235a6d9

Please sign in to comment.