WIP: Start of series command
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Ethan Lane 2024-03-21 18:50:56 +00:00
parent dead9545ba
commit 1e7b221276
3 changed files with 91 additions and 2 deletions

87
src/commands/series.ts Normal file
View file

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

View file

@ -8,6 +8,7 @@ import Gdrivesync from "./commands/gdrivesync";
import Give from "./commands/give"; import Give from "./commands/give";
import Inventory from "./commands/inventory"; import Inventory from "./commands/inventory";
import Resync from "./commands/resync"; import Resync from "./commands/resync";
import Series from "./commands/series";
import Trade from "./commands/trade"; import Trade from "./commands/trade";
import View from "./commands/view"; import View from "./commands/view";
@ -30,6 +31,7 @@ export default class Registry {
CoreClient.RegisterCommand("give", new Give()); CoreClient.RegisterCommand("give", new Give());
CoreClient.RegisterCommand("inventory", new Inventory()); CoreClient.RegisterCommand("inventory", new Inventory());
CoreClient.RegisterCommand("resync", new Resync()); CoreClient.RegisterCommand("resync", new Resync());
CoreClient.RegisterCommand("series", new Series());
CoreClient.RegisterCommand("trade", new Trade()); CoreClient.RegisterCommand("trade", new Trade());
CoreClient.RegisterCommand("view", new View()); CoreClient.RegisterCommand("view", new View());

View file

@ -1,7 +1,7 @@
import { CommandInteraction, SlashCommandBuilder } from "discord.js"; import { CommandInteraction } from "discord.js";
export abstract class Command { export abstract class Command {
public CommandBuilder: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">; public CommandBuilder: any;
abstract execute(interaction: CommandInteraction): Promise<void>; abstract execute(interaction: CommandInteraction): Promise<void>;
} }