-
Notifications
You must be signed in to change notification settings - Fork 0
/
emoji-save.js
40 lines (38 loc) · 1.16 KB
/
emoji-save.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
const dotenv = require('dotenv');
const fs = require('fs');
const request = require('request-promise-native');
dotenv.config();
const dirName = process.env.DIRNAME;
const apiToken = process.env.DOWNLOAD_SLACK_TOKEN;
(async () => {
try {
const res = await request.post({
url: 'https://slack.com/api/emoji.list',
form: {
token: apiToken,
},
});
const json = JSON.parse(res);
if (!fs.existsSync(dirName)) fs.mkdirSync(dirName);
Object.keys(json.emoji).forEach(key => {
const url = json.emoji[key];
//エイリアスは無視
if (url.match(/alias/)) {
return;
}
console.log(`start ${key}`);
request.get({
url,
encoding: null}
).then(res => res).then(res => {
fs.writeFileSync(`${dirName}/${key}.png`, res);
console.log(`end ${key}`);
}).catch(e => {
console.error(`Error(get): ${e}`);
});
});
} catch (e) {
console.error(`Error: ${e}`);
return;
}
})();