Skip to content

Instantly share code, notes, and snippets.

@mrarmyant
Created December 8, 2020 20:49
Show Gist options
  • Save mrarmyant/2a998404a0575378b23d0b741087954b to your computer and use it in GitHub Desktop.
Save mrarmyant/2a998404a0575378b23d0b741087954b to your computer and use it in GitHub Desktop.
Slackord 2 Node.JS Channel JSON Joiner
var fs = require('fs');
var dirname = __dirname + "\\json\\";
outputFile = "bulk.json";
let output = [];
function readFiles() {
let filenames = fs.readdirSync(dirname);
filenames.forEach((filename)=> {
fileloc = dirname + filename;
onFileContent(fs.readFileSync(fileloc));
});
}
function onFileContent(content) {
let fileObject = JSON.parse(content);
fileObject.forEach((message) => {
output.push(message);
})
}
function saveJson() {
fs.writeFileSync(`./${outputFile}`, JSON.stringify(output), err => {
if (err) {
console.log('Error writing file', err)
} else {
console.log('Successfully wrote file')
}
})
}
readFiles();
saveJson();
// console.log(`FINAL OUTPUT: ${JSON.stringify(output)}`);1
@Geczy
Copy link

Geczy commented Dec 13, 2020

Can you make this switch directories for each channel and do a bulk.json for each?

@mrarmyant
Copy link
Author

Its possibly doable but at that point I'd also probably just use this as the transporter to discord. Its already reading the files into an object. I havent looked at the discord documentation though, im not aure of bots can move channels on their own they arent invited to. Youd also need to make sure channel names were created that matched but only if a bot cant create them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment