Skip to content

Commit

Permalink
Add /list command
Browse files Browse the repository at this point in the history
  • Loading branch information
Erdragh committed Dec 2, 2023
1 parent facb694 commit d589ddc
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,7 +14,8 @@ val commands = arrayOf(
FAQCommand,
LinkCommand,
UnlinkCommand,
LinkCheckCommand
LinkCheckCommand,
ListCommand
)

interface HandledSlashCommand {
Expand Down Expand Up @@ -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()
}
}
}

0 comments on commit d589ddc

Please sign in to comment.