Skip to content

Instantly share code, notes, and snippets.

@chrissharkey
Created March 11, 2012 20:03
Show Gist options
  • Save chrissharkey/2017960 to your computer and use it in GitHub Desktop.
Save chrissharkey/2017960 to your computer and use it in GitHub Desktop.
Pizza voting IRC bot in Node.js
#!/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