<commit_before>var slackbot = require('./lib/bot');
var http = require('http');
var querystring = require('querystring');

var config = {
    server: 'irc.freenode.com',
    nick: '_slack_bot',
    username: 'mslackbot612',
    token: '', //no use
    income_url: '',
    outcome_token: '',
    channels: {
        '#g0v.tw': '#g0v_tw'
    },
    users: {
    },
    // optionals
    floodProtection: true,
    silent: false // keep the bot quiet
};

var slackbot = new slackbot.Bot(config);
slackbot.listen();

var server = http.createServer(function (req, res) {
  if (req.method == 'POST') {
    req.on('data', function(data) {
      var payload = querystring.parse(data.toString());

      if (payload.token == config.outcome_token && payload.user_name != 'slackbot') {
        var ircMsg = "<" + payload.user_name + "> " + payload.text;
        var channel = Object.keys(config.channels)[0];

        slackbot.speak(channel, ircMsg);
        res.end('done');
      }
      res.end('request should not be from slackbot or must have matched token.')
    });
  } else {
    res.end('recieved request (not post)');
  }
});

server.listen(5555);
console.log("Server running at http://localhost:5555/");<commit_msg>convert channel, member id to name<commit_after>var slackbot = require('./lib/bot');
var http = require('http');
var querystring = require('querystring');
var request = require('request');
var config = {
    server: 'irc.freenode.com',
    nick: '_slack_bot',
    username: 'mslackbot612',
    token: '', // get from https://api.slack.com/web#basics
    income_url: '',
    outcome_token: '',
    channels: {
        '#g0v.tw': '#g0v_tw'
    },
    users: {
    },
    // optionals
    floodProtection: true,
    silent: false // keep the bot quiet
};
var slackUsers = {};
var slackChannels = {};

request.get({
    url: 'https://slack.com/api/users.list?token=' + config.token
}, function (error, response, body) {
  var res = JSON.parse(body);
  res.members.map(function (member) {
    slackUsers[member.id] = member.name;
  });
});

request.get({
    url: 'https://slack.com/api/channels.list?token=' + config.token
}, function (error, response, body) {
  var res = JSON.parse(body);
  res.channels.map(function (channel) {
    slackChannels[channel.id] = channel.name;
  });
});

var slackbot = new slackbot.Bot(config);
slackbot.listen();

var server = http.createServer(function (req, res) {
  if (req.method == 'POST') {
    req.on('data', function(data) {
      var payload = querystring.parse(data.toString());
      if (payload.token == config.outcome_token && payload.user_name != 'slackbot') {
        var ircMsg = "<" + payload.user_name + "> " + payload.text;
        var channel = Object.keys(config.channels)[0];
        ircMsg = ircMsg.replace(/<#C\w{8}>/g, function (matched) {
            var channel_id = matched.match(/#(C\w{8})/)[1];
            return '#' + slackChannels[channel_id];
        });
        ircMsg = ircMsg.replace(/<@U\w{8}>/g, function (matched) {
            var member_id = matched.match(/@(U\w{8})/)[1];
            return '@' + slackUsers[member_id];
        });
        slackbot.speak(channel, ircMsg);
        res.end('done');
      }
      res.end('request should not be from slackbot or must have matched token.')
    });
  } else {
    res.end('recieved request (not post)');
  }
});

server.listen(5555);
console.log("Server running at http://localhost:5555/");
{'fraction_non_alphanumeric': 0.1764018691588785, 'fraction_numerical': 0.009929906542056074, 'mean_word_length': 2.991841491841492, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4364834', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1139, 'n_words': 238}