discord.js-backup-v13 13.1.1 → 13.1.2
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/lib/create.js +42 -46
- package/lib/load.js +2 -2
- package/lib/types/RoleData.d.ts +1 -1
- package/lib/util.js +30 -23
- package/package.json +1 -1
package/lib/create.js
CHANGED
|
@@ -89,6 +89,8 @@ async function getEmojis(guild, options) {
|
|
|
89
89
|
return emojis;
|
|
90
90
|
}
|
|
91
91
|
exports.getEmojis = getEmojis;
|
|
92
|
+
|
|
93
|
+
|
|
92
94
|
/**
|
|
93
95
|
* Returns an array with the channels of the guild
|
|
94
96
|
* @param {Guild} guild The discord guild
|
|
@@ -96,57 +98,51 @@ exports.getEmojis = getEmojis;
|
|
|
96
98
|
* @returns {ChannelData[]} The channels of the guild
|
|
97
99
|
*/
|
|
98
100
|
async function getChannels(guild, options) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
const allChannels = guild.channels.cache;
|
|
102
|
+
|
|
103
|
+
const categories = allChannels
|
|
104
|
+
.filter(ch => ch.type === 'GUILD_CATEGORY')
|
|
105
|
+
.sort((a, b) => a.position - b.position);
|
|
106
|
+
|
|
107
|
+
const categoryDataPromises = categories.map(async (category) => {
|
|
108
|
+
const children = allChannels
|
|
109
|
+
.filter(c => c.parentId === category.id)
|
|
110
|
+
.sort((a, b) => a.position - b.position);
|
|
111
|
+
|
|
112
|
+
const childrenData = await Promise.all(children.map(child => fetchAnyChannelData(child, options)));
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
name: category.name,
|
|
116
|
+
permissions: (0, util_1.fetchChannelPermissions)(category),
|
|
117
|
+
children: childrenData
|
|
103
118
|
};
|
|
119
|
+
});
|
|
104
120
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
121
|
+
const others = allChannels
|
|
122
|
+
.filter(ch => !ch.parent && ch.type !== 'GUILD_CATEGORY' && !ch.isThread() && ch.type !== 'GUILD_STORE')
|
|
123
|
+
.sort((a, b) => a.position - b.position);
|
|
108
124
|
|
|
109
|
-
|
|
125
|
+
const othersDataPromises = others.map(ch => fetchAnyChannelData(ch, options));
|
|
110
126
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
};
|
|
116
|
-
const children = guild.channels.cache.filter(c => c.parentId == category.id).sort((a, b) => a.position - b.position)
|
|
127
|
+
const [categoriesResult, othersResult] = await Promise.all([
|
|
128
|
+
Promise.all(categoryDataPromises),
|
|
129
|
+
Promise.all(othersDataPromises)
|
|
130
|
+
]);
|
|
117
131
|
|
|
118
|
-
|
|
132
|
+
return {
|
|
133
|
+
categories: categoriesResult,
|
|
134
|
+
others: othersResult
|
|
135
|
+
};
|
|
136
|
+
}
|
|
119
137
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
channels.categories.push(categoryData);
|
|
130
|
-
}
|
|
131
|
-
const others = guild.channels.cache
|
|
132
|
-
.filter((ch) => {
|
|
133
|
-
return !ch.parent && ch.type !== 'GUILD_CATEGORY'
|
|
134
|
-
&& ch.type !== 'GUILD_STORE'
|
|
135
|
-
&& ch.type !== 'GUILD_NEWS_THREAD' && ch.type !== 'GUILD_PRIVATE_THREAD' && ch.type !== 'GUILD_PUBLIC_THREAD';
|
|
136
|
-
})
|
|
137
|
-
.sort((a, b) => a.position - b.position)
|
|
138
|
-
.toJSON();
|
|
139
|
-
for (const channel of others.values()) {
|
|
140
|
-
if (channel.type === 'GUILD_TEXT' || channel.type === 'GUILD_NEWS') {
|
|
141
|
-
const channelData = await (0, util_1.fetchTextChannelData)(channel, options);
|
|
142
|
-
channels.others.push(channelData);
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
const channelData = await (0, util_1.fetchVoiceChannelData)(channel);
|
|
146
|
-
channels.others.push(channelData);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
resolve(channels);
|
|
150
|
-
});
|
|
138
|
+
/**
|
|
139
|
+
* Fonction utilitaire pour éviter la répétition de la logique IF/ELSE
|
|
140
|
+
*/
|
|
141
|
+
async function fetchAnyChannelData(channel, options) {
|
|
142
|
+
if (['GUILD_TEXT', 'GUILD_NEWS'].includes(channel.type)) {
|
|
143
|
+
return await (0, util_1.fetchTextChannelData)(channel, options);
|
|
144
|
+
} else {
|
|
145
|
+
return await (0, util_1.fetchVoiceChannelData)(channel);
|
|
146
|
+
}
|
|
151
147
|
}
|
|
152
148
|
exports.getChannels = getChannels;
|
package/lib/load.js
CHANGED
|
@@ -50,7 +50,7 @@ const loadRoles = (guild, backupData) => {
|
|
|
50
50
|
if (roleData.isEveryone) {
|
|
51
51
|
rolePromises.push(guild.roles.cache.get(guild.id).edit({
|
|
52
52
|
name: roleData.name,
|
|
53
|
-
|
|
53
|
+
colors: { primaryColor: roleData.color },
|
|
54
54
|
permissions: BigInt(roleData.permissions),
|
|
55
55
|
mentionable: roleData.mentionable
|
|
56
56
|
}));
|
|
@@ -58,7 +58,7 @@ const loadRoles = (guild, backupData) => {
|
|
|
58
58
|
else {
|
|
59
59
|
rolePromises.push(guild.roles.create({
|
|
60
60
|
name: roleData.name,
|
|
61
|
-
|
|
61
|
+
colors: { primaryColor: roleData.color },
|
|
62
62
|
hoist: roleData.hoist,
|
|
63
63
|
permissions: BigInt(roleData.permissions),
|
|
64
64
|
mentionable: roleData.mentionable
|
package/lib/types/RoleData.d.ts
CHANGED
package/lib/util.js
CHANGED
|
@@ -47,37 +47,41 @@ async function fetchVoiceChannelData(channel) {
|
|
|
47
47
|
}
|
|
48
48
|
exports.fetchVoiceChannelData = fetchVoiceChannelData;
|
|
49
49
|
async function fetchChannelMessages(channel, options) {
|
|
50
|
-
|
|
51
|
-
const
|
|
50
|
+
const messages = [];
|
|
51
|
+
const maxMessages = isNaN(options.maxMessagesPerChannel) ? 10 : options.maxMessagesPerChannel;
|
|
52
52
|
const fetchOptions = { limit: 100 };
|
|
53
53
|
let lastMessageId;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
|
|
55
|
+
const imageRegex = /\.(png|jpg|jpeg|jpe|jif|jfif|jfi)$/i;
|
|
56
|
+
|
|
57
|
+
while (messages.length < maxMessages) {
|
|
58
|
+
if (lastMessageId) fetchOptions.before = lastMessageId;
|
|
59
|
+
|
|
59
60
|
const fetched = await channel.messages.fetch(fetchOptions);
|
|
60
|
-
if (fetched.size === 0)
|
|
61
|
-
|
|
62
|
-
}
|
|
61
|
+
if (fetched.size === 0) break;
|
|
62
|
+
|
|
63
63
|
lastMessageId = fetched.last().id;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
|
|
65
|
+
for (const msg of fetched.values()) {
|
|
66
|
+
if (messages.length >= maxMessages) break;
|
|
67
|
+
if (!msg.author) continue;
|
|
68
|
+
|
|
69
69
|
const files = await Promise.all(msg.attachments.map(async (a) => {
|
|
70
70
|
let attach = a.url;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
|
|
72
|
+
if (options.saveImages === 'base64' && imageRegex.test(a.url)) {
|
|
73
|
+
try {
|
|
74
|
+
const response = await fetch(a.url);
|
|
75
|
+
const buffer = await response.arrayBuffer();
|
|
76
|
+
attach = Buffer.from(buffer).toString('base64');
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.error(`Erreur base64 sur ${a.url}:`, e);
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
attachment: attach
|
|
79
|
-
};
|
|
81
|
+
|
|
82
|
+
return { name: a.name, attachment: attach };
|
|
80
83
|
}));
|
|
84
|
+
|
|
81
85
|
messages.push({
|
|
82
86
|
username: msg.author.username,
|
|
83
87
|
avatar: msg.author.displayAvatarURL(),
|
|
@@ -87,8 +91,11 @@ async function fetchChannelMessages(channel, options) {
|
|
|
87
91
|
pinned: msg.pinned,
|
|
88
92
|
sentAt: msg.createdAt.toISOString(),
|
|
89
93
|
});
|
|
90
|
-
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (fetched.size < 100) break;
|
|
91
97
|
}
|
|
98
|
+
|
|
92
99
|
return messages;
|
|
93
100
|
}
|
|
94
101
|
exports.fetchChannelMessages = fetchChannelMessages;
|