windsor-bot 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
1
  import { join, dirname } from 'path';
2
2
  import { fileURLToPath } from 'url';
3
+ import { access } from 'fs/promises';
3
4
  import { tryExecCommandFunction } from './util.js';
4
5
  const __dirname = dirname(fileURLToPath(import.meta.url));
5
- const SPRITE_DIR = join(__dirname, '../assets/pokemon-sprites');
6
+ const SPRITE_DIR = join(__dirname, '../../assets/pokemon-sprites');
6
7
  // Kanto Pokédex — index 0 = Bulbasaur (#1)
7
8
  const KANTO = [
8
9
  'Bulbasaur', 'Ivysaur', 'Venusaur',
@@ -117,6 +118,12 @@ async function pokemonWorker(args, ctx) {
117
118
  }
118
119
  const spritePath = join(SPRITE_DIR, `${id}.png`);
119
120
  const numStr = String(id).padStart(3, '0');
121
+ try {
122
+ await access(spritePath);
123
+ }
124
+ catch (error) {
125
+ throw new Error(`Pokémon sprite not found at ${spritePath}`, { cause: error });
126
+ }
120
127
  const job = {
121
128
  header: `#${numStr} ${name}`,
122
129
  lines: [],
@@ -32,6 +32,19 @@ export async function buildPdfBuffer(job, paperSize) {
32
32
  doc.fontSize(FONT_HEADER).font('Helvetica-Bold').text(job.header, { align: 'center', lineGap: LINE_GAP });
33
33
  doc.moveDown(0.5);
34
34
  }
35
+ if (job.iconPath) {
36
+ try {
37
+ doc.image(job.iconPath, {
38
+ fit: [doc.page.width - MARGIN * 2, 300],
39
+ align: 'center',
40
+ valign: 'center',
41
+ });
42
+ doc.moveDown(0.5);
43
+ }
44
+ catch (error) {
45
+ throw new Error(`Failed to load image ${job.iconPath}`, { cause: error });
46
+ }
47
+ }
35
48
  // Primary text
36
49
  if (job.lines.length > 0) {
37
50
  doc.fontSize(bodyFontSize).font('Helvetica');
@@ -59,8 +59,8 @@ export async function buildEscpBuffer(job) {
59
59
  await printer.draw(escImage);
60
60
  await printer.feed(1);
61
61
  }
62
- catch {
63
- // silently skip if image can't be loaded/printed
62
+ catch (error) {
63
+ throw new Error(`Failed to load or print image ${job.iconPath}`, { cause: error });
64
64
  }
65
65
  }
66
66
  // Primary text
@@ -66,8 +66,8 @@ export async function renderJobToPng(job) {
66
66
  sprite.resize({ w: Math.round(sprite.width * scale), h: Math.round(sprite.height * scale), mode: ResizeStrategy.NEAREST_NEIGHBOR });
67
67
  scaledSprite = sprite;
68
68
  }
69
- catch {
70
- // silently skip
69
+ catch (error) {
70
+ throw new Error(`Failed to load image ${job.iconPath}`, { cause: error });
71
71
  }
72
72
  }
73
73
  // Measure total height now that icon dimensions are known
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "windsor-bot",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Self-hosted Discord bot automation for household list and todo printing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",