discord-message-transcript 1.1.4 → 1.1.6-dev.0
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.
|
@@ -109,7 +109,7 @@ export async function fetchMessages(channel, options, authors, mentions, after)
|
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
const components = await componentsToJson(message.components, options);
|
|
112
|
-
getMentions(message, mentions);
|
|
112
|
+
await getMentions(message, mentions);
|
|
113
113
|
return {
|
|
114
114
|
attachments: options.includeAttachments ? attachments : [],
|
|
115
115
|
authorId: message.author.id,
|
package/dist/core/getMentions.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChannelType } from "discord.js";
|
|
2
|
-
export function getMentions(message, mentions) {
|
|
2
|
+
export async function getMentions(message, mentions) {
|
|
3
3
|
message.mentions.channels.forEach(channel => {
|
|
4
4
|
if (!mentions.channels.has(channel.id)) {
|
|
5
5
|
mentions.channels.set(channel.id, {
|
|
@@ -17,8 +17,6 @@ export function getMentions(message, mentions) {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
-
if (message.guild) {
|
|
21
|
-
}
|
|
22
20
|
if (message.mentions.members) {
|
|
23
21
|
message.mentions.members.forEach(member => {
|
|
24
22
|
if (!mentions.users.has(member.id)) {
|
|
@@ -41,59 +39,70 @@ export function getMentions(message, mentions) {
|
|
|
41
39
|
}
|
|
42
40
|
});
|
|
43
41
|
}
|
|
44
|
-
fetchRoleMention(message, mentions);
|
|
45
|
-
fetchChannelMention(message, mentions);
|
|
46
|
-
fetchUserMention(message, mentions);
|
|
42
|
+
await Promise.all([fetchRoleMention(message, mentions), fetchChannelMention(message, mentions), fetchUserMention(message, mentions)]);
|
|
47
43
|
}
|
|
48
|
-
//
|
|
49
|
-
function fetchRoleMention(message, mentions) {
|
|
50
|
-
const roleIds =
|
|
44
|
+
// Discord sometimes lacks role mentions in message.mentions
|
|
45
|
+
async function fetchRoleMention(message, mentions) {
|
|
46
|
+
const roleIds = new Set();
|
|
51
47
|
for (const match of message.content.matchAll(/<@&(\d+)>/g)) {
|
|
52
48
|
const roleId = match[1];
|
|
53
|
-
if (roleId && !
|
|
54
|
-
roleIds.
|
|
49
|
+
if (roleId && !mentions.roles.has(roleId)) {
|
|
50
|
+
roleIds.add(roleId);
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
for (const id of roleIds) {
|
|
54
|
+
try {
|
|
55
|
+
const role = await message.guild?.roles.fetch(id);
|
|
56
|
+
if (!role)
|
|
57
|
+
continue;
|
|
58
|
+
mentions.roles.set(role.id, { id: role.id, color: role.hexColor, name: role.name });
|
|
59
|
+
}
|
|
60
|
+
catch { } // Role may not exist
|
|
61
|
+
}
|
|
63
62
|
}
|
|
64
|
-
function fetchUserMention(message, mentions) {
|
|
65
|
-
const usersId =
|
|
63
|
+
async function fetchUserMention(message, mentions) {
|
|
64
|
+
const usersId = new Set();
|
|
66
65
|
for (const match of message.content.matchAll(/<@(\d+)>/g)) {
|
|
67
66
|
const userId = match[1];
|
|
68
|
-
if (userId && !
|
|
69
|
-
usersId.
|
|
67
|
+
if (userId && !mentions.users.has(userId)) {
|
|
68
|
+
usersId.add(userId);
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
|
-
|
|
71
|
+
for (const id of usersId) {
|
|
73
72
|
if (message.guild) {
|
|
74
|
-
|
|
73
|
+
try {
|
|
74
|
+
const user = await message.guild.members.fetch(id);
|
|
75
|
+
if (user) {
|
|
76
|
+
mentions.users.set(user.id, { id: user.id, color: user.displayHexColor, name: user.displayName });
|
|
77
|
+
continue; // Continue inside if to allow fallback to regular user fetch
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch { } // Member may not exist
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const user = await message.client.users.fetch(id);
|
|
75
84
|
if (!user)
|
|
76
|
-
|
|
77
|
-
mentions.users.set(user.id, { id: user.id, color: user.
|
|
85
|
+
continue;
|
|
86
|
+
mentions.users.set(user.id, { id: user.id, color: message.guild ? null : user.hexAccentColor ?? null, name: user.displayName });
|
|
78
87
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return;
|
|
82
|
-
mentions.users.set(user.id, { id: user.id, color: user.hexAccentColor ?? null, name: user.displayName });
|
|
83
|
-
});
|
|
88
|
+
catch { } // User may not exist
|
|
89
|
+
}
|
|
84
90
|
}
|
|
85
|
-
function fetchChannelMention(message, mentions) {
|
|
86
|
-
const channelIds =
|
|
91
|
+
async function fetchChannelMention(message, mentions) {
|
|
92
|
+
const channelIds = new Set();
|
|
87
93
|
for (const match of message.content.matchAll(/<#(\d+)>/g)) {
|
|
88
94
|
const channelId = match[1];
|
|
89
|
-
if (channelId && !
|
|
90
|
-
channelIds.
|
|
95
|
+
if (channelId && !mentions.channels.has(channelId)) {
|
|
96
|
+
channelIds.add(channelId);
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
for (const id of channelIds) {
|
|
100
|
+
try {
|
|
101
|
+
const channel = await message.guild?.channels.fetch(id);
|
|
102
|
+
if (!channel)
|
|
103
|
+
continue;
|
|
104
|
+
mentions.channels.set(channel.id, { id: channel.id, name: channel.name });
|
|
105
|
+
}
|
|
106
|
+
catch { } // Channel may not exist
|
|
107
|
+
}
|
|
99
108
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "discord-message-transcript",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6-dev.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"typescript": "^5.9.3"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"discord-message-transcript-base": "
|
|
51
|
+
"discord-message-transcript-base": "1.1.6-dev.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"discord.js": ">=14.19.0 <15"
|