Created
March 31, 2012 21:45
-
-
Save ericholscher/2268845 to your computer and use it in GitHub Desktop.
Basic Redis IRC Client
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
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