diff --git a/.dev.env b/.dev.env index 14ad89c..d1b74b1 100644 --- a/.dev.env +++ b/.dev.env @@ -7,7 +7,7 @@ # any secret values. BOT_TOKEN= -BOT_VER=0.4.0 +BOT_VER=0.3.1 BOT_AUTHOR=Vylpes BOT_OWNERID=147392775707426816 BOT_CLIENTID=682942374040961060 diff --git a/.prod.env b/.prod.env index df28009..0755c1e 100644 --- a/.prod.env +++ b/.prod.env @@ -7,7 +7,7 @@ # any secret values. BOT_TOKEN= -BOT_VER=0.4.0 +BOT_VER=0.3.1 BOT_AUTHOR=Vylpes BOT_OWNERID=147392775707426816 BOT_CLIENTID=1093810443589529631 diff --git a/.stage.env b/.stage.env index 79dcc48..4f70991 100644 --- a/.stage.env +++ b/.stage.env @@ -7,7 +7,7 @@ # any secret values. BOT_TOKEN= -BOT_VER=0.4.0 +BOT_VER=0.3.1 BOT_AUTHOR=Vylpes BOT_OWNERID=147392775707426816 BOT_CLIENTID=1147976642942214235 diff --git a/package-lock.json b/package-lock.json index ab7b52a..2a39551 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1656,9 +1656,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "20.10.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.5.tgz", - "integrity": "sha512-nNPsNE65wjMxEKI93yOP+NPGGBJz/PoN3kZsVLee0XMiJolxSekEVD8wRwBUBqkwc7UWop0edW50yrCQW4CyRw==", + "version": "20.10.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.4.tgz", + "integrity": "sha512-D08YG6rr8X90YB56tSIuBaddy/UXAA9RKJoFvrsnogAum/0pmjkgi4+2nx96A330FmioegBWmEYQ+syqCFaveg==", "dependencies": { "undici-types": "~5.26.4" } diff --git a/src/buttonEvents/Inventory.ts b/src/buttonEvents/Inventory.ts deleted file mode 100644 index 63ea5a4..0000000 --- a/src/buttonEvents/Inventory.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ButtonInteraction } from "discord.js"; -import { ButtonEvent } from "../type/buttonEvent"; -import InventoryHelper from "../helpers/InventoryHelper"; - -export default class Inventory extends ButtonEvent { - public override async execute(interaction: ButtonInteraction) { - const userid = interaction.customId.split(' ')[1]; - const page = interaction.customId.split(' ')[2]; - - try { - const embed = await InventoryHelper.GenerateInventoryPage(interaction.user.username, userid, Number(page)); - - await interaction.update({ - embeds: [ embed.embed ], - components: [ embed.row ], - }); - } catch { - await interaction.reply("No page for user found."); - } - } -} \ No newline at end of file diff --git a/src/client/client.ts b/src/client/client.ts index 85ef43e..643036d 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -14,7 +14,6 @@ import { Environment } from "../constants/Environment"; import Webhooks from "../webhooks"; import CardMetadataFunction from "../Functions/CardMetadataFunction"; import SeriesMetadata from "../contracts/SeriesMetadata"; -import InventoryHelper from "../helpers/InventoryHelper"; export class CoreClient extends Client { private static _commandItems: ICommandItem[]; diff --git a/src/commands/drop.ts b/src/commands/drop.ts index 2ecd936..5a8ccd9 100644 --- a/src/commands/drop.ts +++ b/src/commands/drop.ts @@ -1,4 +1,4 @@ -import { AttachmentBuilder, CommandInteraction, SlashCommandBuilder } from "discord.js"; +import { AttachmentBuilder, CommandInteraction, DiscordAPIError, SlashCommandBuilder } from "discord.js"; import { Command } from "../type/command"; import { readFileSync } from "fs"; import { CoreClient } from "../client/client"; diff --git a/src/commands/inventory.ts b/src/commands/inventory.ts deleted file mode 100644 index 39d0881..0000000 --- a/src/commands/inventory.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { CommandInteraction, SlashCommandBuilder } from "discord.js"; -import { Command } from "../type/command"; -import InventoryHelper from "../helpers/InventoryHelper"; - -export default class Inventory extends Command { - constructor() { - super(); - - this.CommandBuilder = new SlashCommandBuilder() - .setName('inventory') - .setDescription('View your inventory') - .addNumberOption(x => - x - .setName('page') - .setDescription('The page to start with')); - } - - public override async execute(interaction: CommandInteraction) { - const page = interaction.options.get('page'); - - try { - let pageNumber = 0; - - if (page && page.value) { - pageNumber = Number(page.value) - 1; - } - - const embed = await InventoryHelper.GenerateInventoryPage(interaction.user.username, interaction.user.id, pageNumber); - - await interaction.reply({ - embeds: [ embed.embed ], - components: [ embed.row ], - }); - } catch { - await interaction.reply("No page for user found."); - } - } -} \ No newline at end of file diff --git a/src/database/entities/app/Inventory.ts b/src/database/entities/app/Inventory.ts index cfe8c3d..adec824 100644 --- a/src/database/entities/app/Inventory.ts +++ b/src/database/entities/app/Inventory.ts @@ -40,12 +40,4 @@ export default class Inventory extends AppBaseEntity { return single; } - - public static async FetchAllByUserId(userId: string): Promise { - const repository = AppDataSource.getRepository(Inventory); - - const all = await repository.find({ where: { UserId: userId }}); - - return all; - } } \ No newline at end of file diff --git a/src/helpers/InventoryHelper.ts b/src/helpers/InventoryHelper.ts deleted file mode 100644 index ad4bf85..0000000 --- a/src/helpers/InventoryHelper.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js"; -import Inventory from "../database/entities/app/Inventory"; -import { CoreClient } from "../client/client"; -import SeriesMetadata from "../contracts/SeriesMetadata"; -import EmbedColours from "../constants/EmbedColours"; -import { CardRarity, CardRarityToString } from "../constants/CardRarity"; - -interface InventoryPage { - id: number, - name: string, - cards: InventoryPageCards[], - seriesSubpage: number, -} - -interface InventoryPageCards { - id: string, - name: string, - type: CardRarity, - quantity: number, -} - -export default class InventoryHelper { - public static async GenerateInventoryPage(username: string, userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder }> { - const cardsPerPage = 15; - - const inventory = await Inventory.FetchAllByUserId(userid); - - const allSeriesClaimed = CoreClient.Cards - .sort((a, b) => a.id - b.id) - .filter(x => { - x.cards = x.cards - .sort((a, b) => b.type - a.type) - .filter(y => inventory.find(z => z.CardNumber == y.id)); - - return x; - }); - - const pages: InventoryPage[] = []; - - for (let series of allSeriesClaimed) { - const seriesCards = series.cards; - - for (let i = 0; i < seriesCards.length; i+= cardsPerPage) { - const cards = series.cards.slice(i, i + cardsPerPage); - const pageCards: InventoryPageCards[] = []; - - for (let card of cards) { - const item = inventory.find(x => x.CardNumber == card.id); - - if (!item) { - continue; - } - - pageCards.push({ - id: card.id, - name: card.name, - type: card.type, - quantity: item.Quantity, - }); - } - - pages.push({ - id: series.id, - name: series.name, - cards: pageCards, - seriesSubpage: i / cardsPerPage, - }); - } - } - - const currentPage = pages[page]; - - if (!currentPage) { - console.error("Unable to find page"); - return Promise.reject("Unable to find page"); - } - - const embed = new EmbedBuilder() - .setTitle(username) - .setDescription(`**${currentPage.name} (${currentPage.seriesSubpage + 1})**\n${currentPage.cards.map(x => `[${x.id}] ${x.name} (${CardRarityToString(x.type)}) x${x.quantity}`).join('\n')}`) - .setFooter({ text: `Page ${page + 1} of ${pages.length}` }) - .setColor(EmbedColours.Ok); - - const row = new ActionRowBuilder() - .addComponents( - new ButtonBuilder() - .setCustomId(`inventory ${userid} ${page - 1}`) - .setLabel("Previous") - .setStyle(ButtonStyle.Primary) - .setDisabled(page == 0), - new ButtonBuilder() - .setCustomId(`inventory ${userid} ${page + 1}`) - .setLabel("Next") - .setStyle(ButtonStyle.Primary) - .setDisabled(page + 1 == pages.length)); - - return { embed, row }; - } -} \ No newline at end of file diff --git a/src/registry.ts b/src/registry.ts index 679c70e..e602198 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -1,11 +1,9 @@ import { CoreClient } from "./client/client"; -import { Environment } from "./constants/Environment"; // Global Command Imports import About from "./commands/about"; import Drop from "./commands/drop"; import Gdrivesync from "./commands/gdrivesync"; -import Inventory from "./commands/inventory"; import Resync from "./commands/resync"; // Test Command Imports @@ -14,8 +12,8 @@ import Droprarity from "./commands/stage/droprarity"; // Button Event Imports import Claim from "./buttonEvents/Claim"; -import InventoryButtonEvent from "./buttonEvents/Inventory"; import Reroll from "./buttonEvents/Reroll"; +import { Environment } from "./constants/Environment"; export default class Registry { public static RegisterCommands() { @@ -23,7 +21,6 @@ export default class Registry { CoreClient.RegisterCommand('about', new About()); CoreClient.RegisterCommand('drop', new Drop()); CoreClient.RegisterCommand('gdrivesync', new Gdrivesync()); - CoreClient.RegisterCommand('inventory', new Inventory()); CoreClient.RegisterCommand('resync', new Resync()); // Test Commands @@ -37,7 +34,6 @@ export default class Registry { public static RegisterButtonEvents() { CoreClient.RegisterButtonEvent('claim', new Claim()); - CoreClient.RegisterButtonEvent('inventory', new InventoryButtonEvent); CoreClient.RegisterButtonEvent('reroll', new Reroll()); } } \ No newline at end of file