Compare commits

..

No commits in common. "9bf145c4e3cddd77843a7d3e16ebd382fa44ed0d" and "9b11d5d4951e216660d25ac077e07c53f6096e4f" have entirely different histories.

8 changed files with 17 additions and 51 deletions

View file

@ -6,16 +6,14 @@ import SeriesMetadata from "../contracts/SeriesMetadata";
import { CoreClient } from "../client/client"; import { CoreClient } from "../client/client";
export default class CardMetadataFunction { export default class CardMetadataFunction {
public static async Execute(overrideSafeMode: boolean = false): Promise<boolean> { public static async Execute(): Promise<boolean> {
if (!overrideSafeMode && await Config.GetValue('safemode') == "true") return false; if (await Config.GetValue('safemode') == "true") return false;
try { try {
CoreClient.Cards = await this.FindMetadataJSONs(); CoreClient.Cards = await this.FindMetadataJSONs();
console.log(`Loaded ${CoreClient.Cards.flatMap(x => x.cards).length} cards to database`); console.log(`Loaded ${CoreClient.Cards.flatMap(x => x.cards).length} cards to database`);
} catch (e) { } catch {
console.error(e);
await Config.SetValue('safemode', 'true'); await Config.SetValue('safemode', 'true');
return false; return false;
} }
@ -29,7 +27,6 @@ export default class CardMetadataFunction {
const seriesJSONs = await glob(path.join(process.cwd(), 'cards', '/**/*.json')); const seriesJSONs = await glob(path.join(process.cwd(), 'cards', '/**/*.json'));
for (let jsonPath of seriesJSONs) { for (let jsonPath of seriesJSONs) {
console.log(`Reading file ${jsonPath}`);
const jsonFile = readFileSync(jsonPath); const jsonFile = readFileSync(jsonPath);
const parsedJson: SeriesMetadata[] = JSON.parse(jsonFile.toString()); const parsedJson: SeriesMetadata[] = JSON.parse(jsonFile.toString());

View file

@ -7,8 +7,8 @@ import { CardRarity, CardRarityToString } from "../constants/CardRarity";
import Config from "../database/entities/app/Config"; import Config from "../database/entities/app/Config";
export default class CardSetupFunction { export default class CardSetupFunction {
public static async Execute(overrideSafeMode: boolean = false): Promise<boolean> { public static async Execute(): Promise<boolean> {
if (!overrideSafeMode && await Config.GetValue('safemode') == "true") return false; if (await Config.GetValue('safemode') == "true") return false;
try { try {
await this.ClearDatabase(); await this.ClearDatabase();

View file

@ -33,24 +33,16 @@ export default class Reroll extends ButtonEvent {
return; return;
} }
let image: Buffer; const image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path));
const imageFileName = randomCard.card.path.split("/").pop()!;
try {
image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path));
} catch {
await interaction.reply(`Unable to fetch image for card ${randomCard.card.id}`);
return;
}
await interaction.deferReply(); await interaction.deferReply();
const attachment = new AttachmentBuilder(image, { name: imageFileName }); const attachment = new AttachmentBuilder(image, { name: randomCard.card.id });
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id);
const quantityClaimed = inventory ? inventory.Quantity : 0; const quantityClaimed = inventory ? inventory.Quantity : 0;
const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed, imageFileName); const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed);
const claimId = v4(); const claimId = v4();

View file

@ -79,9 +79,9 @@ export class CoreClient extends Client {
super.on("ready", this._events.onReady); super.on("ready", this._events.onReady);
if (process.env.FEATURE_METADATA && process.env.FEATURE_METADATA == 'true') { if (process.env.FEATURE_METADATA && process.env.FEATURE_METADATA == 'true') {
await CardMetadataFunction.Execute(true); await CardMetadataFunction.Execute();
} else { } else {
await CardSetupFunction.Execute(true); await CardSetupFunction.Execute();
} }
this._util.loadEvents(this, CoreClient._eventItems); this._util.loadEvents(this, CoreClient._eventItems);

View file

@ -41,24 +41,16 @@ export default class Drop extends Command {
return; return;
} }
let image: Buffer; const image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path));
const imageFileName = randomCard.card.path.split("/").pop()!;
try {
image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path));
} catch {
await interaction.reply(`Unable to fetch image for card ${randomCard.card.id}`);
return;
}
await interaction.deferReply(); await interaction.deferReply();
const attachment = new AttachmentBuilder(image, { name: imageFileName }); const attachment = new AttachmentBuilder(image, { name: randomCard.card.id });
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id);
const quantityClaimed = inventory ? inventory.Quantity : 0; const quantityClaimed = inventory ? inventory.Quantity : 0;
const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed, imageFileName); const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed);
const claimId = v4(); const claimId = v4();

View file

@ -4,7 +4,6 @@ import { ExecException, exec } from "child_process";
import CardSetupFunction from "../Functions/CardSetupFunction"; import CardSetupFunction from "../Functions/CardSetupFunction";
import { CoreClient } from "../client/client"; import { CoreClient } from "../client/client";
import Config from "../database/entities/app/Config"; import Config from "../database/entities/app/Config";
import CardMetadataFunction from "../Functions/CardMetadataFunction";
export default class Gdrivesync extends Command { export default class Gdrivesync extends Command {
constructor() { constructor() {
@ -35,12 +34,7 @@ export default class Gdrivesync extends Command {
await interaction.editReply(`Error while running sync command. Safe Mode has been activated. Code: ${error.code}`); await interaction.editReply(`Error while running sync command. Safe Mode has been activated. Code: ${error.code}`);
await Config.SetValue('safemode', 'true'); await Config.SetValue('safemode', 'true');
} else { } else {
if (process.env.FEATURE_METADATA && process.env.FEATURE_METADATA == 'true') { await CardSetupFunction.Execute();
await CardMetadataFunction.Execute();
} else {
await CardSetupFunction.Execute();
}
await interaction.editReply('Synced successfully.'); await interaction.editReply('Synced successfully.');
CoreClient.AllowDrops = true; CoreClient.AllowDrops = true;

View file

@ -2,7 +2,6 @@ import { CacheType, CommandInteraction, PermissionsBitField, SlashCommandBuilder
import { Command } from "../type/command"; import { Command } from "../type/command";
import CardSetupFunction from "../Functions/CardSetupFunction"; import CardSetupFunction from "../Functions/CardSetupFunction";
import Config from "../database/entities/app/Config"; import Config from "../database/entities/app/Config";
import CardMetadataFunction from "../Functions/CardMetadataFunction";
export default class Resync extends Command { export default class Resync extends Command {
constructor() { constructor() {
@ -24,15 +23,7 @@ export default class Resync extends Command {
return; return;
} }
let result: boolean; if (await CardSetupFunction.Execute()) {
if (process.env.FEATURE_METADATA && process.env.FEATURE_METADATA == 'true') {
result = await CardMetadataFunction.Execute(true);
} else {
result = await CardSetupFunction.Execute(true);
}
if (result) {
if (await Config.GetValue('safemode') == "true") { if (await Config.GetValue('safemode') == "true") {
await Config.SetValue('safemode', 'false'); await Config.SetValue('safemode', 'false');
await interaction.reply("Resynced database and disabled safe mode."); await interaction.reply("Resynced database and disabled safe mode.");

View file

@ -48,7 +48,7 @@ export default class CardDropHelperMetadata {
}; };
} }
public static GenerateDropEmbed(drop: DropResult, quantityClaimed: Number, imageFileName: string): EmbedBuilder { public static GenerateDropEmbed(drop: DropResult, quantityClaimed: Number): EmbedBuilder {
let description = ""; let description = "";
description += `Series: ${drop.series.name}\n`; description += `Series: ${drop.series.name}\n`;
description += `Claimed: ${quantityClaimed}\n`; description += `Claimed: ${quantityClaimed}\n`;
@ -58,7 +58,7 @@ export default class CardDropHelperMetadata {
.setDescription(description) .setDescription(description)
.setFooter({ text: CardRarityToString(drop.card.type) }) .setFooter({ text: CardRarityToString(drop.card.type) })
.setColor(CardRarityToColour(drop.card.type)) .setColor(CardRarityToColour(drop.card.type))
.setImage(`attachment://${imageFileName}`); .setImage(`attachment://${drop.card.id}`);
} }
public static GenerateDropButtons(drop: DropResult, claimId: string, userId: string): ActionRowBuilder<ButtonBuilder> { public static GenerateDropButtons(drop: DropResult, claimId: string, userId: string): ActionRowBuilder<ButtonBuilder> {