From f6a85314dc6ec393505735bfd4d8d5f7f30b1915 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 15 Oct 2022 15:58:08 +0100 Subject: [PATCH 1/3] 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"); } -- 2.43.4 From bd15d581950b0ba7566f74a649753c977bf216ee Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Tue, 8 Nov 2022 18:54:23 +0000 Subject: [PATCH 2/3] Fix lobbies not showing up --- src/commands/501231711271780357/Lobby/list.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/501231711271780357/Lobby/list.ts b/src/commands/501231711271780357/Lobby/list.ts index 1b92d55..5dd2779 100644 --- a/src/commands/501231711271780357/Lobby/list.ts +++ b/src/commands/501231711271780357/Lobby/list.ts @@ -21,27 +21,27 @@ export default class ListLobby extends Command { const channels: eLobby[] = []; - interaction.guild.channels.cache.forEach(async (channel) => { + for (let channel of interaction.guild.channels.cache.map(x => x)) { 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 => { + for (let lobby of channels) { embed.addFields([ { name: `<#${lobby.ChannelId}>`, value: `Last Used: ${lobby.LastUsed}` } ]); - }); + } await interaction.reply({ embeds: [ embed ]}); } -- 2.43.4 From ffed976c09ce8d21ad8608287362ef3ecba9f6f4 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Tue, 8 Nov 2022 19:11:27 +0000 Subject: [PATCH 3/3] Fix channel link text --- src/commands/501231711271780357/Lobby/list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/501231711271780357/Lobby/list.ts b/src/commands/501231711271780357/Lobby/list.ts index 5dd2779..ccf0766 100644 --- a/src/commands/501231711271780357/Lobby/list.ts +++ b/src/commands/501231711271780357/Lobby/list.ts @@ -37,7 +37,7 @@ export default class ListLobby extends Command { for (let lobby of channels) { embed.addFields([ { - name: `<#${lobby.ChannelId}>`, + name: `# ${lobby.Name}`, value: `Last Used: ${lobby.LastUsed}` } ]); -- 2.43.4