From 1e7b22127680bb1b7733e62afd81bf4d0267dea2 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 21 Mar 2024 18:50:56 +0000 Subject: [PATCH] WIP: Start of series command --- src/commands/series.ts | 87 ++++++++++++++++++++++++++++++++++++++++++ src/registry.ts | 2 + src/type/command.ts | 4 +- 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 src/commands/series.ts diff --git a/src/commands/series.ts b/src/commands/series.ts new file mode 100644 index 0000000..ede9186 --- /dev/null +++ b/src/commands/series.ts @@ -0,0 +1,87 @@ +import { CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js"; +import { Command } from "../type/command"; +import { CoreClient } from "../client/client"; +import EmbedColours from "../constants/EmbedColours"; +import AppLogger from "../client/appLogger"; + +export default class Series extends Command { + constructor() { + super(); + + this.CommandBuilder = new SlashCommandBuilder() + .setName("view") + .setDescription("View details on a series") + .addSubcommand(x => + x + .setName("view") + .setDescription("View a specifiic series by id") + .addStringOption(y => + y + .setName("id") + .setDescription("The series id") + .setRequired(true))) + .addSubcommand(x => + x + .setName("list") + .setDescription("List all series")); + } + + public override async execute(interaction: CommandInteraction) { + if (!interaction.isChatInputCommand()) return; + + switch (interaction.options.getSubcommand()) { + case "view": + await this.ViewSeries(interaction); + break; + case "list": + await this.ListSeries(interaction); + break; + default: + AppLogger.LogWarn("Commands/Series", `Subcommand doesn't exist: ${interaction.options.getSubcommand()}`); + await interaction.reply("Subcommand doesn't exist."); + } + } + + private async ViewSeries(interaction: CommandInteraction) { + const id = interaction.options.get("id"); + + AppLogger.LogSilly("Commands/Series/View", `Parameters: id=${id?.value}`); + + if (!id) return; + + const series = CoreClient.Cards.find(x => x.id == id.value); + + if (!series) { + AppLogger.LogVerbose("Commands/Series/View", "Series not found."); + + await interaction.reply("Series not found."); + return; + } + + const description = series.cards + .map(x => { return `[${x.id}] ${x.name}` }) + .join("\n"); + + const embed = new EmbedBuilder() + .setTitle(series.name) + .setColor(EmbedColours.Ok) + .setDescription(description) + .setFooter({ text: `${series.id} ยท ${series.cards.length} cards` }); + + await interaction.reply({ embeds: [ embed ]}); + } + + private async ListSeries(interaction: CommandInteraction) { + const description = CoreClient.Cards + .map(x => { return `[${x.id}] ${x.name}` }) + .join("\n"); + + const embed = new EmbedBuilder() + .setTitle("Series") + .setColor(EmbedColours.Ok) + .setDescription(description) + .setFooter({ text: `${CoreClient.Cards.length} series` }); + + await interaction.reply({ embeds: [ embed ]}); + } +} \ No newline at end of file diff --git a/src/registry.ts b/src/registry.ts index 1087cda..05c5714 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -8,6 +8,7 @@ import Gdrivesync from "./commands/gdrivesync"; import Give from "./commands/give"; import Inventory from "./commands/inventory"; import Resync from "./commands/resync"; +import Series from "./commands/series"; import Trade from "./commands/trade"; import View from "./commands/view"; @@ -30,6 +31,7 @@ export default class Registry { CoreClient.RegisterCommand("give", new Give()); CoreClient.RegisterCommand("inventory", new Inventory()); CoreClient.RegisterCommand("resync", new Resync()); + CoreClient.RegisterCommand("series", new Series()); CoreClient.RegisterCommand("trade", new Trade()); CoreClient.RegisterCommand("view", new View()); diff --git a/src/type/command.ts b/src/type/command.ts index 20f5e3a..409a4ca 100644 --- a/src/type/command.ts +++ b/src/type/command.ts @@ -1,7 +1,7 @@ -import { CommandInteraction, SlashCommandBuilder } from "discord.js"; +import { CommandInteraction } from "discord.js"; export abstract class Command { - public CommandBuilder: Omit; + public CommandBuilder: any; abstract execute(interaction: CommandInteraction): Promise; }