Compare commits

..

5 commits

Author SHA1 Message Date
cb57b24521 Fix pagination bugs
All checks were successful
continuous-integration/drone/push Build is passing
2023-12-20 19:31:21 +00:00
fa9a84dbe6 Add page start option 2023-12-20 18:41:04 +00:00
bbe8f0d4d8 Add inventory button event 2023-12-20 18:37:06 +00:00
95ed90b916 Create inventory command 2023-12-20 18:33:07 +00:00
b667f1ffb9 Put user's name in the embed 2023-12-20 18:30:32 +00:00
5 changed files with 56 additions and 13 deletions

View file

@ -0,0 +1,21 @@
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.");
}
}
}

View file

@ -84,11 +84,7 @@ export class CoreClient extends Client {
console.log(`Registered Events: ${CoreClient._eventItems.flatMap(x => x.EventType).join(", ")}`);
console.log(`Registered Buttons: ${CoreClient._buttonEvents.flatMap(x => x.ButtonId).join(", ")}`);
const page = await InventoryHelper.GenerateInventoryPage('125776189666230272', 0);
console.log(page);
// await super.login(process.env.BOT_TOKEN);
await super.login(process.env.BOT_TOKEN);
}
public static RegisterCommand(name: string, command: Command, environment: Environment = Environment.All, serverId?: string) {

View file

@ -1,5 +1,6 @@
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
import { Command } from "../type/command";
import InventoryHelper from "../helpers/InventoryHelper";
export default class Inventory extends Command {
constructor() {
@ -7,10 +8,31 @@ export default class Inventory extends Command {
this.CommandBuilder = new SlashCommandBuilder()
.setName('inventory')
.setDescription('View your 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.");
}
}
}

View file

@ -20,8 +20,8 @@ interface InventoryPageCards {
}
export default class InventoryHelper {
public static async GenerateInventoryPage(userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder<ButtonBuilder> }> {
const cardsPerPage = 9;
public static async GenerateInventoryPage(username: string, userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder<ButtonBuilder> }> {
const cardsPerPage = 15;
const inventory = await Inventory.FetchAllByUserId(userid);
@ -76,9 +76,9 @@ export default class InventoryHelper {
}
const embed = new EmbedBuilder()
.setTitle(`${currentPage.name} (${currentPage.seriesSubpage + 1})`)
.setDescription(currentPage.cards.map(x => `[${x.id}] ${x.name} (${CardRarityToString(x.type)}) x${x.quantity}`).join('\n'))
.setFooter({ text: `Page ${page} of ${pages.length}` })
.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<ButtonBuilder>()
@ -92,7 +92,7 @@ export default class InventoryHelper {
.setCustomId(`inventory ${userid} ${page + 1}`)
.setLabel("Next")
.setStyle(ButtonStyle.Primary)
.setDisabled(page == pages.length));
.setDisabled(page + 1 == pages.length));
return { embed, row };
}

View file

@ -1,9 +1,11 @@
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
@ -12,8 +14,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() {
@ -21,6 +23,7 @@ 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
@ -34,6 +37,7 @@ export default class Registry {
public static RegisterButtonEvents() {
CoreClient.RegisterButtonEvent('claim', new Claim());
CoreClient.RegisterButtonEvent('inventory', new InventoryButtonEvent);
CoreClient.RegisterButtonEvent('reroll', new Reroll());
}
}