Skip to content

Instantly share code, notes, and snippets.

@krrishd
Created July 26, 2018 18:27
Show Gist options
  • Save krrishd/5c14c345f070df891696c3dce89f616a to your computer and use it in GitHub Desktop.
Save krrishd/5c14c345f070df891696c3dce89f616a to your computer and use it in GitHub Desktop.
get nice data from a slack archive
'use strict';
const fs = require('fs');
const path = require('path');
const async = require('async');
const getUserFromMessage = (messageObject, userList) => {
const relevantUser = userList.filter(user => {
return (user.id == messageObject.user);
})[0];
return {
name: relevantUser.name,
img: relevantUser.profile.image_512
};
}
module.exports = (folderPath, callback) => {
const users = require(folderPath + '/users.json');
const channels = require(folderPath + '/channels.json');
const channelNames = channels.map(channel => {
return `${folderPath}/${channel.name}`;
});
const totalChannelContents = [];
const traverseChannel = (channelPath, next) => {
let channelContents = [];
fs.readdir(channelPath, (err, files) => {
if (err) {
throw(err);
}
files.map(file => {
return path.join(channelPath, file);
}).filter(file => {
return fs.statSync(file).isFile()
}).forEach(file => {
const contents = require(`./${file}`);
contents.forEach(message => {
totalChannelContents.push(message);
});
});
next();
});
};
async.each(channelNames, traverseChannel, err => {
callback({
totalChannelContents,
getUserFromMessage,
users
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment