From f6a85314dc6ec393505735bfd4d8d5f7f30b1915 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 15 Oct 2022 15:58:08 +0100 Subject: [PATCH] Add list lobby command --- src/commands/501231711271780357/Lobby/list.ts | 48 +++++++++++++++++++ src/registry.ts | 3 ++ 2 files changed, 51 insertions(+) create mode 100644 src/commands/501231711271780357/Lobby/list.ts diff --git a/src/commands/501231711271780357/Lobby/list.ts b/src/commands/501231711271780357/Lobby/list.ts new file mode 100644 index 0000000..1b92d55 --- /dev/null +++ b/src/commands/501231711271780357/Lobby/list.ts @@ -0,0 +1,48 @@ +import { CacheType, CommandInteraction, EmbedBuilder, GuildBasedChannel, PermissionsBitField, SlashCommandBuilder } from "discord.js"; +import { Command } from "../../../type/command"; +import { default as eLobby } from "../../../entity/501231711271780357/Lobby"; +import EmbedColours from "../../../constants/EmbedColours"; + +export default class ListLobby extends Command { + constructor() { + super(); + + super.CommandBuilder = new SlashCommandBuilder() + .setName('listlobby') + .setDescription('Lists all channels set up as lobbies') + .setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers); + } + + public override async execute(interaction: CommandInteraction) { + if (!interaction.guild) { + await interaction.reply('Guild not found.'); + return; + } + + const channels: eLobby[] = []; + + interaction.guild.channels.cache.forEach(async (channel) => { + const lobby = await eLobby.FetchOneByChannelId(channel.id); + + if (lobby) { + channels.push(lobby); + } + }); + + const embed = new EmbedBuilder() + .setColor(EmbedColours.Ok) + .setTitle("Lobbies") + .setDescription(`Channels: ${channels.length}`); + + channels.forEach(lobby => { + embed.addFields([ + { + name: `<#${lobby.ChannelId}>`, + value: `Last Used: ${lobby.LastUsed}` + } + ]); + }); + + await interaction.reply({ embeds: [ embed ]}); + } +} \ No newline at end of file diff --git a/src/registry.ts b/src/registry.ts index f9a3278..a86ce96 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -25,6 +25,7 @@ import Entry from "./commands/501231711271780357/entry"; import Lobby from "./commands/501231711271780357/Lobby/lobby"; import AddLobby from "./commands/501231711271780357/Lobby/add"; import RemoveLobby from "./commands/501231711271780357/Lobby/remove"; +import ListLobby from "./commands/501231711271780357/Lobby/list"; // Event Imports import GuildMemberAdd from "./events/MemberEvents/GuildMemberAdd"; @@ -59,12 +60,14 @@ export default class Registry { CoreClient.RegisterCommand("lobby", new Lobby(), "501231711271780357"); CoreClient.RegisterCommand("lobbyAdd", new AddLobby(), "501231711271780357"); CoreClient.RegisterCommand("lobbyRemove", new RemoveLobby(), "501231711271780357"); + CoreClient.RegisterCommand("listlobby", new ListLobby(), "501231711271780357"); CoreClient.RegisterCommand("entry", new Entry(), "501231711271780357"); // Add Exclusive Commands to Test Server CoreClient.RegisterCommand("lobby", new Lobby(), "442730357897429002"); CoreClient.RegisterCommand("addlobby", new AddLobby(), "442730357897429002"); CoreClient.RegisterCommand("removelobby", new RemoveLobby(), "442730357897429002"); + CoreClient.RegisterCommand("listlobby", new ListLobby(), "442730357897429002"); CoreClient.RegisterCommand("entry", new Entry(), "442730357897429002"); }