Compare commits
5 commits
3c3381847b
...
cb57b24521
Author | SHA1 | Date | |
---|---|---|---|
cb57b24521 | |||
fa9a84dbe6 | |||
bbe8f0d4d8 | |||
95ed90b916 | |||
b667f1ffb9 |
5 changed files with 56 additions and 13 deletions
21
src/buttonEvents/Inventory.ts
Normal file
21
src/buttonEvents/Inventory.ts
Normal 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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -84,11 +84,7 @@ 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(", ")}`);
|
||||||
|
|
||||||
const page = await InventoryHelper.GenerateInventoryPage('125776189666230272', 0);
|
await super.login(process.env.BOT_TOKEN);
|
||||||
|
|
||||||
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) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
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() {
|
||||||
|
@ -7,10 +8,31 @@ 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.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,8 +20,8 @@ interface InventoryPageCards {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class InventoryHelper {
|
export default class InventoryHelper {
|
||||||
public static async GenerateInventoryPage(userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder<ButtonBuilder> }> {
|
public static async GenerateInventoryPage(username: string, userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder<ButtonBuilder> }> {
|
||||||
const cardsPerPage = 9;
|
const cardsPerPage = 15;
|
||||||
|
|
||||||
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(`${currentPage.name} (${currentPage.seriesSubpage + 1})`)
|
.setTitle(username)
|
||||||
.setDescription(currentPage.cards.map(x => `[${x.id}] ${x.name} (${CardRarityToString(x.type)}) x${x.quantity}`).join('\n'))
|
.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} of ${pages.length}` })
|
.setFooter({ text: `Page ${page + 1} 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 == pages.length));
|
.setDisabled(page + 1 == pages.length));
|
||||||
|
|
||||||
return { embed, row };
|
return { embed, row };
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
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
|
||||||
|
@ -12,8 +14,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() {
|
||||||
|
@ -21,6 +23,7 @@ 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
|
||||||
|
@ -34,6 +37,7 @@ 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue