@theholocron/holocron-plugin-discord 5.0.0-alpha.192 → 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.
- package/dist/index.mjs +25 -5
- 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 (!
|
|
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"}
|
|
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) {
|
|
@@ -352,11 +352,19 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
352
352
|
set("contentFilter", "explicit_content_filter", s_(settings.contentFilter, FILTER), guild.explicit_content_filter);
|
|
353
353
|
set("systemChannel", "system_channel_id", settings.systemChannel && idOf(settings.systemChannel), guild.system_channel_id);
|
|
354
354
|
set("rulesChannel", "rules_channel_id", settings.rulesChannel && idOf(settings.rulesChannel), guild.rules_channel_id);
|
|
355
|
-
|
|
355
|
+
const updatesId = settings.updatesChannel ? idOf(settings.updatesChannel) : void 0;
|
|
356
|
+
const updatesChanged = updatesId !== void 0 && updatesId !== guild.public_updates_channel_id;
|
|
356
357
|
set("description", "description", settings.description, guild.description ?? "");
|
|
357
358
|
set("locale", "preferred_locale", settings.locale, guild.preferred_locale);
|
|
358
359
|
const community = (guild.features ?? []).includes("COMMUNITY");
|
|
359
360
|
const toggleCommunity = settings.community !== void 0 && settings.community !== community;
|
|
361
|
+
const updatesWithCommunity = updatesId !== void 0 && toggleCommunity && settings.community === true;
|
|
362
|
+
const communityAfter = toggleCommunity ? settings.community === true : community;
|
|
363
|
+
if (updatesChanged && !updatesWithCommunity) {
|
|
364
|
+
if (!communityAfter) throw new Error(`\`updatesChannel\` can only be set while community features are on, but they are off and the layout does not turn them on -- add \`community: true\` or remove \`updatesChannel\``);
|
|
365
|
+
patch.public_updates_channel_id = updatesId;
|
|
366
|
+
updated.push("updatesChannel");
|
|
367
|
+
}
|
|
360
368
|
const ordinary = async () => {
|
|
361
369
|
if (Object.keys(patch).length === 0) return;
|
|
362
370
|
let after;
|
|
@@ -373,11 +381,19 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
373
381
|
};
|
|
374
382
|
const toggle = async () => {
|
|
375
383
|
if (!toggleCommunity) return;
|
|
376
|
-
const
|
|
384
|
+
const freshGuild = await bot.guilds.get(this.guild());
|
|
385
|
+
const fresh = freshGuild.features ?? [];
|
|
377
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;
|
|
378
390
|
let after;
|
|
379
391
|
try {
|
|
380
|
-
after = await bot.guilds.modify(this.guild(), {
|
|
392
|
+
after = await bot.guilds.modify(this.guild(), {
|
|
393
|
+
features: wanted,
|
|
394
|
+
...rulesSent ? { rules_channel_id: rulesSent } : {},
|
|
395
|
+
...updatesSent ? { public_updates_channel_id: updatesSent } : {}
|
|
396
|
+
});
|
|
381
397
|
} catch (err) {
|
|
382
398
|
throw await this.communityHint(err, updated, settings.community === true);
|
|
383
399
|
}
|
|
@@ -387,6 +403,9 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
387
403
|
const lost = fresh.filter((f) => f !== "COMMUNITY" && !nowFeatures.includes(f));
|
|
388
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`);
|
|
389
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`);
|
|
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`);
|
|
408
|
+
if (updatesWithCommunity && updatesChanged) updated.push("updatesChannel");
|
|
390
409
|
updated.push("community");
|
|
391
410
|
};
|
|
392
411
|
if (toggleCommunity && settings.community === false) {
|
|
@@ -408,6 +427,7 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
408
427
|
const value = server?.[field];
|
|
409
428
|
if (value !== void 0 && !Object.hasOwn(map, value)) return `server: \`${field}\` is ${JSON.stringify(value)}; use one of ${Object.keys(map).join(", ")}`;
|
|
410
429
|
}
|
|
430
|
+
if (server?.community === false && server.updatesChannel !== void 0) return "server: `updatesChannel` can only be set while community features are on; remove it or set `community: true`";
|
|
411
431
|
if (server?.locale !== void 0 && !LOCALES.has(server.locale)) return `server: \`locale\` ${JSON.stringify(server.locale)} is not a locale Discord accepts (for example en-US, en-GB, de, fr)`;
|
|
412
432
|
if (server?.community === true && (server.verification === void 0 || server.verification === "none")) return "server: community features need `verification` of at least `low`";
|
|
413
433
|
if (server?.community === true && server.contentFilter !== "all") return "server: community features need `contentFilter: \"all\"`";
|
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.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.
|
|
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.
|
|
56
|
+
"@theholocron/cli": "5.0.0-alpha.194"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=22"
|