@theholocron/holocron-plugin-discord 5.0.0-alpha.195 → 5.0.0-alpha.196

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.
package/dist/index.d.mts CHANGED
@@ -73,6 +73,10 @@ declare class DiscordNotifications implements Notifications {
73
73
  }>;
74
74
  /** A 403 on the welcome screen or onboarding becomes the likely reason; anything else is passed on. */
75
75
  private static communityFeatureHint;
76
+ /** The numeric code Discord puts in the JSON body of an error, or undefined when the body is not that. */
77
+ private static codeOf;
78
+ /** The welcome screen; a server that never had one answers 404 (10069), which is an empty screen. */
79
+ private welcomeScreenOf;
76
80
  ensureWelcome(welcome: NotificationsWelcomeLayout): Promise<{
77
81
  updated: string[];
78
82
  }>;
package/dist/index.mjs CHANGED
@@ -161,6 +161,9 @@ function keepThreadBits(desired, existing) {
161
161
  }
162
162
  return merged;
163
163
  }
164
+ let idCounter = 0;
165
+ /** A snowflake-shaped id for a new onboarding question or answer, which Discord asks the sender to make. */
166
+ const newId = () => String((BigInt(Date.now()) - 1420070400000n << 22n) + BigInt(idCounter++ % 4096));
164
167
  var DiscordNotifications = class DiscordNotifications {
165
168
  client;
166
169
  opts;
@@ -274,7 +277,7 @@ var DiscordNotifications = class DiscordNotifications {
274
277
  let welcomeError;
275
278
  if (layout.welcome) try {
276
279
  const guild = await bot.guilds.get(this.guild());
277
- const screen = await bot.guilds.welcomeScreen(this.guild());
280
+ const screen = await this.welcomeScreenOf();
278
281
  welcome = {
279
282
  enabled: (guild.features ?? []).includes("WELCOME_SCREEN_ENABLED"),
280
283
  description: screen.description ?? "",
@@ -477,6 +480,26 @@ var DiscordNotifications = class DiscordNotifications {
477
480
  if (!(err instanceof ProviderApiError && err.status === 403)) return err;
478
481
  return new Error(`the bot is not allowed to change ${what} (Discord said: ${String(err.details).slice(0, 120)}). It needs Manage Server, and the server needs community features on`, { cause: err });
479
482
  }
483
+ /** The numeric code Discord puts in the JSON body of an error, or undefined when the body is not that. */
484
+ static codeOf(err) {
485
+ try {
486
+ return JSON.parse(String(err.details)).code;
487
+ } catch {
488
+ return;
489
+ }
490
+ }
491
+ /** The welcome screen; a server that never had one answers 404 (10069), which is an empty screen. */
492
+ async welcomeScreenOf() {
493
+ try {
494
+ return await this.bot().guilds.welcomeScreen(this.guild());
495
+ } catch (err) {
496
+ if (err instanceof ProviderApiError && err.status === 404 && DiscordNotifications.codeOf(err) === 10069) return {
497
+ description: null,
498
+ welcome_channels: []
499
+ };
500
+ throw err;
501
+ }
502
+ }
480
503
  async ensureWelcome(welcome) {
481
504
  const bot = this.bot();
482
505
  const channels = await this.channelList();
@@ -501,7 +524,7 @@ var DiscordNotifications = class DiscordNotifications {
501
524
  let screen;
502
525
  try {
503
526
  guild = await bot.guilds.get(this.guild());
504
- screen = await bot.guilds.welcomeScreen(this.guild());
527
+ screen = await this.welcomeScreenOf();
505
528
  } catch (err) {
506
529
  throw DiscordNotifications.communityFeatureHint(err, "the welcome screen");
507
530
  }
@@ -549,20 +572,32 @@ var DiscordNotifications = class DiscordNotifications {
549
572
  } catch (err) {
550
573
  throw DiscordNotifications.communityFeatureHint(err, "onboarding");
551
574
  }
552
- const prompts = onboarding.prompts === void 0 ? current.prompts : onboarding.prompts.map((p) => ({
553
- type: 0,
554
- title: p.title,
555
- single_select: p.singleSelect ?? false,
556
- required: p.required ?? false,
557
- in_onboarding: true,
558
- options: p.options.map((o) => ({
559
- title: o.title,
560
- description: o.description ?? null,
561
- channel_ids: (o.channels ?? []).map(channelId),
562
- role_ids: (o.roles ?? []).map(roleId),
563
- emoji_name: o.emoji ?? null
564
- }))
565
- }));
575
+ const usedIds = /* @__PURE__ */ new Set();
576
+ const prompts = onboarding.prompts === void 0 ? current.prompts : onboarding.prompts.map((p) => {
577
+ const had = current.prompts.find((c) => c.title === p.title && !usedIds.has(c.id));
578
+ if (had) usedIds.add(had.id);
579
+ const hadOptions = /* @__PURE__ */ new Set();
580
+ return {
581
+ id: had?.id ?? newId(),
582
+ type: 0,
583
+ title: p.title,
584
+ single_select: p.singleSelect ?? false,
585
+ required: p.required ?? false,
586
+ in_onboarding: true,
587
+ options: p.options.map((o) => ({
588
+ id: (() => {
589
+ const old = had?.options.find((c) => c.title === o.title && !hadOptions.has(c.id));
590
+ if (old) hadOptions.add(old.id);
591
+ return old?.id ?? newId();
592
+ })(),
593
+ title: o.title,
594
+ description: o.description ?? null,
595
+ channel_ids: (o.channels ?? []).map(channelId),
596
+ role_ids: (o.roles ?? []).map(roleId),
597
+ emoji_name: o.emoji ?? null
598
+ }))
599
+ };
600
+ });
566
601
  const defaultChannels = onboarding.defaultChannels === void 0 ? current.default_channel_ids : onboarding.defaultChannels.map(channelId);
567
602
  const enabled = onboarding.enabled ?? current.enabled;
568
603
  const updated = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-discord",
3
- "version": "5.0.0-alpha.195",
3
+ "version": "5.0.0-alpha.196",
4
4
  "description": "Holocron plugin for Discord. Implements the notifications capability via Discord incoming webhooks.",
5
5
  "keywords": [
6
6
  "discord",
@@ -48,12 +48,12 @@
48
48
  "tsx": "4.23.15",
49
49
  "typescript": "^5.9.3",
50
50
  "vitest": "^4.1.11",
51
- "@theholocron/cli": "5.0.0-alpha.195"
51
+ "@theholocron/cli": "5.0.0-alpha.196"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@theholocron/discord-client": "^1.44.0",
55
55
  "@theholocron/misc-utils": "^1.16.0",
56
- "@theholocron/cli": "5.0.0-alpha.195"
56
+ "@theholocron/cli": "5.0.0-alpha.196"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">=22"