Created
March 11, 2012 20:03
-
-
Save chrissharkey/2017960 to your computer and use it in GitHub Desktop.
Pizza voting IRC bot in Node.js
This file contains 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
#!/usr/bin/env node | |
CHANNEL = '#bozler' | |
MINIMUM_HUMAN_REACTION = 2 | |
DIALOGUE = | |
ACTIONS_IN_REPLY: [ | |
"I vote for pizza", | |
"Disregard that, I vote for pizza", | |
"Another vote for pizza!" | |
] | |
irc = require 'irc' | |
client = new irc.Client 'irc.bozler.net', 'ImpartialOutsider', | |
userName: 'im' | |
realName: 'im' | |
channels: [CHANNEL] | |
sayLock = false | |
say = (message, timeout, ignoreLock) -> | |
unless sayLock | |
sayLock = true | |
timeout = Math.random()*30 unless timeout | |
setTimeout -> | |
client.say CHANNEL, message | |
sayLock = false | |
, timeout*1000 + MINIMUM_HUMAN_REACTION*1000 | |
client.addListener "message#{CHANNEL}", (from, message) -> | |
if Math.floor(Math.random()*11) is 3 | |
say(DIALOGUE.ACTIONS_IN_REPLY[Math.floor(Math.random()*DIALOGUE.ACTIONS_IN_REPLY.length-1)]) | |
client.addListener 'pm', (from, message) -> | |
client.say CHANNEL, message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment