Skip to content
Browse files

Added a Proof of concept python version.

  • Loading branch information...
1 parent 925db18 commit 9264bbf0923d798e5cd443c65291781e3b2feb3a @ericholscher ericholscher committed Dec 15, 2011
Showing with 46 additions and 0 deletions.
  1. +46 −0 bot.py
View
46 bot.py
@@ -0,0 +1,46 @@
+import gevent
+import redis
+import json
+
+from irc import IRCBot, run_bot
+from gevent import monkey
+
+monkey.patch_all()
+
+r = redis.StrictRedis(host='localhost', port=6379, db=0)
+
+class RelayBot(IRCBot):
+
+ def __init__(self, *args, **kwargs):
+ super(RelayBot, self).__init__(*args, **kwargs)
+ gevent.spawn(self.do_sub)
+
+ def do_sub(self):
+ r = redis.StrictRedis(host='localhost', port=6379, db=0)
+ self.pubsub = r.pubsub()
+ self.pubsub.subscribe('out')
+ for msg in self.pubsub.listen():
+ message = json.loads(msg['data'])
+ print "Got %s" % message
+ self.respond(message['data']['message'], channel=message['data']['to'])
+
+ def do_pub(self, nick, message, channel):
+ to_publish = json.dumps({
+ 'data': {
+ 'to': channel,
+ 'message': message,
+ }
+ })
+ r.publish('in', to_publish)
+ print "Sending to in %s" % to_publish
+
+ def command_patterns(self):
+ return (
+ ('.*', self.do_pub),
+ )
+
+host = 'irc.freenode.net'
+port = 6667
+nick = 'relaybot'
+
+run_bot(RelayBot, host, port, nick, ['#pdxbots'])

0 comments on commit 9264bbf

Please sign in to comment.
Something went wrong with that request. Please try again.