From 690b63470a3d99cd98b0fd8824c390ef0b83d401 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Wed, 3 Jul 2024 20:50:47 +0100 Subject: [PATCH] Create lobby command --- .../1719856023429-CreateMoon/Up/01-Moon.sql | 2 +- src/commands/304276391837302787/moons/list.ts | 19 ++++++++++++++++++- src/database/entities/Moon.ts | 6 +++++- src/registry.ts | 7 +++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/database/3.3.0/1719856023429-CreateMoon/Up/01-Moon.sql b/database/3.3.0/1719856023429-CreateMoon/Up/01-Moon.sql index 38ef6b2..a2afcbf 100644 --- a/database/3.3.0/1719856023429-CreateMoon/Up/01-Moon.sql +++ b/database/3.3.0/1719856023429-CreateMoon/Up/01-Moon.sql @@ -2,7 +2,7 @@ CREATE TABLE `moon` ( `Id` varchar(255) NOT NULL, `WhenCreated` datetime NOT NULL, `WhenUpdated` datetime NOT NULL, - `ServerId` varchar(255) NOT NULL, + `MoonNumber` int NOT NULL, `UserId` varchar(255) NOT NULL, `Description` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; diff --git a/src/commands/304276391837302787/moons/list.ts b/src/commands/304276391837302787/moons/list.ts index 023fa89..d862d5c 100644 --- a/src/commands/304276391837302787/moons/list.ts +++ b/src/commands/304276391837302787/moons/list.ts @@ -1,5 +1,22 @@ -import {CommandInteraction} from "discord.js"; +import {CommandInteraction, EmbedBuilder} from "discord.js"; +import Moon from "../../../database/entities/Moon"; +import EmbedColours from "../../../constants/EmbedColours"; export default async function ListMoons(interaction: CommandInteraction) { + const moons = await Moon.FetchMoonsByUserId(interaction.user.id); + if (!moons || moons.length == 0) { + await interaction.reply("You do not have any moons."); + return; + } + + const description = moons.flatMap(x => `${x.MoonNumber}. ${x.Description.slice(0, 15)}`); + + const embed = new EmbedBuilder() + .setTitle(`${interaction.user.username}'s Moons`) + .setColor(EmbedColours.Ok) + .setDescription(description.join("\n")) + .setFooter({ text: `${moons.length} moons` }); + + await interaction.reply({ embeds: [ embed ] }); } diff --git a/src/database/entities/Moon.ts b/src/database/entities/Moon.ts index cedf96f..feb2cbb 100644 --- a/src/database/entities/Moon.ts +++ b/src/database/entities/Moon.ts @@ -4,12 +4,16 @@ import AppDataSource from "../dataSources/appDataSource"; @Entity() export default class Moon extends BaseEntity { - constructor(description: string, userId: string) { + constructor(moonNumber: number, description: string, userId: string) { super(); + this.MoonNumber = moonNumber; this.Description = description; this.UserId = userId; } + + @Column() + MoonNumber: number; @Column() Description: string; diff --git a/src/registry.ts b/src/registry.ts index 68428de..703bb9f 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -30,6 +30,9 @@ import AddLobby from "./commands/501231711271780357/Lobby/add"; import RemoveLobby from "./commands/501231711271780357/Lobby/remove"; import ListLobby from "./commands/501231711271780357/Lobby/list"; +// Command Imports: Potato Talk +import Moons from "./commands/304276391837302787/moons"; + // Event Imports import GuildMemberAdd from "./events/MemberEvents/GuildMemberAdd"; import GuildMemberRemove from "./events/MemberEvents/GuildMemberRemove"; @@ -72,12 +75,16 @@ export default class Registry { CoreClient.RegisterCommand("listlobby", new ListLobby(), "501231711271780357"); CoreClient.RegisterCommand("entry", new Entry(), "501231711271780357"); + // Exclusive Commands: Potato Talk + CoreClient.RegisterCommand("moons", new Moons(), "304276391837302787"); + // 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"); + CoreClient.RegisterCommand("moons", new Moons(), "442730357897429002"); } public static RegisterEvents() {