Compare commits
No commits in common. "9bf145c4e3cddd77843a7d3e16ebd382fa44ed0d" and "9b11d5d4951e216660d25ac077e07c53f6096e4f" have entirely different histories.
9bf145c4e3
...
9b11d5d495
8 changed files with 17 additions and 51 deletions
|
@ -6,16 +6,14 @@ import SeriesMetadata from "../contracts/SeriesMetadata";
|
|||
import { CoreClient } from "../client/client";
|
||||
|
||||
export default class CardMetadataFunction {
|
||||
public static async Execute(overrideSafeMode: boolean = false): Promise<boolean> {
|
||||
if (!overrideSafeMode && await Config.GetValue('safemode') == "true") return false;
|
||||
public static async Execute(): Promise<boolean> {
|
||||
if (await Config.GetValue('safemode') == "true") return false;
|
||||
|
||||
try {
|
||||
CoreClient.Cards = await this.FindMetadataJSONs();
|
||||
|
||||
console.log(`Loaded ${CoreClient.Cards.flatMap(x => x.cards).length} cards to database`);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
||||
} catch {
|
||||
await Config.SetValue('safemode', 'true');
|
||||
return false;
|
||||
}
|
||||
|
@ -29,7 +27,6 @@ export default class CardMetadataFunction {
|
|||
const seriesJSONs = await glob(path.join(process.cwd(), 'cards', '/**/*.json'));
|
||||
|
||||
for (let jsonPath of seriesJSONs) {
|
||||
console.log(`Reading file ${jsonPath}`);
|
||||
const jsonFile = readFileSync(jsonPath);
|
||||
const parsedJson: SeriesMetadata[] = JSON.parse(jsonFile.toString());
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import { CardRarity, CardRarityToString } from "../constants/CardRarity";
|
|||
import Config from "../database/entities/app/Config";
|
||||
|
||||
export default class CardSetupFunction {
|
||||
public static async Execute(overrideSafeMode: boolean = false): Promise<boolean> {
|
||||
if (!overrideSafeMode && await Config.GetValue('safemode') == "true") return false;
|
||||
public static async Execute(): Promise<boolean> {
|
||||
if (await Config.GetValue('safemode') == "true") return false;
|
||||
|
||||
try {
|
||||
await this.ClearDatabase();
|
||||
|
|
|
@ -33,24 +33,16 @@ export default class Reroll extends ButtonEvent {
|
|||
return;
|
||||
}
|
||||
|
||||
let image: Buffer;
|
||||
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;
|
||||
}
|
||||
const image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path));
|
||||
|
||||
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 quantityClaimed = inventory ? inventory.Quantity : 0;
|
||||
|
||||
const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed, imageFileName);
|
||||
const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed);
|
||||
|
||||
const claimId = v4();
|
||||
|
||||
|
|
|
@ -79,9 +79,9 @@ export class CoreClient extends Client {
|
|||
super.on("ready", this._events.onReady);
|
||||
|
||||
if (process.env.FEATURE_METADATA && process.env.FEATURE_METADATA == 'true') {
|
||||
await CardMetadataFunction.Execute(true);
|
||||
await CardMetadataFunction.Execute();
|
||||
} else {
|
||||
await CardSetupFunction.Execute(true);
|
||||
await CardSetupFunction.Execute();
|
||||
}
|
||||
|
||||
this._util.loadEvents(this, CoreClient._eventItems);
|
||||
|
|
|
@ -41,24 +41,16 @@ export default class Drop extends Command {
|
|||
return;
|
||||
}
|
||||
|
||||
let image: Buffer;
|
||||
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;
|
||||
}
|
||||
const image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path));
|
||||
|
||||
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 quantityClaimed = inventory ? inventory.Quantity : 0;
|
||||
|
||||
const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed, imageFileName);
|
||||
const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed);
|
||||
|
||||
const claimId = v4();
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import { ExecException, exec } from "child_process";
|
|||
import CardSetupFunction from "../Functions/CardSetupFunction";
|
||||
import { CoreClient } from "../client/client";
|
||||
import Config from "../database/entities/app/Config";
|
||||
import CardMetadataFunction from "../Functions/CardMetadataFunction";
|
||||
|
||||
export default class Gdrivesync extends Command {
|
||||
constructor() {
|
||||
|
@ -34,13 +33,8 @@ export default class Gdrivesync extends Command {
|
|||
if (error) {
|
||||
await interaction.editReply(`Error while running sync command. Safe Mode has been activated. Code: ${error.code}`);
|
||||
await Config.SetValue('safemode', 'true');
|
||||
} else {
|
||||
if (process.env.FEATURE_METADATA && process.env.FEATURE_METADATA == 'true') {
|
||||
await CardMetadataFunction.Execute();
|
||||
} else {
|
||||
await CardSetupFunction.Execute();
|
||||
}
|
||||
|
||||
await interaction.editReply('Synced successfully.');
|
||||
|
||||
CoreClient.AllowDrops = true;
|
||||
|
|
|
@ -2,7 +2,6 @@ import { CacheType, CommandInteraction, PermissionsBitField, SlashCommandBuilder
|
|||
import { Command } from "../type/command";
|
||||
import CardSetupFunction from "../Functions/CardSetupFunction";
|
||||
import Config from "../database/entities/app/Config";
|
||||
import CardMetadataFunction from "../Functions/CardMetadataFunction";
|
||||
|
||||
export default class Resync extends Command {
|
||||
constructor() {
|
||||
|
@ -24,15 +23,7 @@ export default class Resync extends Command {
|
|||
return;
|
||||
}
|
||||
|
||||
let result: boolean;
|
||||
|
||||
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 CardSetupFunction.Execute()) {
|
||||
if (await Config.GetValue('safemode') == "true") {
|
||||
await Config.SetValue('safemode', 'false');
|
||||
await interaction.reply("Resynced database and disabled safe mode.");
|
||||
|
|
|
@ -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 = "";
|
||||
description += `Series: ${drop.series.name}\n`;
|
||||
description += `Claimed: ${quantityClaimed}\n`;
|
||||
|
@ -58,7 +58,7 @@ export default class CardDropHelperMetadata {
|
|||
.setDescription(description)
|
||||
.setFooter({ text: CardRarityToString(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> {
|
||||
|
|
Loading…
Reference in a new issue