From 30c342fc3143c129531f531eebb4b3cb58ad2e12 Mon Sep 17 00:00:00 2001 From: rhearmas <34490428+qu-ota@users.noreply.github.com> Date: Sat, 21 Dec 2019 10:45:07 -0500 Subject: [PATCH] Initial commit --- commands/Fun/imagedumper.js | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 commands/Fun/imagedumper.js diff --git a/commands/Fun/imagedumper.js b/commands/Fun/imagedumper.js new file mode 100644 index 0000000..736e9dc --- /dev/null +++ b/commands/Fun/imagedumper.js @@ -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 " +}; + +function download(url) { + let file = fs.createWriteStream(`${__dirname}/../../imagedumper_output/attachment_${path.basename(url)}`); + got.stream(url).pipe(file); +} \ No newline at end of file