diff --git a/common/src/main/kotlin/dev/erdragh/astralbot/commands/Commands.kt b/common/src/main/kotlin/dev/erdragh/astralbot/commands/Commands.kt index ec59b94..8cc3077 100644 --- a/common/src/main/kotlin/dev/erdragh/astralbot/commands/Commands.kt +++ b/common/src/main/kotlin/dev/erdragh/astralbot/commands/Commands.kt @@ -1,6 +1,8 @@ package dev.erdragh.astralbot.commands import dev.erdragh.astralbot.handlers.FAQHandler +import dev.erdragh.astralbot.handlers.MinecraftHandler +import dev.erdragh.astralbot.minecraftHandler import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent import net.dv8tion.jda.api.interactions.commands.OptionType @@ -12,7 +14,8 @@ val commands = arrayOf( FAQCommand, LinkCommand, UnlinkCommand, - LinkCheckCommand + LinkCheckCommand, + ListCommand ) interface HandledSlashCommand { @@ -62,3 +65,19 @@ object FAQCommand : HandledSlashCommand, AutocompleteCommand { } } } + +object ListCommand : HandledSlashCommand { + override val command: SlashCommandData = Commands.slash("list", "Lists currently online players") + + override fun handle(event: SlashCommandInteractionEvent) { + event.deferReply(false).queue() + + val list = minecraftHandler?.getOnlinePlayers()?.map { "- ${it.name}\n" } + + if (!list.isNullOrEmpty()) { + event.hook.sendMessage("The following players are currently online:\n${list.joinToString()}").queue() + } else { + event.hook.sendMessage("There are no players online currently").queue() + } + } +} \ No newline at end of file