From d04d8df328c1f8cdae5364bef412a2372c2afca6 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 28 Mar 2021 21:42:13 -0400 Subject: [PATCH] Emoji Zip Command --- commands/info/emoji-zip.js | 33 +++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 34 insertions(+) create mode 100644 commands/info/emoji-zip.js diff --git a/commands/info/emoji-zip.js b/commands/info/emoji-zip.js new file mode 100644 index 00000000..fc18e1d6 --- /dev/null +++ b/commands/info/emoji-zip.js @@ -0,0 +1,33 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const JSZip = require('jszip'); + +module.exports = class EmojiZipCommand extends Command { + constructor(client) { + super(client, { + name: 'emoji-zip', + aliases: ['emojis-zip', 'emotes-zip', 'e-zip'], + group: 'info', + memberName: 'emoji-zip', + description: 'Responds with a ZIP file of the server\'s custom emoji.', + throttling: { + usages: 1, + duration: 60 + }, + guildOnly: true + }); + } + + async run(msg) { + const emojis = msg.guild.emojis.cache; + if (!emojis.size) return msg.say('This server has no custom emoji.'); + const zip = new JSZip(); + await Promise.all(emojis.map(async emoji => { + const { body } = await request.get(emoji.url); + const format = emoji.animated ? 'gif' : 'png'; + zip.file(`${emoji.id}.${format}`, body); + })); + const zipped = await zip.generateAsync({ type: 'nodebuffer' }); + return msg.say({ files: [{ attachment: zipped, name: 'emoji.zip' }] }); + } +}; diff --git a/package.json b/package.json index e5a82c3a..0e7a04c5 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "ioredis": "^4.24.5", "js-beautify": "^1.13.5", "js-chess-engine": "^0.11.1", + "jszip": "^3.6.0", "kuroshiro": "^1.1.2", "kuroshiro-analyzer-kuromoji": "^1.1.0", "mathjs": "^9.3.0",