Compare commits
5 commits
66b499d8d2
...
3c3381847b
Author | SHA1 | Date | |
---|---|---|---|
3c3381847b | |||
366bf08d3e | |||
b9f6ea69b7 | |||
c8a4fe25d1 | |||
f475f5fb42 |
8 changed files with 133 additions and 5 deletions
2
.dev.env
2
.dev.env
|
@ -7,7 +7,7 @@
|
||||||
# any secret values.
|
# any secret values.
|
||||||
|
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=0.3.1
|
BOT_VER=0.4.0
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
BOT_CLIENTID=682942374040961060
|
BOT_CLIENTID=682942374040961060
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
# any secret values.
|
# any secret values.
|
||||||
|
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=0.3.1
|
BOT_VER=0.4.0
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
BOT_CLIENTID=1093810443589529631
|
BOT_CLIENTID=1093810443589529631
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
# any secret values.
|
# any secret values.
|
||||||
|
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=0.3.1
|
BOT_VER=0.4.0
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
BOT_CLIENTID=1147976642942214235
|
BOT_CLIENTID=1147976642942214235
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { Environment } from "../constants/Environment";
|
||||||
import Webhooks from "../webhooks";
|
import Webhooks from "../webhooks";
|
||||||
import CardMetadataFunction from "../Functions/CardMetadataFunction";
|
import CardMetadataFunction from "../Functions/CardMetadataFunction";
|
||||||
import SeriesMetadata from "../contracts/SeriesMetadata";
|
import SeriesMetadata from "../contracts/SeriesMetadata";
|
||||||
|
import InventoryHelper from "../helpers/InventoryHelper";
|
||||||
|
|
||||||
export class CoreClient extends Client {
|
export class CoreClient extends Client {
|
||||||
private static _commandItems: ICommandItem[];
|
private static _commandItems: ICommandItem[];
|
||||||
|
@ -83,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) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { AttachmentBuilder, CommandInteraction, DiscordAPIError, SlashCommandBuilder } from "discord.js";
|
import { AttachmentBuilder, CommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
import { CoreClient } from "../client/client";
|
import { CoreClient } from "../client/client";
|
||||||
|
|
16
src/commands/inventory.ts
Normal file
16
src/commands/inventory.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||||
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
|
export default class Inventory extends Command {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('inventory')
|
||||||
|
.setDescription('View your inventory');
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async execute(interaction: CommandInteraction) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,4 +40,12 @@ export default class Inventory extends AppBaseEntity {
|
||||||
|
|
||||||
return single;
|
return single;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async FetchAllByUserId(userId: string): Promise<Inventory[]> {
|
||||||
|
const repository = AppDataSource.getRepository(Inventory);
|
||||||
|
|
||||||
|
const all = await repository.find({ where: { UserId: userId }});
|
||||||
|
|
||||||
|
return all;
|
||||||
|
}
|
||||||
}
|
}
|
99
src/helpers/InventoryHelper.ts
Normal file
99
src/helpers/InventoryHelper.ts
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
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(userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder<ButtonBuilder> }> {
|
||||||
|
const cardsPerPage = 9;
|
||||||
|
|
||||||
|
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(`${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}` })
|
||||||
|
.setColor(EmbedColours.Ok);
|
||||||
|
|
||||||
|
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||||
|
.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 == pages.length));
|
||||||
|
|
||||||
|
return { embed, row };
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue