Merge branch 'develop' into feature/380-use-effect

This commit is contained in:
Ethan Lane 2025-01-22 17:49:40 +00:00
commit f726a613ea
10 changed files with 74 additions and 66 deletions

View file

@ -7,7 +7,7 @@
# any secret values.
BOT_TOKEN=
BOT_VER=0.8.2
BOT_VER=0.8.3
BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816
BOT_CLIENTID=682942374040961060

View file

@ -1,6 +1,6 @@
{
"name": "card-drop",
"version": "0.8.2",
"version": "0.8.3",
"main": "./dist/bot.js",
"typings": "./dist",
"scripts": {

View file

@ -52,10 +52,17 @@ export default class Reroll extends ButtonEvent {
try {
AppLogger.LogVerbose("Button/Reroll", `Sending next drop: ${randomCard.card.id} (${randomCard.card.name})`);
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path));
const imageFileName = randomCard.card.path.split("/").pop()!;
const files = [];
let imageFileName = "";
const attachment = new AttachmentBuilder(image, { name: imageFileName });
if (!(randomCard.card.path.startsWith("http://") || randomCard.card.path.startsWith("https://"))) {
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path));
imageFileName = randomCard.card.path.split("/").pop()!;
const attachment = new AttachmentBuilder(image, { name: imageFileName });
files.push(attachment);
}
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id);
const quantityClaimed = inventory ? inventory.Quantity : 0;
@ -68,7 +75,7 @@ export default class Reroll extends ButtonEvent {
await interaction.editReply({
embeds: [ embed ],
files: [ attachment ],
files: files,
components: [ row ],
});

View file

@ -19,7 +19,7 @@ export default class View extends ButtonEvent {
await interaction.editReply({
embeds: [ searchResult.embed ],
components: [ searchResult.row ],
files: [ searchResult.attachment ],
files: searchResult.attachments,
});
}
}

View file

@ -70,10 +70,17 @@ export default class Drop extends Command {
await interaction.deferReply();
try {
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path));
const imageFileName = randomCard.card.path.split("/").pop()!;
const files = [];
let imageFileName = "";
const attachment = new AttachmentBuilder(image, { name: imageFileName });
if (!(randomCard.card.path.startsWith("http://") || randomCard.card.path.startsWith("https://"))) {
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path));
imageFileName = randomCard.card.path.split("/").pop()!;
const attachment = new AttachmentBuilder(image, { name: imageFileName });
files.push(attachment);
}
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id);
const quantityClaimed = inventory ? inventory.Quantity : 0;
@ -86,7 +93,7 @@ export default class Drop extends Command {
await interaction.editReply({
embeds: [ embed ],
files: [ attachment ],
files: files,
components: [ row ],
});

View file

@ -43,22 +43,20 @@ export default class Id extends Command {
const series = CoreClient.Cards
.find(x => x.cards.includes(card))!;
let image: Buffer;
const imageFileName = card.path.split("/").pop()!;
const files = [];
let imageFileName = "";
try {
image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path));
} catch {
AppLogger.LogError("Commands/View", `Unable to fetch image for card ${card.id}.`);
if (!(card.path.startsWith("http://") || card.path.startsWith("https://"))) {
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path));
imageFileName = card.path.split("/").pop()!;
await interaction.reply(`Unable to fetch image for card ${card.id}.`);
return;
const attachment = new AttachmentBuilder(image, { name: imageFileName });
files.push(attachment);
}
await interaction.deferReply();
const attachment = new AttachmentBuilder(image, { name: imageFileName });
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.id);
const quantityClaimed = inventory ? inventory.Quantity : 0;
@ -67,7 +65,7 @@ export default class Id extends Command {
try {
await interaction.editReply({
embeds: [ embed ],
files: [ attachment ],
files: files,
});
} catch (e) {
AppLogger.LogError("Commands/View", `Error sending view for card ${card.id}: ${e}`);

View file

@ -43,20 +43,20 @@ export default class Dropnumber extends Command {
const series = CoreClient.Cards
.find(x => x.cards.includes(card))!;
let image: Buffer;
const imageFileName = card.path.split("/").pop()!;
const files = [];
let imageFileName = "";
try {
image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path));
} catch {
await interaction.reply(`Unable to fetch image for card ${card.id}`);
return;
if (!(card.path.startsWith("http://") || card.path.startsWith("https://"))) {
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path));
imageFileName = card.path.split("/").pop()!;
const attachment = new AttachmentBuilder(image, { name: imageFileName });
files.push(attachment);
}
await interaction.deferReply();
const attachment = new AttachmentBuilder(image, { name: imageFileName });
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.id);
const quantityClaimed = inventory ? inventory.Quantity : 0;
@ -69,7 +69,7 @@ export default class Dropnumber extends Command {
try {
await interaction.editReply({
embeds: [ embed ],
files: [ attachment ],
files: files,
components: [ row ],
});
} catch (e) {

View file

@ -47,20 +47,18 @@ export default class Droprarity extends Command {
return;
}
let image: Buffer;
const imageFileName = card.card.path.split("/").pop()!;
const files = [];
let imageFileName = "";
try {
image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
} catch {
await interaction.reply(`Unable to fetch image for card ${card.card.id}`);
return;
if (!(card.card.path.startsWith("http://") || card.card.path.startsWith("https://"))) {
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
imageFileName = card.card.path.split("/").pop()!;
const attachment = new AttachmentBuilder(image, { name: imageFileName });
files.push(attachment);
}
await interaction.deferReply();
const attachment = new AttachmentBuilder(image, { name: imageFileName });
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.card.id);
const quantityClaimed = inventory ? inventory.Quantity : 0;
@ -73,7 +71,7 @@ export default class Droprarity extends Command {
try {
await interaction.editReply({
embeds: [ embed ],
files: [ attachment ],
files: files,
components: [ row ],
});
} catch (e) {

View file

@ -34,7 +34,7 @@ export default class View extends Command {
await interaction.editReply({
embeds: [ searchResult.embed ],
components: [ searchResult.row ],
files: [ searchResult.attachment ],
files: searchResult.attachments,
});
}
}

View file

@ -11,7 +11,7 @@ import DropEmbedHelper from "./DropHelpers/DropEmbedHelper.js";
interface ReturnedPage {
embed: EmbedBuilder,
row: ActionRowBuilder<ButtonBuilder>,
attachment: AttachmentBuilder,
attachments: AttachmentBuilder[],
results: string[],
}
@ -37,19 +37,18 @@ export default class CardSearchHelper {
if (!card) return undefined;
let image: Buffer;
const imageFileName = card.card.path.split("/").pop()!;
const attachments = [];
let imageFileName = "";
try {
image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
} catch {
AppLogger.LogError("CardSearchHelper/GenerateSearchQuery", `Unable to fetch image for card ${card.card.id}.`);
if (!(card.card.path.startsWith("http://") || card.card.path.startsWith("https://"))) {
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
imageFileName = card.card.path.split("/").pop()!;
return undefined;
const attachment = new AttachmentBuilder(image, { name: imageFileName });
attachments.push(attachment);
}
const attachment = new AttachmentBuilder(image, { name: imageFileName });
const inventory = await Inventory.FetchOneByCardNumberAndUserId(userid, card.card.id);
const quantityClaimed = inventory?.Quantity ?? 0;
@ -68,7 +67,7 @@ export default class CardSearchHelper {
.setStyle(ButtonStyle.Primary)
.setDisabled(pages == 1));
return { embed, row, attachment, results };
return { embed, row, attachments, results };
}
public static async GenerateSearchPageFromQuery(results: string[], userid: string, page: number): Promise<ReturnedPage | undefined> {
@ -82,19 +81,18 @@ export default class CardSearchHelper {
return undefined;
}
let image: Buffer;
const imageFileName = card.card.path.split("/").pop()!;
const attachments = [];
let imageFileName = "";
try {
image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
} catch {
AppLogger.LogError("CardSearchHelper/GenerateSearchPageFromQuery", `Unable to fetch image for card ${card.card.id}.`);
if (!(card.card.path.startsWith("http://") || card.card.path.startsWith("https://"))) {
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
imageFileName = card.card.path.split("/").pop()!;
return undefined;
const attachment = new AttachmentBuilder(image, { name: imageFileName });
attachments.push(attachment);
}
const attachment = new AttachmentBuilder(image, { name: imageFileName });
const inventory = await Inventory.FetchOneByCardNumberAndUserId(userid, card.card.id);
const quantityClaimed = inventory?.Quantity ?? 0;
@ -113,6 +111,6 @@ export default class CardSearchHelper {
.setStyle(ButtonStyle.Primary)
.setDisabled(page == results.length));
return { embed, row, attachment, results };
return { embed, row, attachments, results };
}
}