Add list lobby command

This commit is contained in:
Ethan Lane 2022-10-15 15:58:08 +01:00
parent 0d63bd120d
commit f6a85314dc
2 changed files with 51 additions and 0 deletions

View file

@ -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<CacheType>) {
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 ]});
}
}

View file

@ -25,6 +25,7 @@ import Entry from "./commands/501231711271780357/entry";
import Lobby from "./commands/501231711271780357/Lobby/lobby"; import Lobby from "./commands/501231711271780357/Lobby/lobby";
import AddLobby from "./commands/501231711271780357/Lobby/add"; import AddLobby from "./commands/501231711271780357/Lobby/add";
import RemoveLobby from "./commands/501231711271780357/Lobby/remove"; import RemoveLobby from "./commands/501231711271780357/Lobby/remove";
import ListLobby from "./commands/501231711271780357/Lobby/list";
// Event Imports // Event Imports
import GuildMemberAdd from "./events/MemberEvents/GuildMemberAdd"; import GuildMemberAdd from "./events/MemberEvents/GuildMemberAdd";
@ -59,12 +60,14 @@ export default class Registry {
CoreClient.RegisterCommand("lobby", new Lobby(), "501231711271780357"); CoreClient.RegisterCommand("lobby", new Lobby(), "501231711271780357");
CoreClient.RegisterCommand("lobbyAdd", new AddLobby(), "501231711271780357"); CoreClient.RegisterCommand("lobbyAdd", new AddLobby(), "501231711271780357");
CoreClient.RegisterCommand("lobbyRemove", new RemoveLobby(), "501231711271780357"); CoreClient.RegisterCommand("lobbyRemove", new RemoveLobby(), "501231711271780357");
CoreClient.RegisterCommand("listlobby", new ListLobby(), "501231711271780357");
CoreClient.RegisterCommand("entry", new Entry(), "501231711271780357"); CoreClient.RegisterCommand("entry", new Entry(), "501231711271780357");
// Add Exclusive Commands to Test Server // Add Exclusive Commands to Test Server
CoreClient.RegisterCommand("lobby", new Lobby(), "442730357897429002"); CoreClient.RegisterCommand("lobby", new Lobby(), "442730357897429002");
CoreClient.RegisterCommand("addlobby", new AddLobby(), "442730357897429002"); CoreClient.RegisterCommand("addlobby", new AddLobby(), "442730357897429002");
CoreClient.RegisterCommand("removelobby", new RemoveLobby(), "442730357897429002"); CoreClient.RegisterCommand("removelobby", new RemoveLobby(), "442730357897429002");
CoreClient.RegisterCommand("listlobby", new ListLobby(), "442730357897429002");
CoreClient.RegisterCommand("entry", new Entry(), "442730357897429002"); CoreClient.RegisterCommand("entry", new Entry(), "442730357897429002");
} }