To use this drop these two files in beside a folder called emoji
filled with the emoji you want to upload.
Run npm install
to grab the needed dependencies.
Modify the host, user, and pass in the file.
Then run: node import-emoji.js
const { driver } = require('@rocket.chat/sdk'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const mime = require('mime-types'); | |
// customize the following with your server and user account information | |
const HOST = 'yourserver'; | |
const USER = 'youruser'; | |
const PASS = 'yourpassword'; | |
const SSL = true; // server uses https ? | |
const emojiDir = './emoji'; | |
var myuserid; | |
const run = async () => { | |
try { | |
const conn = await driver.connect( { host: HOST, useSsl: SSL}) | |
myuserid = await driver.login({username: USER, password: PASS}); | |
} catch (err) { | |
console.error('Failed to connect', err); | |
process.exit(1); | |
} | |
console.log(`Connected! UserId is ${myuserid}`); | |
const files = fs.readdirSync(emojiDir); | |
for (const file of files) { | |
const pathToFile = path.join(emojiDir, file); | |
console.log(`Preparing to upload: ${file}`); | |
try { | |
const stat = fs.statSync(pathToFile) | |
// Finally its a file... lets do something with it | |
if (stat.isFile()) { | |
const mimeType = mime.lookup(pathToFile); | |
var fileSplit = file.split('.'); | |
const emojiData = { | |
name: fileSplit[0], | |
aliases: '', | |
newFile: true, | |
extension: fileSplit[1] | |
}; | |
await driver.callMethod('insertOrUpdateEmoji', emojiData); | |
const fileData = fs.readFileSync(pathToFile); | |
console.log(`Uploading: ${file} mimeType: ${mimeType}`); | |
await driver.asyncCall('uploadEmojiCustom', [fileData, mimeType, emojiData]); | |
console.log(`Finished Uploading: ${file}`); | |
delete fileData; | |
} | |
} catch (err) { | |
console.error(err); | |
} | |
await sleep(1000); | |
} | |
} | |
function sleep(ms) { | |
console.log(`Sleeping for ${ms}ms`); | |
return new Promise((resolve) => { | |
setTimeout(resolve, ms); | |
}); | |
} | |
run() |
{ | |
"name": "rc-import-emoji", | |
"version": "1.0.0", | |
"description": "", | |
"main": "import-emoji.js", | |
"dependencies": { | |
"@rocket.chat/sdk": "^0.2.9-2", | |
"mime-types": "^2.1.27" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "github.com/geekgonecrazy", | |
} |
I need to update this and use the rest api instead of realtime