@theholocron/holocron-plugin-discord 5.0.0-alpha.189 → 5.0.0-alpha.190
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.mjs +49 -15
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -29,13 +29,18 @@ function colorToHex(color) {
|
|
|
29
29
|
function reason(err) {
|
|
30
30
|
return err instanceof ProviderApiError && err.details ? `${errorMessage(err)}: ${String(err.details).slice(0, 200)}` : errorMessage(err);
|
|
31
31
|
}
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
/**
|
|
33
|
+
* What @everyone loses when a channel is read-only. Only sending: Discord refuses (403) any change to the
|
|
34
|
+
* thread permissions on an existing text channel from a bot whose own role lacks them, and Holonet's
|
|
35
|
+
* does. Members can therefore still start threads in a read-only channel until the bot is given those
|
|
36
|
+
* permissions; see {@link THREAD_BITS} for how channels that already carry them are read.
|
|
37
|
+
*/
|
|
38
|
+
const POST = ["SendMessages"];
|
|
39
|
+
const THREAD_MASK = ~BigInt(permissions([
|
|
35
40
|
"SendMessagesInThreads",
|
|
36
41
|
"CreatePublicThreads",
|
|
37
42
|
"CreatePrivateThreads"
|
|
38
|
-
];
|
|
43
|
+
]));
|
|
39
44
|
/** What the bot keeps in a channel it has locked down, so it can still manage it and post. */
|
|
40
45
|
const BOT_KEEPS = [
|
|
41
46
|
"ViewChannel",
|
|
@@ -44,9 +49,41 @@ const BOT_KEEPS = [
|
|
|
44
49
|
"ManageChannels",
|
|
45
50
|
"ManageWebhooks"
|
|
46
51
|
];
|
|
47
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Overwrites as a comparable set: order and the shape of the array do not matter, and the thread
|
|
54
|
+
* permissions are left out (setup does not manage them, so their presence is not a difference).
|
|
55
|
+
*/
|
|
48
56
|
function overwriteKey(list) {
|
|
49
|
-
return (list ?? []).map((o) =>
|
|
57
|
+
return (list ?? []).map((o) => ({
|
|
58
|
+
...o,
|
|
59
|
+
allow: BigInt(o.allow) & THREAD_MASK,
|
|
60
|
+
deny: BigInt(o.deny) & THREAD_MASK
|
|
61
|
+
})).filter((o) => o.allow !== 0n || o.deny !== 0n).map((o) => `${o.id}:${o.type}:${o.allow}:${o.deny}`).sort().join("|");
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Desired overwrites with the thread permissions of the existing ones laid back in. Discord refuses
|
|
65
|
+
* any change to those from this bot, so a replacement list must carry them over untouched or the
|
|
66
|
+
* whole edit is rejected, even when it changes nothing but what we do manage.
|
|
67
|
+
*/
|
|
68
|
+
function keepThreadBits(desired, existing) {
|
|
69
|
+
const threads = ~THREAD_MASK;
|
|
70
|
+
const merged = desired.map((o) => ({ ...o }));
|
|
71
|
+
for (const old of existing ?? []) {
|
|
72
|
+
const allow = BigInt(old.allow) & threads;
|
|
73
|
+
const deny = BigInt(old.deny) & threads;
|
|
74
|
+
if (allow === 0n && deny === 0n) continue;
|
|
75
|
+
const same = merged.find((o) => o.id === old.id && o.type === old.type);
|
|
76
|
+
if (same) {
|
|
77
|
+
same.allow = (BigInt(same.allow) | allow).toString();
|
|
78
|
+
same.deny = (BigInt(same.deny) | deny).toString();
|
|
79
|
+
} else merged.push({
|
|
80
|
+
id: old.id,
|
|
81
|
+
type: old.type,
|
|
82
|
+
allow: allow.toString(),
|
|
83
|
+
deny: deny.toString()
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return merged;
|
|
50
87
|
}
|
|
51
88
|
var DiscordNotifications = class DiscordNotifications {
|
|
52
89
|
client;
|
|
@@ -214,11 +251,8 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
214
251
|
accessOf(overwrites, roleName) {
|
|
215
252
|
const list = overwrites ?? [];
|
|
216
253
|
const managed = permissions(["ViewChannel", ...POST]);
|
|
217
|
-
const
|
|
218
|
-
const
|
|
219
|
-
const have = POST.filter((b) => permissionNames(bits).includes(b)).length;
|
|
220
|
-
return have === 0 ? "none" : have === POST.length ? "all" : "some";
|
|
221
|
-
};
|
|
254
|
+
const unthreaded = (bits) => BigInt(bits) & THREAD_MASK;
|
|
255
|
+
const within = (bits) => (unthreaded(bits) & ~BigInt(managed)) === 0n;
|
|
222
256
|
const botSignature = permissions(BOT_KEEPS);
|
|
223
257
|
let everyone;
|
|
224
258
|
const roles = [];
|
|
@@ -226,8 +260,8 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
226
260
|
if (o.allow !== botSignature || o.deny !== "0") return "custom";
|
|
227
261
|
} else if (o.id === this.guild()) everyone = o;
|
|
228
262
|
else roles.push(o);
|
|
229
|
-
if (everyone && (everyone.allow !==
|
|
230
|
-
for (const o of roles) if (o.deny !==
|
|
263
|
+
if (everyone && (unthreaded(everyone.allow) !== 0n || !within(everyone.deny))) return "custom";
|
|
264
|
+
for (const o of roles) if (unthreaded(o.deny) !== 0n || !within(o.allow)) return "custom";
|
|
231
265
|
const denied = (bit) => everyone !== void 0 && permissionNames(everyone.deny).includes(bit);
|
|
232
266
|
const names = (bit) => roles.filter((o) => permissionNames(o.allow).includes(bit)).map((o) => roleName(o.id));
|
|
233
267
|
return {
|
|
@@ -288,7 +322,7 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
288
322
|
const overwrites = opts.access ? await this.overwritesFor(opts.access) : void 0;
|
|
289
323
|
if (existing) {
|
|
290
324
|
if (overwrites && overwriteKey(existing.permission_overwrites) !== overwriteKey(overwrites)) {
|
|
291
|
-
await this.modifyChannel(existing, { permission_overwrites: overwrites });
|
|
325
|
+
await this.modifyChannel(existing, { permission_overwrites: keepThreadBits(overwrites, existing.permission_overwrites) });
|
|
292
326
|
return {
|
|
293
327
|
id: existing.id,
|
|
294
328
|
created: false,
|
|
@@ -355,7 +389,7 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
355
389
|
updated.push("topic");
|
|
356
390
|
}
|
|
357
391
|
if (overwrites && overwriteKey(existing.permission_overwrites) !== overwriteKey(overwrites)) {
|
|
358
|
-
patch.permission_overwrites = overwrites;
|
|
392
|
+
patch.permission_overwrites = keepThreadBits(overwrites, existing.permission_overwrites);
|
|
359
393
|
updated.push("access");
|
|
360
394
|
}
|
|
361
395
|
if (updated.length > 0) await this.modifyChannel(existing, patch);
|
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.190",
|
|
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.
|
|
51
|
+
"@theholocron/cli": "5.0.0-alpha.190"
|
|
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.
|
|
56
|
+
"@theholocron/cli": "5.0.0-alpha.190"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=22"
|