Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
c4e345cc46 | |||
659906e562 | |||
1796f2519e |
2 changed files with 49 additions and 39 deletions
|
@ -60,13 +60,18 @@ export default class Series extends Command {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const embed = await SeriesHelper.GenerateSeriesViewPage(series.id, 0, interaction.user.id);
|
try {
|
||||||
|
const embed = await SeriesHelper.GenerateSeriesViewPage(series.id, 0, interaction.user.id);
|
||||||
|
|
||||||
await interaction.followUp({
|
await interaction.followUp({
|
||||||
embeds: [ embed!.embed ],
|
embeds: [ embed!.embed ],
|
||||||
components: [ embed!.row ],
|
components: [ embed!.row ],
|
||||||
files: [ embed!.image ],
|
files: [ embed!.image ],
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
await interaction.followUp("An error has occured generating the series grid.");
|
||||||
|
AppLogger.CatchError("Series", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async ListSeries(interaction: CommandInteraction) {
|
private async ListSeries(interaction: CommandInteraction) {
|
||||||
|
|
|
@ -26,46 +26,51 @@ export default class ImageHelper {
|
||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
|
|
||||||
for (let i = 0; i < cards.length; i++) {
|
for (let i = 0; i < cards.length; i++) {
|
||||||
const card = cards[i];
|
try {
|
||||||
|
const card = cards[i];
|
||||||
|
|
||||||
const filePath = path.join(process.env.DATA_DIR!, "cards", card.path);
|
const filePath = path.join(process.env.DATA_DIR!, "cards", card.path);
|
||||||
|
|
||||||
let bitmap: Bitmap;
|
let bitmap: Bitmap;
|
||||||
|
|
||||||
if (existsSync(filePath)) {
|
if (existsSync(filePath)) {
|
||||||
const data = await Jimp.read(filePath);
|
const data = await Jimp.read(filePath);
|
||||||
|
|
||||||
bitmap = data.bitmap;
|
bitmap = data.bitmap;
|
||||||
} else if (card.path.startsWith("http://") || card.path.startsWith("https://")) {
|
} else if (card.path.startsWith("http://") || card.path.startsWith("https://")) {
|
||||||
const response = await axios.get(card.path, { responseType: "arraybuffer" });
|
const response = await axios.get(card.path, { responseType: "arraybuffer" });
|
||||||
const buffer = Buffer.from(response.data);
|
const buffer = Buffer.from(response.data);
|
||||||
const data = await Jimp.fromBuffer(buffer);
|
const data = await Jimp.fromBuffer(buffer);
|
||||||
|
|
||||||
bitmap = data.bitmap;
|
bitmap = data.bitmap;
|
||||||
} else {
|
} else {
|
||||||
AppLogger.LogError("ImageHelper/GenerateCardImageGrid", `Failed to load image from path ${card.path}`);
|
AppLogger.LogError("ImageHelper/GenerateCardImageGrid", `Failed to load image from path ${card.path}`);
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
const imageData = Jimp.fromBitmap(bitmap);
|
|
||||||
|
|
||||||
if (userId != null) {
|
|
||||||
const claimed = await Inventory.FetchOneByCardNumberAndUserId(userId, card.id);
|
|
||||||
|
|
||||||
if (!claimed || claimed.Quantity == 0) {
|
|
||||||
imageData.greyscale();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const imageData = Jimp.fromBitmap(bitmap);
|
||||||
|
|
||||||
|
if (userId != null) {
|
||||||
|
const claimed = await Inventory.FetchOneByCardNumberAndUserId(userId, card.id);
|
||||||
|
|
||||||
|
if (!claimed || claimed.Quantity == 0) {
|
||||||
|
imageData.greyscale();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const image = await loadImage(await imageData.getBuffer("image/png"));
|
||||||
|
|
||||||
|
const x = i % gridWidth;
|
||||||
|
const y = Math.floor(i / gridWidth);
|
||||||
|
|
||||||
|
const imageX = imageWidth * x;
|
||||||
|
const imageY = imageHeight * y;
|
||||||
|
|
||||||
|
ctx.drawImage(image, imageX, imageY);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
AppLogger.CatchError("ImageHelper", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
const image = await loadImage(await imageData.getBuffer("image/png"));
|
|
||||||
|
|
||||||
const x = i % gridWidth;
|
|
||||||
const y = Math.floor(i / gridWidth);
|
|
||||||
|
|
||||||
const imageX = imageWidth * x;
|
|
||||||
const imageY = imageHeight * y;
|
|
||||||
|
|
||||||
ctx.drawImage(image, imageX, imageY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return canvas.toBuffer();
|
return canvas.toBuffer();
|
||||||
|
|
Loading…
Add table
Reference in a new issue