From 1be9ba23a3e12715f17d64049fa5d076ca9894cd Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 23 Nov 2024 17:20:47 +0000 Subject: [PATCH 1/2] Create base effects command --- src/commands/effects.ts | 15 +++++++++++++++ src/commands/effects/list.ts | 0 src/registry.ts | 2 ++ 3 files changed, 17 insertions(+) create mode 100644 src/commands/effects.ts create mode 100644 src/commands/effects/list.ts diff --git a/src/commands/effects.ts b/src/commands/effects.ts new file mode 100644 index 0000000..d52b3ce --- /dev/null +++ b/src/commands/effects.ts @@ -0,0 +1,15 @@ +import {CommandInteraction, SlashCommandBuilder} from "discord.js"; +import {Command} from "../type/command"; + +export default class Effects extends Command { + constructor() { + super(); + + this.CommandBuilder = new SlashCommandBuilder() + .setName("effects") + .setDescription("Effects"); + } + + public override async execute(interaction: CommandInteraction) { + } +} diff --git a/src/commands/effects/list.ts b/src/commands/effects/list.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/registry.ts b/src/registry.ts index e4e5d64..3be1fb8 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -7,6 +7,7 @@ import AllBalance from "./commands/allbalance"; import Balance from "./commands/balance"; import Daily from "./commands/daily"; import Drop from "./commands/drop"; +import Effects from "./commands/effects"; import Gdrivesync from "./commands/gdrivesync"; import Give from "./commands/give"; import Id from "./commands/id"; @@ -44,6 +45,7 @@ export default class Registry { CoreClient.RegisterCommand("balance", new Balance()); CoreClient.RegisterCommand("daily", new Daily()); CoreClient.RegisterCommand("drop", new Drop()); + CoreClient.RegisterCommand("effects", new Effects()); CoreClient.RegisterCommand("gdrivesync", new Gdrivesync()); CoreClient.RegisterCommand("give", new Give()); CoreClient.RegisterCommand("id", new Id()); From 9fce79579baee90688064c0375c83f2ccf41519f Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 23 Nov 2024 17:40:29 +0000 Subject: [PATCH 2/2] WIP: Start creating user effects builder --- src/commands/effects.ts | 5 ++++- src/commands/effects/list.ts | 0 src/database/entities/app/UserEffect.ts | 15 +++++++++++++++ src/helpers/EffectHelper.ts | 19 +++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) delete mode 100644 src/commands/effects/list.ts diff --git a/src/commands/effects.ts b/src/commands/effects.ts index d52b3ce..0b014df 100644 --- a/src/commands/effects.ts +++ b/src/commands/effects.ts @@ -7,7 +7,10 @@ export default class Effects extends Command { this.CommandBuilder = new SlashCommandBuilder() .setName("effects") - .setDescription("Effects"); + .setDescription("Effects") + .addSubcommand(x => x + .setName("list") + .setDescription("List all effects I have")); } public override async execute(interaction: CommandInteraction) { diff --git a/src/commands/effects/list.ts b/src/commands/effects/list.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/database/entities/app/UserEffect.ts b/src/database/entities/app/UserEffect.ts index fa1b584..189b206 100644 --- a/src/database/entities/app/UserEffect.ts +++ b/src/database/entities/app/UserEffect.ts @@ -57,4 +57,19 @@ export default class UserEffect extends AppBaseEntity { return single; } + + public static async FetchAllByUserIdPaginated(userId: string, page: number = 0): Promise { + const itemsPerPage = 10; + + const repository = AppDataSource.getRepository(UserEffect); + + const all = await repository.find({ + where: { UserId: userId }, + order: { Name: "ASC" }, + skip: page * itemsPerPage, + take: itemsPerPage, + }); + + return all; + } } diff --git a/src/helpers/EffectHelper.ts b/src/helpers/EffectHelper.ts index 14c2f43..7f16f84 100644 --- a/src/helpers/EffectHelper.ts +++ b/src/helpers/EffectHelper.ts @@ -1,4 +1,6 @@ +import {EmbedBuilder} from "discord.js"; import UserEffect from "../database/entities/app/UserEffect"; +import EmbedColours from "../constants/EmbedColours"; export default class EffectHelper { public static async AddEffectToUserInventory(userId: string, name: string, quantity: number = 1) { @@ -46,4 +48,21 @@ export default class EffectHelper { return true; } + + public static async GenerateEffectEmbed(userId: string, page: number): Promise { + const effects = await UserEffect.FetchAllByUserIdPaginated(userId, page - 1); + + let description = "*none*"; + + if (effects.length > 0) { + description = effects.map(x => `${x.Name} x${x.Unused}`).join("\n"); + } + + const embed = new EmbedBuilder() + .setTitle("Effects") + .setDescription(description) + .setColor(EmbedColours.Ok); + + return embed; + } }