Last active
August 29, 2015 14:06
-
-
Save coleww/93da70b5efbc5b4dd329 to your computer and use it in GitHub Desktop.
FIX THE BOTS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var irc = require("irc"); | |
var fs = require('fs'); | |
var markov = require('markov'); | |
var FIVE_MINUTES = 5 * 60 * 1000; | |
var TOTAL = 25000; | |
var CHANNEL_NAME = '#the_name_of_yr_channel' | |
var NETWORK = 'the.name.of.yr.network | |
var installBot = function(options){ | |
var mark = markov(options.ngram); | |
var txt = fs.createReadStream(__dirname + options.fileName); | |
mark.seed(txt, function(){ | |
var bot = new irc.Client(NETWORK, options.name, {channels: [CHANNEL_NAME]}); | |
saySomething(bot, mark, options); | |
// eavesDrop(bot, mark, options); | |
}); | |
}; | |
var saySomething = function(bot, mark, options){ | |
var response = breakThyChains(mark, options); | |
bot.say(CHANNEL_NAME, response); | |
var nextTime = FIVE_MINUTES + Math.random() * (TOTAL / options.rate); | |
setTimeout(function(){ | |
saySomething(bot, mark, options); | |
}, nextTime); | |
}; | |
var breakThyChains = function(mark, options, txt){ | |
var str = ''; | |
if (txt) { | |
str = txt.replace(options.name, ''); | |
} else { | |
str = mark.pick(); | |
} | |
return mark.respond(str, 50).join(" ").replace(/,/g, " ").replace(/\s+/, ' '); | |
}; | |
require('./config.js').forEach(function(botOpts){ | |
console.log(botOpts); | |
installBot(botOpts); | |
}); | |
// a botOpts looks like this: | |
{ | |
ngram: 2, | |
name: 'coledubs', | |
fileName: '/coledubs.txt', | |
listeners: /\bcole/i, | |
rate: 2703 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2014-09-18T15:29:39.569030+00:00 app[bot.1]: /app/node_modules/irc/lib/irc.js:672 | |
2014-09-18T15:29:39.569292+00:00 app[bot.1]: throw err; | |
2014-09-18T15:29:39.569360+00:00 app[bot.1]: ^ | |
2014-09-18T15:29:39.571603+00:00 app[bot.1]: TypeError: Uncaught, unspecified "error" event. | |
2014-09-18T15:29:39.571606+00:00 app[bot.1]: at TypeError (<anonymous>) | |
2014-09-18T15:29:39.571607+00:00 app[bot.1]: at Client.emit (events.js:74:15) | |
2014-09-18T15:29:39.571609+00:00 app[bot.1]: at Client.<anonymous> (/app/node_modules/irc/lib/irc.js:550:26) | |
2014-09-18T15:29:39.571611+00:00 app[bot.1]: at Client.emit (events.js:95:17) | |
2014-09-18T15:29:39.571612+00:00 app[bot.1]: at /app/node_modules/irc/lib/irc.js:669:22 | |
2014-09-18T15:29:39.571614+00:00 app[bot.1]: at Array.forEach (native) | |
2014-09-18T15:29:39.571615+00:00 app[bot.1]: at Socket.<anonymous> (/app/node_modules/irc/lib/irc.js:666:15) | |
2014-09-18T15:29:39.571617+00:00 app[bot.1]: at Socket.emit (events.js:95:17) | |
2014-09-18T15:29:39.571618+00:00 app[bot.1]: at Socket.<anonymous> (_stream_readable.js:764:14) | |
2014-09-18T15:29:39.571640+00:00 app[bot.1]: at Socket.emit (events.js:92:17) | |
2014-09-18T15:29:40.274969+00:00 heroku[bot.1]: Process exited with status 8 | |
2014-09-18T15:29:40.285369+00:00 heroku[bot.1]: State changed from up to crashed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment