Skip to content

Commit

Permalink
🐛 Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Androz2091 committed Apr 28, 2021
1 parent fc1e9d8 commit 427755d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
4 changes: 1 addition & 3 deletions src/types/LoadOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { WebhookMessageOptions } from 'discord.js';

export interface LoadOptions {
clearGuildBeforeRestore: boolean;
maxMessagesPerChannel?: number;
disableWebhookMention?: 'none' | 'all' | 'everyone';
disableWebhookMentions?: 'none' | 'all' | 'everyone';
}
31 changes: 16 additions & 15 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,32 @@ export async function fetchTextChannelData(channel: TextChannel | NewsChannel, o
break;
}
lastMessageId = fetched.last().id;
fetched.forEach((msg) => {
await Promise.all(fetched.map(async (msg) => {
if (!msg.author || channelData.messages.length >= messageCount) {
fetchComplete = true;
return;
}
const files = await Promise.all(msg.attachments.map(async (a) => {
let attach = a.url
if (a.url && ['png', 'jpg', 'jpeg', 'jpe', 'jif', 'jfif', 'jfi'].includes(a.url)) {
if (options.saveImages && options.saveImages === 'base64') {
attach = (await (nodeFetch(a.url).then((res) => res.buffer()))).toString('base64')
}
}
return {
name: a.name,
attachment: attach
};
}))
channelData.messages.push({
username: msg.author.username,
avatar: msg.author.displayAvatarURL(),
content: msg.cleanContent,
embeds: msg.embeds,
files: msg.attachments.map((a) => {
let attach = a.url
if (a.url && ['png', 'jpg', 'jpeg', 'jpe', 'jif', 'jfif', 'jfi'].includes(a.url)) {
if (options.saveImages && options.saveImages === 'base64') {
attach = (nodeFetch(a.url).then((res) => res.buffer())).toString('base64')
}
}
return {
name: a.name,
attachment: attach
};
}),
files,
pinned: msg.pinned
});
});
}));
}
/* Return channel data */
resolve(channelData);
Expand Down Expand Up @@ -212,7 +213,7 @@ export async function loadChannel(
avatarURL: msg.avatar,
embeds: msg.embeds,
files: msg.files,
disableMentions: options.disableWebhookMention
disableMentions: options.disableWebhookMentions
})
.catch((err) => {
console.log(err.message);
Expand Down

0 comments on commit 427755d

Please sign in to comment.