-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (39 loc) · 1.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const { existsSync } = require('fs');
const Slack = require('slack');
const download = require('download-file');
const { forEach, last, split, startsWith } = require('lodash');
const directory = './emoji';
const token = process.env.EMOJINATOR_SLACKBOT_TOKEN;
const bot = new Slack({ token });
bot.emoji.list().then(({ emoji }) => {
forEach(emoji, (url, key) => {
try {
downloadEmojum(url, key);
} catch (err) {
console.error(err.message, { url, key });
}
})
});
function downloadEmojum(url, key) {
if (startsWith(url, 'alias:')) {
console.log(`Skipping alias: ${key}`);
return;
}
const ext = last(split(url, '.')).toLowerCase();
if (ext === 'gif') {
console.log(`Skipping GIF :${key}:`);
return; // free Discord disables animated emoji
}
const filename = `${key}.${ext}`;
if (existsSync(`${directory}/${filename}`)) {
console.log(`File exists, skipping: ${filename}`);
return;
}
download(url, { directory, filename }, err => {
if (err) {
console.error(err.message);
return;
}
console.log(`Downloaded ${filename}`);
});
}