@theholocron/holocron-plugin-discord 5.0.0-alpha.193 → 5.0.0-alpha.194

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.
Files changed (2) hide show
  1. package/dist/index.mjs +10 -4
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -317,11 +317,11 @@ var DiscordNotifications = class DiscordNotifications {
317
317
  }
318
318
  /** Turning community on or off needs Administrator, which is more than the bot should keep. */
319
319
  async communityHint(err, applied, turningOn) {
320
- if (!DiscordNotifications.missingPermissions(err)) return err;
320
+ if (!(err instanceof ProviderApiError && err.status === 403)) return err;
321
321
  const link = await this.inviteOrNothing(["Administrator"]);
322
322
  const byHand = turningOn ? "turn them on once in Discord (Server Settings → Enable Community; setup then keeps everything else in line)" : "turn them off once in Discord (Server Settings → Community Settings → Disable Community)";
323
323
  const viaBot = link ? `give Holonet Administrator for one run and take it away again afterwards: ${link}` : "re-invite Holonet with the Administrator permission for one run, and take it away again afterwards";
324
- return new Error(`${appliedPrefix(applied)}turning community features ${turningOn ? "on" : "off"} needs the Administrator permission, which Holonet does not have. Either ${byHand}, or ${viaBot}`, { cause: err });
324
+ return new Error(`${appliedPrefix(applied)}turning community features ${turningOn ? "on" : "off"} was refused (Discord said: ${String(err.details).slice(0, 120)}), which means Holonet lacks the Administrator permission it needs for that. Either ${byHand}, or ${viaBot}. If Holonet already has Administrator, check that it is still in the server`, { cause: err });
325
325
  }
326
326
  /** A 403 on a server edit becomes the explanation and the invite link; anything else is passed on as it is. */
327
327
  async manageServerHint(err) {
@@ -381,13 +381,18 @@ var DiscordNotifications = class DiscordNotifications {
381
381
  };
382
382
  const toggle = async () => {
383
383
  if (!toggleCommunity) return;
384
- const fresh = (await bot.guilds.get(this.guild())).features ?? [];
384
+ const freshGuild = await bot.guilds.get(this.guild());
385
+ const fresh = freshGuild.features ?? [];
385
386
  const wanted = settings.community ? [.../* @__PURE__ */ new Set([...fresh, "COMMUNITY"])] : fresh.filter((f) => f !== "COMMUNITY");
387
+ const turningOn = settings.community === true;
388
+ const rulesSent = turningOn ? (settings.rulesChannel ? idOf(settings.rulesChannel) : freshGuild.rules_channel_id) || void 0 : void 0;
389
+ const updatesSent = turningOn ? (updatesWithCommunity ? updatesId : freshGuild.public_updates_channel_id) || void 0 : void 0;
386
390
  let after;
387
391
  try {
388
392
  after = await bot.guilds.modify(this.guild(), {
389
393
  features: wanted,
390
- ...updatesWithCommunity ? { public_updates_channel_id: updatesId } : {}
394
+ ...rulesSent ? { rules_channel_id: rulesSent } : {},
395
+ ...updatesSent ? { public_updates_channel_id: updatesSent } : {}
391
396
  });
392
397
  } catch (err) {
393
398
  throw await this.communityHint(err, updated, settings.community === true);
@@ -398,6 +403,7 @@ var DiscordNotifications = class DiscordNotifications {
398
403
  const lost = fresh.filter((f) => f !== "COMMUNITY" && !nowFeatures.includes(f));
399
404
  if (lost.length > 0) throw new Error(`turned community on, but the server no longer has ${lost.join(", ")} -- another admin may have changed its features at the same time; check Server Settings and re-run`);
400
405
  }
406
+ if (settings.rulesChannel && rulesSent && after.rules_channel_id !== rulesSent) throw new Error(`${appliedPrefix(updated)}turned community on, but the server did not keep ${settings.rulesChannel} as its rules channel`);
401
407
  if (updatesWithCommunity && after.public_updates_channel_id !== updatesId) throw new Error(`${appliedPrefix(updated)}turned community on, but the server did not keep ${settings.updatesChannel} as its updates channel`);
402
408
  if (updatesWithCommunity && updatesChanged) updated.push("updatesChannel");
403
409
  updated.push("community");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-discord",
3
- "version": "5.0.0-alpha.193",
3
+ "version": "5.0.0-alpha.194",
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.193"
51
+ "@theholocron/cli": "5.0.0-alpha.194"
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.193"
56
+ "@theholocron/cli": "5.0.0-alpha.194"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">=22"