@theholocron/holocron-plugin-discord 5.0.0-alpha.197 → 5.0.0-alpha.199
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 +7 -1
- package/dist/index.mjs +157 -0
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthError, EnsureWebhookResult, EnsuredResource, Notifications, NotificationsAccess, NotificationsLayout, NotificationsOnboardingLayout, NotificationsServerLayout, NotificationsWelcomeLayout, ResolveTokenInput, ServerInspection, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
|
|
1
|
+
import { AuthError, EnsureWebhookResult, EnsuredResource, Notifications, NotificationsAccess, NotificationsApplicationLayout, NotificationsEveryoneLayout, NotificationsLayout, NotificationsOnboardingLayout, NotificationsServerLayout, NotificationsWelcomeLayout, ResolveTokenInput, ServerInspection, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
|
|
2
2
|
import { DiscordBotClient, DiscordClient, DiscordClientOptions, DiscordWebhookInfo, createDiscordClient, parseWebhookUrl } from "@theholocron/discord-client";
|
|
3
3
|
//#region src/auth.d.ts
|
|
4
4
|
declare const resolveToken: (input?: ResolveTokenInput) => string;
|
|
@@ -85,6 +85,12 @@ declare class DiscordNotifications implements Notifications {
|
|
|
85
85
|
ensureOnboarding(onboarding: NotificationsOnboardingLayout): Promise<{
|
|
86
86
|
updated: string[];
|
|
87
87
|
}>;
|
|
88
|
+
ensureEveryone(everyone: NotificationsEveryoneLayout): Promise<{
|
|
89
|
+
updated: string[];
|
|
90
|
+
}>;
|
|
91
|
+
ensureApplication(app: NotificationsApplicationLayout): Promise<{
|
|
92
|
+
updated: string[];
|
|
93
|
+
}>;
|
|
88
94
|
validateLayout(layout: NotificationsLayout): string | undefined;
|
|
89
95
|
private botUser?;
|
|
90
96
|
private botId;
|
package/dist/index.mjs
CHANGED
|
@@ -47,6 +47,35 @@ const BOT_NEEDS = [
|
|
|
47
47
|
"CreatePrivateThreads",
|
|
48
48
|
"SendMessagesInThreads"
|
|
49
49
|
];
|
|
50
|
+
/** The OAuth2 scopes Discord offers an application, as its own application page lists them. Exact, lower-case. */
|
|
51
|
+
const SCOPES = /* @__PURE__ */ new Set([
|
|
52
|
+
"applications.builds.read",
|
|
53
|
+
"applications.commands",
|
|
54
|
+
"applications.commands.permissions.update",
|
|
55
|
+
"applications.entitlements",
|
|
56
|
+
"applications.store.update",
|
|
57
|
+
"bot",
|
|
58
|
+
"connections",
|
|
59
|
+
"email",
|
|
60
|
+
"gdm.join",
|
|
61
|
+
"guilds",
|
|
62
|
+
"guilds.join",
|
|
63
|
+
"guilds.members.read",
|
|
64
|
+
"identify",
|
|
65
|
+
"messages.read",
|
|
66
|
+
"openid",
|
|
67
|
+
"role_connections.write",
|
|
68
|
+
"rpc",
|
|
69
|
+
"rpc.activities.write",
|
|
70
|
+
"rpc.notifications.read",
|
|
71
|
+
"rpc.screenshare.read",
|
|
72
|
+
"rpc.screenshare.write",
|
|
73
|
+
"rpc.video.read",
|
|
74
|
+
"rpc.video.write",
|
|
75
|
+
"rpc.voice.read",
|
|
76
|
+
"rpc.voice.write",
|
|
77
|
+
"webhook.incoming"
|
|
78
|
+
]);
|
|
50
79
|
/** The locales Discord accepts for a server's preferred language. */
|
|
51
80
|
const LOCALES = /* @__PURE__ */ new Set([
|
|
52
81
|
"id",
|
|
@@ -318,6 +347,34 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
318
347
|
} catch (err) {
|
|
319
348
|
onboardingError = reason(err);
|
|
320
349
|
}
|
|
350
|
+
let application;
|
|
351
|
+
let applicationError;
|
|
352
|
+
if (layout.application) try {
|
|
353
|
+
const app = await bot.application.get();
|
|
354
|
+
const install = app.install_params;
|
|
355
|
+
application = {
|
|
356
|
+
...app.description ? { description: app.description } : {},
|
|
357
|
+
tags: app.tags ?? [],
|
|
358
|
+
...install ? { install: {
|
|
359
|
+
scopes: install.scopes,
|
|
360
|
+
permissions: permissionNames(install.permissions)
|
|
361
|
+
} } : {},
|
|
362
|
+
...app.terms_of_service_url ? { termsUrl: app.terms_of_service_url } : {},
|
|
363
|
+
...app.privacy_policy_url ? { privacyUrl: app.privacy_policy_url } : {},
|
|
364
|
+
...app.role_connections_verification_url ? { roleConnectionsUrl: app.role_connections_verification_url } : {}
|
|
365
|
+
};
|
|
366
|
+
} catch (err) {
|
|
367
|
+
applicationError = reason(err);
|
|
368
|
+
}
|
|
369
|
+
let everyone;
|
|
370
|
+
let everyoneError;
|
|
371
|
+
if (layout.everyone) try {
|
|
372
|
+
const role = (await bot.guilds.roles(this.guild())).find((r) => r.id === this.guild());
|
|
373
|
+
if (role?.permissions === void 0) throw new Error("the server has no @everyone role to read");
|
|
374
|
+
everyone = { permissions: permissionNames(role.permissions) };
|
|
375
|
+
} catch (err) {
|
|
376
|
+
everyoneError = reason(err);
|
|
377
|
+
}
|
|
321
378
|
const roleName = (id) => roles.find((r) => r.id === id)?.name ?? id;
|
|
322
379
|
found.forEach((entry, i) => {
|
|
323
380
|
entry.access = this.accessOf(text[i].permission_overwrites, roleName);
|
|
@@ -333,6 +390,10 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
333
390
|
...welcomeError ? { welcomeError } : {},
|
|
334
391
|
...onboarding ? { onboarding } : {},
|
|
335
392
|
...onboardingError ? { onboardingError } : {},
|
|
393
|
+
...application ? { application } : {},
|
|
394
|
+
...applicationError ? { applicationError } : {},
|
|
395
|
+
...everyone ? { everyone } : {},
|
|
396
|
+
...everyoneError ? { everyoneError } : {},
|
|
336
397
|
channels: found,
|
|
337
398
|
roles,
|
|
338
399
|
...rolesError ? { rolesError } : {}
|
|
@@ -624,7 +685,103 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
624
685
|
if (after.enabled !== enabled || JSON.stringify([...after.default_channel_ids].sort()) !== JSON.stringify([...defaultChannels].sort()) || DiscordNotifications.onboardingKey(after.prompts) !== DiscordNotifications.onboardingKey(prompts)) throw new Error("sent onboarding but it came back different -- Discord may have refused a part of it");
|
|
625
686
|
return { updated };
|
|
626
687
|
}
|
|
688
|
+
async ensureEveryone(everyone) {
|
|
689
|
+
const bot = this.bot();
|
|
690
|
+
const role = (await bot.guilds.roles(this.guild())).find((r) => r.id === this.guild());
|
|
691
|
+
if (role?.permissions === void 0) throw new Error("the server has no @everyone role to change");
|
|
692
|
+
const bit = (name) => BigInt(permissions([name]));
|
|
693
|
+
const have = BigInt(role.permissions);
|
|
694
|
+
const allow = everyone.allow ?? [];
|
|
695
|
+
const deny = everyone.deny ?? [];
|
|
696
|
+
const want = allow.reduce((acc, n) => acc | bit(n), have);
|
|
697
|
+
const final = deny.reduce((acc, n) => acc & ~bit(n), want);
|
|
698
|
+
if (final === have) return { updated: [] };
|
|
699
|
+
const updated = [...allow.filter((n) => (have & bit(n)) === 0n), ...deny.filter((n) => (have & bit(n)) !== 0n)];
|
|
700
|
+
this.roleLoad = void 0;
|
|
701
|
+
if ((await bot.guilds.modifyRole(this.guild(), role.id, { permissions: String(final) })).permissions !== String(final)) throw new Error("sent the @everyone permissions but they came back different -- Discord may have refused a part of it");
|
|
702
|
+
return { updated };
|
|
703
|
+
}
|
|
704
|
+
async ensureApplication(app) {
|
|
705
|
+
const bot = this.bot();
|
|
706
|
+
const current = await bot.application.get();
|
|
707
|
+
const set = (list) => JSON.stringify([...new Set(list.map((n) => n.toLowerCase()))].sort());
|
|
708
|
+
const exact = (list) => JSON.stringify([...new Set(list)].sort());
|
|
709
|
+
const urls = [
|
|
710
|
+
["termsUrl", "terms_of_service_url"],
|
|
711
|
+
["privacyUrl", "privacy_policy_url"],
|
|
712
|
+
["roleConnectionsUrl", "role_connections_verification_url"]
|
|
713
|
+
];
|
|
714
|
+
const body = {};
|
|
715
|
+
const updated = [];
|
|
716
|
+
if (app.description !== void 0 && (current.description ?? "") !== app.description) {
|
|
717
|
+
body.description = app.description;
|
|
718
|
+
updated.push("description");
|
|
719
|
+
}
|
|
720
|
+
if (app.tags !== void 0 && set(current.tags ?? []) !== set(app.tags)) {
|
|
721
|
+
body.tags = app.tags;
|
|
722
|
+
updated.push("tags");
|
|
723
|
+
}
|
|
724
|
+
const install = app.install && {
|
|
725
|
+
scopes: app.install.scopes,
|
|
726
|
+
permissions: permissions(app.install.permissions)
|
|
727
|
+
};
|
|
728
|
+
const haveInstall = current.install_params;
|
|
729
|
+
if (install && (!haveInstall || exact(haveInstall.scopes) !== exact(install.scopes) || haveInstall.permissions !== install.permissions)) {
|
|
730
|
+
body.install_params = install;
|
|
731
|
+
updated.push("install");
|
|
732
|
+
}
|
|
733
|
+
for (const [field, key] of urls) if (app[field] !== void 0 && (current[key] ?? "") !== app[field]) {
|
|
734
|
+
body[key] = app[field];
|
|
735
|
+
updated.push(field);
|
|
736
|
+
}
|
|
737
|
+
if (updated.length === 0) return { updated };
|
|
738
|
+
let after;
|
|
739
|
+
try {
|
|
740
|
+
after = await bot.application.modify(body);
|
|
741
|
+
} catch (err) {
|
|
742
|
+
if (err instanceof ProviderApiError && String(err.details).includes("APPLICATION_INSTALL_NEEDS_PUBLIC_INTEGRATION")) throw new Error("Discord only allows an install link on a public application, and this one is private (Public Bot is off). Remove `install` from the layout -- a private bot is invited with a link you build, which `setup` prints when a permission is missing -- or turn on Public Bot in the developer portal, which lets anyone add the bot", { cause: err });
|
|
743
|
+
throw err;
|
|
744
|
+
}
|
|
745
|
+
const stuck = updated.filter((name) => {
|
|
746
|
+
if (name === "description") return (after.description ?? "") !== app.description;
|
|
747
|
+
if (name === "tags") return set(after.tags ?? []) !== set(app.tags);
|
|
748
|
+
if (name === "install") return !after.install_params || exact(after.install_params.scopes) !== exact(install.scopes) || after.install_params.permissions !== install.permissions;
|
|
749
|
+
const key = urls.find(([f]) => f === name)[1];
|
|
750
|
+
return (after[key] ?? "") !== app[name];
|
|
751
|
+
});
|
|
752
|
+
if (stuck.length > 0) throw new Error(`sent ${stuck.join(", ")} but Discord did not keep ${stuck.length === 1 ? "it" : "them"} -- it may not accept that field from a bot, so set it in the developer portal`);
|
|
753
|
+
return { updated };
|
|
754
|
+
}
|
|
627
755
|
validateLayout(layout) {
|
|
756
|
+
const app = layout.application;
|
|
757
|
+
if (app) {
|
|
758
|
+
if (app.description !== void 0 && app.description.length > 400) return `application: \`description\` is ${app.description.length} characters; Discord allows up to 400`;
|
|
759
|
+
if (app.tags !== void 0) {
|
|
760
|
+
if (app.tags.length > 5) return `application: ${app.tags.length} tags; Discord allows up to 5`;
|
|
761
|
+
const long = app.tags.find((t) => t.length > 20);
|
|
762
|
+
if (long !== void 0) return `application: the tag ${JSON.stringify(long)} is over 20 characters`;
|
|
763
|
+
}
|
|
764
|
+
for (const [field, url] of [
|
|
765
|
+
["termsUrl", app.termsUrl],
|
|
766
|
+
["privacyUrl", app.privacyUrl],
|
|
767
|
+
["roleConnectionsUrl", app.roleConnectionsUrl]
|
|
768
|
+
]) if (url !== void 0 && !/^https:\/\//.test(url)) return `application: \`${field}\` ${JSON.stringify(url)} must start with https://`;
|
|
769
|
+
if (app.install) {
|
|
770
|
+
if (app.install.scopes.length === 0) return "application: `install.scopes` is empty; the link needs at least `bot`";
|
|
771
|
+
const unknown = app.install.scopes.find((s) => !SCOPES.has(s));
|
|
772
|
+
if (unknown !== void 0) return `application: \`install.scopes\` has ${JSON.stringify(unknown)}, which is not an OAuth2 scope Discord offers (scopes are lower-case, for example bot, applications.commands)`;
|
|
773
|
+
try {
|
|
774
|
+
permissions(app.install.permissions);
|
|
775
|
+
} catch (err) {
|
|
776
|
+
return `application: \`install.permissions\`: ${errorMessage(err)}`;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
if (layout.everyone) try {
|
|
781
|
+
permissions([...layout.everyone.allow ?? [], ...layout.everyone.deny ?? []]);
|
|
782
|
+
} catch (err) {
|
|
783
|
+
return `everyone: ${errorMessage(err)}`;
|
|
784
|
+
}
|
|
628
785
|
const questions = layout.onboarding?.prompts?.length ?? 0;
|
|
629
786
|
if (questions > 5) return `onboarding: ${questions} questions; Discord allows up to 5`;
|
|
630
787
|
const welcome = layout.welcome;
|
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.199",
|
|
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.45.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.199"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@theholocron/discord-client": "^1.
|
|
54
|
+
"@theholocron/discord-client": "^1.45.0",
|
|
55
55
|
"@theholocron/misc-utils": "^1.16.0",
|
|
56
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
56
|
+
"@theholocron/cli": "5.0.0-alpha.199"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=22"
|