@theholocron/holocron-plugin-discord 5.0.0-alpha.202 → 5.0.0-alpha.203

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 CHANGED
@@ -181,6 +181,7 @@ declare class DiscordNotifications implements Notifications {
181
181
  name: string;
182
182
  category?: string;
183
183
  text: string;
184
+ keep?: boolean;
184
185
  }): Promise<NotificationsDelivery>;
185
186
  /** The one role with this name, or an error that says what to fix: none, or more than one. */
186
187
  private roleNamed;
package/dist/index.mjs CHANGED
@@ -1120,6 +1120,7 @@ var DiscordNotifications = class DiscordNotifications {
1120
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
1121
  let bot;
1122
1122
  let hook;
1123
+ let text = input.text;
1123
1124
  try {
1124
1125
  bot = this.bot();
1125
1126
  const channels = await this.channelList();
@@ -1139,18 +1140,23 @@ var DiscordNotifications = class DiscordNotifications {
1139
1140
  token: usable.token,
1140
1141
  channelId: channel.id
1141
1142
  };
1143
+ text = input.text.replaceAll("{channel}", `<#${channel.id}>`);
1142
1144
  } catch (err) {
1143
1145
  return fail(reason(err));
1144
1146
  }
1145
1147
  let messageId;
1146
1148
  try {
1147
- messageId = (await this.client.webhooks.executeAndWait(hook.id, hook.token, input.text)).id;
1149
+ messageId = (await this.client.webhooks.executeAndWait(hook.id, hook.token, text)).id;
1148
1150
  result.posted = true;
1149
1151
  } catch (err) {
1150
1152
  result.problems.push(`the post was refused (${reason(err)})`);
1151
1153
  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
+ const stray = (await bot.channels.messages(hook.channelId, 100)).find((m) => m.webhook_id === hook.id && m.content === text);
1155
+ if (stray && input.keep) {
1156
+ result.posted = true;
1157
+ result.kept = true;
1158
+ result.problems.push(`the test message ${stray.id} arrived but its response was lost; it was left in place`);
1159
+ } else if (stray) {
1154
1160
  await bot.channels.deleteMessage(hook.channelId, stray.id);
1155
1161
  result.problems.push(`the test message ${stray.id} had been posted, and was removed`);
1156
1162
  }
@@ -1163,6 +1169,10 @@ var DiscordNotifications = class DiscordNotifications {
1163
1169
  } catch (err) {
1164
1170
  result.problems.push(`could not read the channel back (${reason(err)})`);
1165
1171
  }
1172
+ if (input.keep) {
1173
+ result.kept = true;
1174
+ return result;
1175
+ }
1166
1176
  try {
1167
1177
  await this.client.webhooks.deleteMessage(hook.id, hook.token, messageId);
1168
1178
  result.removed = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-discord",
3
- "version": "5.0.0-alpha.202",
3
+ "version": "5.0.0-alpha.203",
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.202"
51
+ "@theholocron/cli": "5.0.0-alpha.203"
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.202"
56
+ "@theholocron/cli": "5.0.0-alpha.203"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">=22"