Compare commits

..

No commits in common. "cb57b245214a19cb6a141b75719f4c115507d625" and "3c3381847bc8f1e1fc204091c96ffdcf06f9cef7" have entirely different histories.

5 changed files with 13 additions and 56 deletions

View file

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

View file

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

View file

@ -1,6 +1,5 @@
import { CommandInteraction, SlashCommandBuilder } from "discord.js"; import { CommandInteraction, SlashCommandBuilder } from "discord.js";
import { Command } from "../type/command"; import { Command } from "../type/command";
import InventoryHelper from "../helpers/InventoryHelper";
export default class Inventory extends Command { export default class Inventory extends Command {
constructor() { constructor() {
@ -8,31 +7,10 @@ export default class Inventory extends Command {
this.CommandBuilder = new SlashCommandBuilder() this.CommandBuilder = new SlashCommandBuilder()
.setName('inventory') .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) { 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 { export default class InventoryHelper {
public static async GenerateInventoryPage(username: string, userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder<ButtonBuilder> }> { public static async GenerateInventoryPage(userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder<ButtonBuilder> }> {
const cardsPerPage = 15; const cardsPerPage = 9;
const inventory = await Inventory.FetchAllByUserId(userid); const inventory = await Inventory.FetchAllByUserId(userid);
@ -76,9 +76,9 @@ export default class InventoryHelper {
} }
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle(username) .setTitle(`${currentPage.name} (${currentPage.seriesSubpage + 1})`)
.setDescription(`**${currentPage.name} (${currentPage.seriesSubpage + 1})**\n${currentPage.cards.map(x => `[${x.id}] ${x.name} (${CardRarityToString(x.type)}) x${x.quantity}`).join('\n')}`) .setDescription(currentPage.cards.map(x => `[${x.id}] ${x.name} (${CardRarityToString(x.type)}) x${x.quantity}`).join('\n'))
.setFooter({ text: `Page ${page + 1} of ${pages.length}` }) .setFooter({ text: `Page ${page} of ${pages.length}` })
.setColor(EmbedColours.Ok); .setColor(EmbedColours.Ok);
const row = new ActionRowBuilder<ButtonBuilder>() const row = new ActionRowBuilder<ButtonBuilder>()
@ -92,7 +92,7 @@ export default class InventoryHelper {
.setCustomId(`inventory ${userid} ${page + 1}`) .setCustomId(`inventory ${userid} ${page + 1}`)
.setLabel("Next") .setLabel("Next")
.setStyle(ButtonStyle.Primary) .setStyle(ButtonStyle.Primary)
.setDisabled(page + 1 == pages.length)); .setDisabled(page == pages.length));
return { embed, row }; return { embed, row };
} }

View file

@ -1,11 +1,9 @@
import { CoreClient } from "./client/client"; import { CoreClient } from "./client/client";
import { Environment } from "./constants/Environment";
// Global Command Imports // Global Command Imports
import About from "./commands/about"; import About from "./commands/about";
import Drop from "./commands/drop"; import Drop from "./commands/drop";
import Gdrivesync from "./commands/gdrivesync"; import Gdrivesync from "./commands/gdrivesync";
import Inventory from "./commands/inventory";
import Resync from "./commands/resync"; import Resync from "./commands/resync";
// Test Command Imports // Test Command Imports
@ -14,8 +12,8 @@ import Droprarity from "./commands/stage/droprarity";
// Button Event Imports // Button Event Imports
import Claim from "./buttonEvents/Claim"; import Claim from "./buttonEvents/Claim";
import InventoryButtonEvent from "./buttonEvents/Inventory";
import Reroll from "./buttonEvents/Reroll"; import Reroll from "./buttonEvents/Reroll";
import { Environment } from "./constants/Environment";
export default class Registry { export default class Registry {
public static RegisterCommands() { public static RegisterCommands() {
@ -23,7 +21,6 @@ export default class Registry {
CoreClient.RegisterCommand('about', new About()); CoreClient.RegisterCommand('about', new About());
CoreClient.RegisterCommand('drop', new Drop()); CoreClient.RegisterCommand('drop', new Drop());
CoreClient.RegisterCommand('gdrivesync', new Gdrivesync()); CoreClient.RegisterCommand('gdrivesync', new Gdrivesync());
CoreClient.RegisterCommand('inventory', new Inventory());
CoreClient.RegisterCommand('resync', new Resync()); CoreClient.RegisterCommand('resync', new Resync());
// Test Commands // Test Commands
@ -37,7 +34,6 @@ export default class Registry {
public static RegisterButtonEvents() { public static RegisterButtonEvents() {
CoreClient.RegisterButtonEvent('claim', new Claim()); CoreClient.RegisterButtonEvent('claim', new Claim());
CoreClient.RegisterButtonEvent('inventory', new InventoryButtonEvent);
CoreClient.RegisterButtonEvent('reroll', new Reroll()); CoreClient.RegisterButtonEvent('reroll', new Reroll());
} }
} }