@theholocron/holocron-plugin-discord 5.0.0-alpha.358 → 5.0.0-alpha.359

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
@@ -79,7 +79,8 @@ export declare class DiscordNotifications implements Notifications {
79
79
  inspect(layout: NotificationsLayout): Promise<ServerInspection>;
80
80
  /**
81
81
  * What the bot keeps: the usual set, Pin Messages when the layout pins messages, and Manage Threads when it
82
- * declares a forum (a post's tags are applied by the bot, and a moderated tag only by someone who can manage threads).
82
+ * declares a forum (a post's tags are applied by the bot, and a moderated tag only by someone who can manage threads),
83
+ * and Add Reactions when a forum has `starterReactions` (without it the bot skips them and the post still gets made).
83
84
  */
84
85
  private needs;
85
86
  /** Where to re-invite the bot so its role holds what `setup` needs. Re-authorising updates the role in place. */
@@ -113,6 +114,12 @@ export declare class DiscordNotifications implements Notifications {
113
114
  }>;
114
115
  /** What the bot's roles give it server-wide (the owner holds every permission), before any channel overwrite. */
115
116
  private serverPermissions;
117
+ /**
118
+ * The permissions `needs()` lists that the bot's roles do not give it server-wide, in plain words ("Manage Threads"),
119
+ * with the invite link that asks for them again when some are missing. The owner and an Administrator hold every
120
+ * permission. Channel overwrites are not looked at: the forum's own check does that.
121
+ */
122
+ private missingBotPermissions;
116
123
  holdsPermission(permission: string): Promise<boolean>;
117
124
  /**
118
125
  * What a member holding `bits` through the roles in `held` has in a channel, in the order Discord applies the
package/dist/index.mjs CHANGED
@@ -763,9 +763,18 @@ var DiscordNotifications = class DiscordNotifications {
763
763
  });
764
764
  const categoryAccess = {};
765
765
  for (const c of channels.filter((c) => c.type === ChannelType.Category)) categoryAccess[c.name] = this.accessOf(c.permission_overwrites, roleName);
766
+ let botPermissions;
767
+ let botPermissionsError;
768
+ try {
769
+ botPermissions = await this.missingBotPermissions();
770
+ } catch (err) {
771
+ botPermissionsError = reason(err);
772
+ }
766
773
  return {
767
774
  categories: [...categoryName.values()],
768
775
  categoryAccess,
776
+ ...botPermissions ? { botPermissions } : {},
777
+ ...botPermissionsError ? { botPermissionsError } : {},
769
778
  ...server ? { server } : {},
770
779
  ...serverError ? { serverError } : {},
771
780
  ...welcome ? { welcome } : {},
@@ -785,14 +794,18 @@ var DiscordNotifications = class DiscordNotifications {
785
794
  }
786
795
  /**
787
796
  * What the bot keeps: the usual set, Pin Messages when the layout pins messages, and Manage Threads when it
788
- * declares a forum (a post's tags are applied by the bot, and a moderated tag only by someone who can manage threads).
797
+ * declares a forum (a post's tags are applied by the bot, and a moderated tag only by someone who can manage threads),
798
+ * and Add Reactions when a forum has `starterReactions` (without it the bot skips them and the post still gets made).
789
799
  */
790
800
  needs() {
791
- const forum = (this.opts.layout?.categories ?? []).some((c) => (c.channels ?? []).some((ch) => ch.kind === "forum"));
801
+ const channels = (this.opts.layout?.categories ?? []).flatMap((c) => c.channels ?? []);
802
+ const forum = channels.some((ch) => ch.kind === "forum");
803
+ const reacts = channels.some((ch) => (ch.starterReactions ?? []).length > 0);
792
804
  return [
793
805
  ...BOT_NEEDS,
794
806
  ...this.opts.layout?.pinned?.length ? ["PinMessages"] : [],
795
- ...forum ? ["ManageThreads"] : []
807
+ ...forum ? ["ManageThreads"] : [],
808
+ ...reacts ? ["AddReactions"] : []
796
809
  ];
797
810
  }
798
811
  /** Where to re-invite the bot so its role holds what `setup` needs. Re-authorising updates the role in place. */
@@ -975,6 +988,24 @@ var DiscordNotifications = class DiscordNotifications {
975
988
  me
976
989
  };
977
990
  }
991
+ /**
992
+ * The permissions `needs()` lists that the bot's roles do not give it server-wide, in plain words ("Manage Threads"),
993
+ * with the invite link that asks for them again when some are missing. The owner and an Administrator hold every
994
+ * permission. Channel overwrites are not looked at: the forum's own check does that.
995
+ */
996
+ async missingBotPermissions() {
997
+ const { owner, bits } = await this.serverPermissions();
998
+ const has = (name) => {
999
+ const bit = BigInt(permissions([name]));
1000
+ return (bits & bit) === bit;
1001
+ };
1002
+ const missing = owner || has("Administrator") ? [] : [...new Set(this.needs())].filter((n) => !has(n));
1003
+ if (missing.length === 0) return { missing: [] };
1004
+ return {
1005
+ missing: missing.map((n) => n.replace(/([a-z])([A-Z])/g, "$1 $2")),
1006
+ inviteUrl: await this.inviteUrl()
1007
+ };
1008
+ }
978
1009
  async holdsPermission(permission) {
979
1010
  const { owner, bits } = await this.serverPermissions();
980
1011
  if (owner) return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-discord",
3
- "version": "5.0.0-alpha.358",
3
+ "version": "5.0.0-alpha.359",
4
4
  "description": "Holocron plugin for Discord. Implements the notifications capability via Discord incoming webhooks.",
5
5
  "keywords": [
6
6
  "discord",
@@ -41,19 +41,19 @@
41
41
  "tsx": "4.23.15",
42
42
  "typescript": "^5.9.3",
43
43
  "vitest": "^5.0.5",
44
- "@theholocron/cli": "5.0.0-alpha.358",
44
+ "@theholocron/cli": "5.0.0-alpha.359",
45
45
  "@theholocron/discord-client": "^1.58.0-alpha.13",
46
- "@theholocron/misc-utils": "^1.17.0-alpha.1",
47
- "@theholocron/tsconfig": "^8.9.0-alpha.9",
48
46
  "@theholocron/eslint-config": "^8.9.0-alpha.9",
49
- "@theholocron/vitest-config": "^8.9.0-alpha.9",
47
+ "@theholocron/http-client": "^1.58.0-alpha.13",
48
+ "@theholocron/misc-utils": "^1.17.0-alpha.1",
50
49
  "@theholocron/tsdown-config": "^8.9.0-alpha.9",
51
- "@theholocron/http-client": "^1.58.0-alpha.13"
50
+ "@theholocron/tsconfig": "^8.9.0-alpha.9",
51
+ "@theholocron/vitest-config": "^8.9.0-alpha.9"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@theholocron/discord-client": "^1.50.0",
55
55
  "@theholocron/misc-utils": "^1.16.0",
56
- "@theholocron/cli": "5.0.0-alpha.358"
56
+ "@theholocron/cli": "5.0.0-alpha.359"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">=22"