Skip to content

Instantly share code, notes, and snippets.

@fanatid
Last active May 26, 2019 06:58
Show Gist options
  • Save fanatid/b9701e584c0e00ec3d40bb1d400db1f7 to your computer and use it in GitHub Desktop.
Save fanatid/b9701e584c0e00ec3d40bb1d400db1f7 to your computer and use it in GitHub Desktop.
Download custom emojis from slack
const fs = require('fs')
const fetch = require('node-fetch')
;(async () => {
const data = JSON.parse(fs.readFileSync('./data.json', 'utf-8'))
// const html = fs.readFileSync('./x.html', 'utf-8')
// const customTag = '<h3 class="p-emoji_picker__heading">Custom</h3>'
// const text = html.includes(customTag) ? html.slice(html.indexOf(customTag)) : html
// const re = /<span class="emoji emoji-sizer" style="background-image:url\((.*?)\)" data-codepoints="(.*?)">/g
// for (;;) {
// const match = re.exec(text)
// if (!match) break
// data[match[2]] = match[1]
// }
// fs.writeFileSync('./data.json', JSON.stringify(data, null, 2), 'utf-8')
try {
fs.mkdirSync('./emojis')
} catch (err) {
if (err.code !== 'EEXIST') throw err
}
for (const [key, value] of Object.entries(data)) {
console.log(key, value)
const resp = await fetch(value)
const body = await resp.arrayBuffer()
const ext = value.match(/\.(\w+)$/)[1]
fs.writeFileSync(`./emojis/${key}.${ext}`, Buffer.from(body))
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment