@theholocron/holocron-plugin-discord 5.0.0-alpha.200 → 5.0.0-alpha.201
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 +10 -1
- package/dist/index.mjs +65 -0
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthError, EnsureWebhookResult, EnsuredResource, Notifications, NotificationsAccess, NotificationsApplicationLayout, NotificationsEveryoneLayout, NotificationsLayout, NotificationsMember, NotificationsOnboardingLayout, NotificationsServerLayout, NotificationsSignIn, NotificationsWelcomeLayout, ResolveTokenInput, ServerInspection, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
|
|
1
|
+
import { AuthError, EnsureWebhookResult, EnsuredResource, Notifications, NotificationsAccess, NotificationsApplicationLayout, NotificationsDelivery, NotificationsEveryoneLayout, NotificationsLayout, NotificationsMember, NotificationsOnboardingLayout, NotificationsServerLayout, NotificationsSignIn, NotificationsWelcomeLayout, ResolveTokenInput, ServerInspection, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
|
|
2
2
|
import { DiscordBotClient, DiscordClient, DiscordClientOptions, DiscordOAuthClient, DiscordWebhookInfo, createDiscordClient, parseWebhookUrl } from "@theholocron/discord-client";
|
|
3
3
|
//#region src/auth.d.ts
|
|
4
4
|
declare const resolveToken: (input?: ResolveTokenInput) => string;
|
|
@@ -21,6 +21,9 @@ interface DiscordNotificationsOptions {
|
|
|
21
21
|
guildId?: string;
|
|
22
22
|
/** The server layout `notifications setup` applies. */
|
|
23
23
|
layout?: NotificationsLayout;
|
|
24
|
+
/** A custom API host, for tests. Webhook tokens are only sent to it when `unsafeBotBaseUrl` is also set. */
|
|
25
|
+
baseUrl?: string;
|
|
26
|
+
unsafeBotBaseUrl?: boolean;
|
|
24
27
|
}
|
|
25
28
|
declare class DiscordNotifications implements Notifications {
|
|
26
29
|
private readonly client;
|
|
@@ -173,6 +176,12 @@ declare class DiscordNotifications implements Notifications {
|
|
|
173
176
|
category?: string;
|
|
174
177
|
avatar?: string;
|
|
175
178
|
}): Promise<EnsureWebhookResult>;
|
|
179
|
+
checkDelivery(input: {
|
|
180
|
+
channel: string;
|
|
181
|
+
name: string;
|
|
182
|
+
category?: string;
|
|
183
|
+
text: string;
|
|
184
|
+
}): Promise<NotificationsDelivery>;
|
|
176
185
|
/** The one role with this name, or an error that says what to fix: none, or more than one. */
|
|
177
186
|
private roleNamed;
|
|
178
187
|
roleMembers(roleName: string): Promise<NotificationsMember[]>;
|
package/dist/index.mjs
CHANGED
|
@@ -1106,6 +1106,71 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
1106
1106
|
}
|
|
1107
1107
|
return result;
|
|
1108
1108
|
}
|
|
1109
|
+
async checkDelivery(input) {
|
|
1110
|
+
const result = {
|
|
1111
|
+
posted: false,
|
|
1112
|
+
readBack: false,
|
|
1113
|
+
removed: false,
|
|
1114
|
+
problems: []
|
|
1115
|
+
};
|
|
1116
|
+
const fail = (problem) => ({
|
|
1117
|
+
...result,
|
|
1118
|
+
problems: [problem]
|
|
1119
|
+
});
|
|
1120
|
+
if (this.opts.baseUrl && !this.opts.unsafeBotBaseUrl) return fail("refusing to send a webhook token to a custom `baseUrl`; remove it, or set `unsafeBotBaseUrl` for a test server");
|
|
1121
|
+
let bot;
|
|
1122
|
+
let hook;
|
|
1123
|
+
try {
|
|
1124
|
+
bot = this.bot();
|
|
1125
|
+
const channels = await this.channelList();
|
|
1126
|
+
let parent;
|
|
1127
|
+
if (input.category) {
|
|
1128
|
+
parent = channels.find((c) => c.type === ChannelType.Category && DiscordNotifications.same(c.name, input.category))?.id;
|
|
1129
|
+
if (!parent) return fail(`no category named \`${input.category}\``);
|
|
1130
|
+
}
|
|
1131
|
+
const channel = DiscordNotifications.findChannel(channels, input.channel, parent);
|
|
1132
|
+
if (!channel || parent && channel.parent_id !== parent) return fail(`no channel named \`${input.channel}\`${input.category ? ` under \`${input.category}\`` : ""}`);
|
|
1133
|
+
const named = (await bot.channels.webhooks(channel.id)).filter((w) => DiscordNotifications.same(w.name ?? "", input.name));
|
|
1134
|
+
if (named.length === 0) return fail(`no webhook named \`${input.name}\``);
|
|
1135
|
+
const usable = named.find((w) => w.token);
|
|
1136
|
+
if (!usable?.token) return fail(`webhook \`${input.name}\` was not created by this bot, so its token is hidden`);
|
|
1137
|
+
hook = {
|
|
1138
|
+
id: usable.id,
|
|
1139
|
+
token: usable.token,
|
|
1140
|
+
channelId: channel.id
|
|
1141
|
+
};
|
|
1142
|
+
} catch (err) {
|
|
1143
|
+
return fail(reason(err));
|
|
1144
|
+
}
|
|
1145
|
+
let messageId;
|
|
1146
|
+
try {
|
|
1147
|
+
messageId = (await this.client.webhooks.executeAndWait(hook.id, hook.token, input.text)).id;
|
|
1148
|
+
result.posted = true;
|
|
1149
|
+
} catch (err) {
|
|
1150
|
+
result.problems.push(`the post was refused (${reason(err)})`);
|
|
1151
|
+
try {
|
|
1152
|
+
const stray = (await bot.channels.messages(hook.channelId, 100)).find((m) => m.webhook_id === hook.id && m.content === input.text);
|
|
1153
|
+
if (stray) {
|
|
1154
|
+
await bot.channels.deleteMessage(hook.channelId, stray.id);
|
|
1155
|
+
result.problems.push(`the test message ${stray.id} had been posted, and was removed`);
|
|
1156
|
+
}
|
|
1157
|
+
} catch {}
|
|
1158
|
+
return result;
|
|
1159
|
+
}
|
|
1160
|
+
try {
|
|
1161
|
+
result.readBack = (await bot.channels.messages(hook.channelId, 100)).some((m) => m.id === messageId && m.content === input.text);
|
|
1162
|
+
if (!result.readBack) result.problems.push("the post was accepted but is not in the channel");
|
|
1163
|
+
} catch (err) {
|
|
1164
|
+
result.problems.push(`could not read the channel back (${reason(err)})`);
|
|
1165
|
+
}
|
|
1166
|
+
try {
|
|
1167
|
+
await this.client.webhooks.deleteMessage(hook.id, hook.token, messageId);
|
|
1168
|
+
result.removed = true;
|
|
1169
|
+
} catch (err) {
|
|
1170
|
+
result.problems.push(`could not remove the test message ${messageId} (${reason(err)})`);
|
|
1171
|
+
}
|
|
1172
|
+
return result;
|
|
1173
|
+
}
|
|
1109
1174
|
/** The one role with this name, or an error that says what to fix: none, or more than one. */
|
|
1110
1175
|
async roleNamed(name) {
|
|
1111
1176
|
const matches = (await this.bot().guilds.roles(this.guild())).filter((r) => DiscordNotifications.same(r.name, name));
|
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.201",
|
|
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.201"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@theholocron/discord-client": "^1.48.0",
|
|
55
55
|
"@theholocron/misc-utils": "^1.16.0",
|
|
56
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
56
|
+
"@theholocron/cli": "5.0.0-alpha.201"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=22"
|