@theholocron/holocron-plugin-discord 5.0.0-alpha.208 → 5.0.0-alpha.209
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 +6 -1
- package/dist/index.mjs +27 -6
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -97,7 +97,12 @@ declare class DiscordNotifications implements Notifications {
|
|
|
97
97
|
private channelDenies;
|
|
98
98
|
/** The messages this bot posted in a channel, pinned or not, among the channel's last hundred. */
|
|
99
99
|
private ownMessages;
|
|
100
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* The layout's text with each `#name` that is one of the server's channels turned into Discord's own link to it
|
|
102
|
+
* (`<#id>`), so the message shows clickable channels. A name that matches no channel, or more than one, is left as written.
|
|
103
|
+
*/
|
|
104
|
+
private static linkChannels;
|
|
105
|
+
/** The layout's messages grouped by channel, in the order the channels first appear, with channel names linked. */
|
|
101
106
|
private static pinsByChannel;
|
|
102
107
|
/**
|
|
103
108
|
* What differs in one channel: the declared messages that are not pinned yet, and the bot's pinned messages the
|
package/dist/index.mjs
CHANGED
|
@@ -655,12 +655,28 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
655
655
|
pinned: m.pinned === true
|
|
656
656
|
}));
|
|
657
657
|
}
|
|
658
|
-
/**
|
|
659
|
-
|
|
658
|
+
/**
|
|
659
|
+
* The layout's text with each `#name` that is one of the server's channels turned into Discord's own link to it
|
|
660
|
+
* (`<#id>`), so the message shows clickable channels. A name that matches no channel, or more than one, is left as written.
|
|
661
|
+
*/
|
|
662
|
+
static linkChannels(content, channels) {
|
|
663
|
+
const idsByName = /* @__PURE__ */ new Map();
|
|
664
|
+
for (const c of channels) {
|
|
665
|
+
if (c.type === ChannelType.Category) continue;
|
|
666
|
+
idsByName.set(c.name.toLowerCase(), [...idsByName.get(c.name.toLowerCase()) ?? [], c.id]);
|
|
667
|
+
}
|
|
668
|
+
return content.split(/(https?:\/\/\S+)/).map((part, i) => i % 2 === 1 ? part : part.replace(/(?<=^|[\s([{"'*_~>])#([\p{L}\p{N}_-]+)/giu, (whole, name) => {
|
|
669
|
+
const ids = idsByName.get(name.toLowerCase());
|
|
670
|
+
return ids?.length === 1 ? `<#${ids[0]}>` : whole;
|
|
671
|
+
})).join("");
|
|
672
|
+
}
|
|
673
|
+
/** The layout's messages grouped by channel, in the order the channels first appear, with channel names linked. */
|
|
674
|
+
static pinsByChannel(pinned, channels) {
|
|
660
675
|
const byChannel = /* @__PURE__ */ new Map();
|
|
661
676
|
for (const pin of pinned) {
|
|
662
677
|
const key = pin.channel.toLowerCase();
|
|
663
|
-
|
|
678
|
+
const content = DiscordNotifications.linkChannels(pin.content, channels);
|
|
679
|
+
byChannel.set(key, [.../* @__PURE__ */ new Set([...byChannel.get(key) ?? [], content])]);
|
|
664
680
|
}
|
|
665
681
|
return byChannel;
|
|
666
682
|
}
|
|
@@ -686,7 +702,7 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
686
702
|
async pinnedStates(pinned) {
|
|
687
703
|
const channels = await this.channelList();
|
|
688
704
|
const verdicts = /* @__PURE__ */ new Map();
|
|
689
|
-
for (const [channel, wanted] of DiscordNotifications.pinsByChannel(pinned)) {
|
|
705
|
+
for (const [channel, wanted] of DiscordNotifications.pinsByChannel(pinned, channels)) {
|
|
690
706
|
const own = await this.ownMessages(DiscordNotifications.pickChannelId(channels, channel, "pinned messages"));
|
|
691
707
|
const drift = DiscordNotifications.pinDrift(own, wanted);
|
|
692
708
|
verdicts.set(channel, {
|
|
@@ -697,7 +713,7 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
697
713
|
}
|
|
698
714
|
return pinned.map((pin) => {
|
|
699
715
|
const v = verdicts.get(pin.channel.toLowerCase());
|
|
700
|
-
const state = v.missing.has(pin.content) ? v.anyPinned ? "different" : "missing" : v.extras > 0 ? "different" : "ok";
|
|
716
|
+
const state = v.missing.has(DiscordNotifications.linkChannels(pin.content, channels)) ? v.anyPinned ? "different" : "missing" : v.extras > 0 ? "different" : "ok";
|
|
701
717
|
return {
|
|
702
718
|
channel: pin.channel,
|
|
703
719
|
state
|
|
@@ -708,7 +724,12 @@ var DiscordNotifications = class DiscordNotifications {
|
|
|
708
724
|
const bot = this.bot();
|
|
709
725
|
const channels = await this.channelList();
|
|
710
726
|
const updated = [];
|
|
711
|
-
|
|
727
|
+
const byChannel = DiscordNotifications.pinsByChannel(pinned, channels);
|
|
728
|
+
for (const [channel, wanted] of byChannel) {
|
|
729
|
+
const long = wanted.find((content) => content.length > 2e3);
|
|
730
|
+
if (long) throw new Error(`the pinned message for #${channel} is ${long.length} characters once its channel names are linked; Discord allows up to 2000`);
|
|
731
|
+
}
|
|
732
|
+
for (const [channel, wanted] of byChannel) {
|
|
712
733
|
const channelId = DiscordNotifications.pickChannelId(channels, channel, "pinned messages");
|
|
713
734
|
const own = await this.ownMessages(channelId);
|
|
714
735
|
const drift = DiscordNotifications.pinDrift(own, wanted);
|
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.209",
|
|
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.209"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@theholocron/discord-client": "^1.50.0",
|
|
55
55
|
"@theholocron/misc-utils": "^1.16.0",
|
|
56
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
56
|
+
"@theholocron/cli": "5.0.0-alpha.209"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">=22"
|