@theholocron/holocron-plugin-discord 5.0.0-alpha.206 → 5.0.0-alpha.208
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 +9 -2
- package/dist/index.mjs +48 -8
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -66,7 +66,7 @@ declare class DiscordNotifications implements Notifications {
|
|
|
66
66
|
* the layout, not with the server.
|
|
67
67
|
*/
|
|
68
68
|
inspect(layout: NotificationsLayout): Promise<ServerInspection>;
|
|
69
|
-
/** What the bot keeps: the usual set, and
|
|
69
|
+
/** What the bot keeps: the usual set, and Pin Messages when the layout pins messages. */
|
|
70
70
|
private needs;
|
|
71
71
|
/** Where to re-invite the bot so its role holds what `setup` needs. Re-authorising updates the role in place. */
|
|
72
72
|
private inviteUrl;
|
|
@@ -87,7 +87,14 @@ declare class DiscordNotifications implements Notifications {
|
|
|
87
87
|
ensureServer(settings: NotificationsServerLayout): Promise<{
|
|
88
88
|
updated: string[];
|
|
89
89
|
}>;
|
|
90
|
+
/** What the bot's roles give it server-wide (the owner holds every permission), before any channel overwrite. */
|
|
91
|
+
private serverPermissions;
|
|
90
92
|
holdsPermission(permission: string): Promise<boolean>;
|
|
93
|
+
/**
|
|
94
|
+
* Whether a channel's own overwrites take a permission away from a bot whose roles grant it, in the order Discord
|
|
95
|
+
* applies them: @everyone, then the bot's roles, then the bot itself. Read fresh, since a person may have just edited them.
|
|
96
|
+
*/
|
|
97
|
+
private channelDenies;
|
|
91
98
|
/** The messages this bot posted in a channel, pinned or not, among the channel's last hundred. */
|
|
92
99
|
private ownMessages;
|
|
93
100
|
/** The layout's messages grouped by channel, in the order the channels first appear. */
|
|
@@ -103,7 +110,7 @@ declare class DiscordNotifications implements Notifications {
|
|
|
103
110
|
ensurePinned(pinned: NotificationsPinnedLayout[]): Promise<{
|
|
104
111
|
updated: string[];
|
|
105
112
|
}>;
|
|
106
|
-
/** A 403 on pinning becomes the missing permission and a link that grants it. */
|
|
113
|
+
/** A 403 on pinning becomes the missing permission and a link that grants it, which `setup` can walk a person through. */
|
|
107
114
|
private pinHint;
|
|
108
115
|
/** A 403 on the welcome screen or onboarding becomes the likely reason; anything else is passed on. */
|
|
109
116
|
private static communityFeatureHint;
|
package/dist/index.mjs
CHANGED
|
@@ -448,9 +448,9 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
448
448
|
...rolesError ? { rolesError } : {}
|
|
449
449
|
};
|
|
450
450
|
}
|
|
451
|
-
/** What the bot keeps: the usual set, and
|
|
451
|
+
/** What the bot keeps: the usual set, and Pin Messages when the layout pins messages. */
|
|
452
452
|
needs() {
|
|
453
|
-
return this.opts.layout?.pinned?.length ? [...BOT_NEEDS, "
|
|
453
|
+
return this.opts.layout?.pinned?.length ? [...BOT_NEEDS, "PinMessages"] : BOT_NEEDS;
|
|
454
454
|
}
|
|
455
455
|
/** Where to re-invite the bot so its role holds what `setup` needs. Re-authorising updates the role in place. */
|
|
456
456
|
async inviteUrl(names = this.needs()) {
|
|
@@ -599,19 +599,53 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
599
599
|
}
|
|
600
600
|
return { updated };
|
|
601
601
|
}
|
|
602
|
-
|
|
602
|
+
/** What the bot's roles give it server-wide (the owner holds every permission), before any channel overwrite. */
|
|
603
|
+
async serverPermissions() {
|
|
603
604
|
const bot = this.bot();
|
|
604
605
|
const me = await this.botId();
|
|
605
|
-
if ((await this.serverOwner()).isBot) return
|
|
606
|
+
if ((await this.serverOwner()).isBot) return {
|
|
607
|
+
owner: true,
|
|
608
|
+
bits: 0n,
|
|
609
|
+
held: /* @__PURE__ */ new Set(),
|
|
610
|
+
me
|
|
611
|
+
};
|
|
606
612
|
const [member, roles] = await Promise.all([bot.guilds.member(this.guild(), me), bot.guilds.roles(this.guild())]);
|
|
607
613
|
const held = /* @__PURE__ */ new Set([this.guild(), ...member.roles]);
|
|
608
|
-
|
|
614
|
+
return {
|
|
615
|
+
owner: false,
|
|
616
|
+
bits: roles.filter((r) => held.has(r.id)).reduce((all, r) => all | BigInt(r.permissions ?? "0"), 0n),
|
|
617
|
+
held,
|
|
618
|
+
me
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
async holdsPermission(permission) {
|
|
622
|
+
const { owner, bits } = await this.serverPermissions();
|
|
623
|
+
if (owner) return true;
|
|
609
624
|
const has = (name) => {
|
|
610
625
|
const bit = BigInt(permissions([name]));
|
|
611
626
|
return (bits & bit) === bit;
|
|
612
627
|
};
|
|
613
628
|
return has("Administrator") || has(permission);
|
|
614
629
|
}
|
|
630
|
+
/**
|
|
631
|
+
* Whether a channel's own overwrites take a permission away from a bot whose roles grant it, in the order Discord
|
|
632
|
+
* applies them: @everyone, then the bot's roles, then the bot itself. Read fresh, since a person may have just edited them.
|
|
633
|
+
*/
|
|
634
|
+
async channelDenies(permission, channelId) {
|
|
635
|
+
const { owner, bits, held, me } = await this.serverPermissions();
|
|
636
|
+
const bit = BigInt(permissions([permission]));
|
|
637
|
+
if (owner || (bits & BigInt(permissions(["Administrator"]))) !== 0n || (bits & bit) !== bit) return false;
|
|
638
|
+
const list = (await this.bot().guilds.channels(this.guild())).find((c) => c.id === channelId)?.permission_overwrites ?? [];
|
|
639
|
+
const apply = (now, found) => {
|
|
640
|
+
const deny = found.reduce((all, o) => all | BigInt(o.deny), 0n);
|
|
641
|
+
const allow = found.reduce((all, o) => all | BigInt(o.allow), 0n);
|
|
642
|
+
return now & ~deny | allow;
|
|
643
|
+
};
|
|
644
|
+
let now = apply(bits, list.filter((o) => o.id === this.guild()));
|
|
645
|
+
now = apply(now, list.filter((o) => o.type === 0 && o.id !== this.guild() && held.has(o.id)));
|
|
646
|
+
now = apply(now, list.filter((o) => o.type === 1 && o.id === me));
|
|
647
|
+
return (now & bit) !== bit;
|
|
648
|
+
}
|
|
615
649
|
/** The messages this bot posted in a channel, pinned or not, among the channel's last hundred. */
|
|
616
650
|
async ownMessages(channelId) {
|
|
617
651
|
const me = await this.botId();
|
|
@@ -706,11 +740,17 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
706
740
|
}
|
|
707
741
|
return { updated };
|
|
708
742
|
}
|
|
709
|
-
/** A 403 on pinning becomes the missing permission and a link that grants it. */
|
|
743
|
+
/** A 403 on pinning becomes the missing permission and a link that grants it, which `setup` can walk a person through. */
|
|
710
744
|
async pinHint(err, channel) {
|
|
711
745
|
if (!DiscordNotifications.missingPermissions(err)) return err;
|
|
712
|
-
|
|
713
|
-
|
|
746
|
+
if (await this.channelDenies("PinMessages", DiscordNotifications.pickChannelId(await this.channelList(), channel, "pinned messages")).catch(() => false)) return new Error(`the bot could not pin the message in #${channel}: its role has Pin Messages, but the channel's permissions take it away. Remove that override under Edit Channel → Permissions, then run setup again`, { cause: err });
|
|
747
|
+
const link = await this.inviteOrNothing([...BOT_NEEDS, "PinMessages"]);
|
|
748
|
+
return new ElevationRequiredError(`the bot could not pin the message in #${channel}: its role lacks Pin Messages. Re-invite it with that permission${link ? ` (this updates its role in place): ${link}` : ""}`, {
|
|
749
|
+
permission: "PinMessages",
|
|
750
|
+
label: "Pin Messages",
|
|
751
|
+
keep: true,
|
|
752
|
+
...link ? { grantUrl: link } : {}
|
|
753
|
+
}, { cause: err });
|
|
714
754
|
}
|
|
715
755
|
/** A 403 on the welcome screen or onboarding becomes the likely reason; anything else is passed on. */
|
|
716
756
|
static communityFeatureHint(err, what) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-discord",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.208",
|
|
4
4
|
"description": "Holocron plugin for Discord. Implements the notifications capability via Discord incoming webhooks.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"discord",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@theholocron/discord-client": "^1.
|
|
33
|
+
"@theholocron/discord-client": "^1.50.0",
|
|
34
34
|
"@theholocron/eslint-config": "^8.8.2",
|
|
35
35
|
"@theholocron/http-client": "^1.43.1",
|
|
36
36
|
"@theholocron/misc-utils": "^1.16.0",
|
|
@@ -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.
|
|
51
|
+
"@theholocron/cli": "5.0.0-alpha.208"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@theholocron/discord-client": "^1.
|
|
54
|
+
"@theholocron/discord-client": "^1.50.0",
|
|
55
55
|
"@theholocron/misc-utils": "^1.16.0",
|
|
56
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
56
|
+
"@theholocron/cli": "5.0.0-alpha.208"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=22"
|