@friendlyrobot/discord-pi-agent 0.22.0 → 0.22.1
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/discord-replies.js +29 -1
- package/package.json +1 -1
package/dist/discord-replies.js
CHANGED
|
@@ -35,6 +35,34 @@ function chunkByLines(text, maxSize) {
|
|
|
35
35
|
return chunks;
|
|
36
36
|
}
|
|
37
37
|
export const DEFAULT_WORKING_EMOJI = "⚙️";
|
|
38
|
+
function normalizeEmoji(value) {
|
|
39
|
+
return value.normalize("NFKC").replace(/\uFE0F/g, "");
|
|
40
|
+
}
|
|
41
|
+
function findReactionByEmoji(message, emoji) {
|
|
42
|
+
const directMatch = message.reactions.cache.get(emoji);
|
|
43
|
+
if (directMatch) {
|
|
44
|
+
return directMatch;
|
|
45
|
+
}
|
|
46
|
+
const normalizedEmoji = normalizeEmoji(emoji);
|
|
47
|
+
const normalizedMatch = Array.from(message.reactions.cache.entries()).find(([key, reaction]) => {
|
|
48
|
+
if (normalizeEmoji(String(key)) === normalizedEmoji) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (typeof reaction.emoji?.name === "string") {
|
|
52
|
+
return normalizeEmoji(reaction.emoji.name) === normalizedEmoji;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
})?.[1];
|
|
56
|
+
if (!normalizedMatch) {
|
|
57
|
+
logger.debug({
|
|
58
|
+
messageId: message.id,
|
|
59
|
+
emoji,
|
|
60
|
+
normalizedEmoji,
|
|
61
|
+
reactionKeys: Array.from(message.reactions.cache.keys()),
|
|
62
|
+
}, "reaction not found in cache");
|
|
63
|
+
}
|
|
64
|
+
return normalizedMatch;
|
|
65
|
+
}
|
|
38
66
|
export async function addReaction(message, emoji) {
|
|
39
67
|
try {
|
|
40
68
|
await message.react(emoji);
|
|
@@ -45,7 +73,7 @@ export async function addReaction(message, emoji) {
|
|
|
45
73
|
}
|
|
46
74
|
export async function removeReaction(message, emoji) {
|
|
47
75
|
try {
|
|
48
|
-
const reaction = message
|
|
76
|
+
const reaction = findReactionByEmoji(message, emoji);
|
|
49
77
|
if (reaction) {
|
|
50
78
|
await reaction.users.remove(message.client.user);
|
|
51
79
|
}
|