Skip to content

Instantly share code, notes, and snippets.

@ericholscher
Created March 31, 2012 21:45
Show Gist options
  • Save ericholscher/2268845 to your computer and use it in GitHub Desktop.
Save ericholscher/2268845 to your computer and use it in GitHub Desktop.
Basic Redis IRC Client
import json
import redis
host = "localhost"
r = redis.Redis(host=host)
def send(to, message):
r.publish('out',
json.dumps({
'version': 1,
'type': 'privmsg',
'data': {
'to': to,
'message': message,
}
}))
def output():
pubsub = r.pubsub()
pubsub.subscribe('in')
for msg in pubsub.listen():
data = json.loads(msg['data'])['data']
print "Got %s in %s from %s" % (data['message'], data['channel'], data['sender'])
if data['message'] == "hello":
send(data['channel'], "Hello %s" % data['sender'])
elif data['message'] == '!woot':
send(data['channel'],"Indeed!")
else:
send(data['channel'],"Wat")
output()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment