diff --git a/src/main/kotlin/de/bigboot/ggtools/fang/CommandContext.kt b/src/main/kotlin/de/bigboot/ggtools/fang/CommandContext.kt index 1854b03..5fcbe0a 100644 --- a/src/main/kotlin/de/bigboot/ggtools/fang/CommandContext.kt +++ b/src/main/kotlin/de/bigboot/ggtools/fang/CommandContext.kt @@ -2,6 +2,7 @@ package de.bigboot.ggtools.fang import discord4j.core.`object`.entity.Guild import discord4j.core.`object`.entity.Message +import discord4j.core.`object`.entity.User import discord4j.core.`object`.entity.channel.MessageChannel import kotlinx.coroutines.reactive.awaitSingle import org.koin.core.component.KoinComponent @@ -16,6 +17,7 @@ data class CommandContext( suspend fun channel(): MessageChannel = message.channel.awaitSingle() suspend fun guild(): Guild = message.guild.awaitSingle() + suspend fun author(): User = message.authorAsMember.awaitSingle() class Arguments(private val arguments: Map) { operator fun get(key: String) = arguments.getValue(key) diff --git a/src/main/kotlin/de/bigboot/ggtools/fang/commands/Root.kt b/src/main/kotlin/de/bigboot/ggtools/fang/commands/Root.kt index 6a11311..e2567bb 100644 --- a/src/main/kotlin/de/bigboot/ggtools/fang/commands/Root.kt +++ b/src/main/kotlin/de/bigboot/ggtools/fang/commands/Root.kt @@ -5,6 +5,7 @@ import de.bigboot.ggtools.fang.CommandGroupSpec import de.bigboot.ggtools.fang.commands.admin.Admin import de.bigboot.ggtools.fang.commands.queue.Queue import de.bigboot.ggtools.fang.commands.server.Server +import de.bigboot.ggtools.fang.commands.match.Match import de.bigboot.ggtools.fang.utils.createEmbedCompat import de.bigboot.ggtools.fang.utils.formatCommandHelp import de.bigboot.ggtools.fang.utils.formatCommandTree @@ -15,6 +16,7 @@ class Root : CommandGroupSpec("", "") { group(Admin()) group(Queue()) group(Server()) + group(Match()) command("help", "show this help") { onCall { diff --git a/src/main/kotlin/de/bigboot/ggtools/fang/commands/match/Match.kt b/src/main/kotlin/de/bigboot/ggtools/fang/commands/match/Match.kt new file mode 100644 index 0000000..a718664 --- /dev/null +++ b/src/main/kotlin/de/bigboot/ggtools/fang/commands/match/Match.kt @@ -0,0 +1,36 @@ +package de.bigboot.ggtools.fang.commands.match + +import de.bigboot.ggtools.fang.CommandGroupBuilder +import de.bigboot.ggtools.fang.CommandGroupSpec +import de.bigboot.ggtools.fang.Config +import de.bigboot.ggtools.fang.service.MatchService +import de.bigboot.ggtools.fang.service.QueueMessageService +import de.bigboot.ggtools.fang.utils.* +import discord4j.common.util.Snowflake +import kotlinx.coroutines.reactive.awaitSingle +import org.koin.core.component.inject + +class Match : CommandGroupSpec("match", "Commands for matches") { + private val matchService by inject() + private val queueMessageService by inject() + + override val build: CommandGroupBuilder.() -> Unit = { + command("swap", "shows the swap commands for the server") { + onCall { + val currentServer = queueMessageService.findUser(author().id.asLong()); + + channel().createMessageCompat { + addEmbedCompat { + if (currentServer != null && currentServer.openUrl != null) { + title("Swap commands") + description("Leiren: `open ${currentServer.openUrl}?team=0`\nGrenn: `open ${currentServer.openUrl}?team=1`") + } + else { + description("You are not in a game with a server up") + } + } + }.awaitSingle() + } + } + } +} diff --git a/src/main/kotlin/de/bigboot/ggtools/fang/service/QueueMessageService.kt b/src/main/kotlin/de/bigboot/ggtools/fang/service/QueueMessageService.kt index 592c55c..0401110 100644 --- a/src/main/kotlin/de/bigboot/ggtools/fang/service/QueueMessageService.kt +++ b/src/main/kotlin/de/bigboot/ggtools/fang/service/QueueMessageService.kt @@ -397,6 +397,15 @@ class QueueMessageService : AutostartService, KoinComponent { )) } + fun findUser(user: Long): MatchRequest? { + matchReuests.forEach { (_, request) -> + if (request.pop.allPlayers.contains(user)) { + return request; + } + } + return null; + } + private suspend fun handleInteraction(event: ComponentInteractionEvent, button: ButtonJoin) { event.deferEdit().awaitSafe() matchService.join(button.queue, event.interaction.user.id.asLong())