Initial commit

This commit is contained in:
rhearmas 2019-12-21 10:45:07 -05:00
parent 3f3dc42332
commit 30c342fc31
1 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,50 @@
const got = require('got');
const fs = require('fs');
const path = require('path');
exports.run = async (client, message, args, level) => {
let count = parseInt(args[0]) || 100;
let attachments = [];
message.channel.fetchMessages({ limit: Math.min(count, 100), before: message.id }).then(messages => {
messages.map(m => {
m.attachments.map(attachment => {
if (attachment.height) {
attachments.push(attachment.url);
}
});
});
let dir = __dirname + '/../../imagedumper_output';
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
for (let i = 0; i < attachments.length; i++) download(attachments[i]);
if (attachments.length === 0) {
message.reply("I couldn\'t find any images here.");
message.delete();
return;
}
message.channel.send(`:white_check_mark: ${attachments.length} images scraped and saved to the "out" folder in this bot's folder.`).then(m => { m.delete(10000); });
message.delete();
}).catch(message.error);
};
exports.conf = {
enabled: true,
guildOnly: false,
aliases: [],
permLevel: "User"
};
exports.help = {
name: "imagedumper",
category: "Fun",
description: "Grabs all images from the specified amount of messages (max 100).",
usage: "imagedumper <amount>"
};
function download(url) {
let file = fs.createWriteStream(`${__dirname}/../../imagedumper_output/attachment_${path.basename(url)}`);
got.stream(url).pipe(file);
}