Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added a Proof of concept python version.

  • Loading branch information...
commit 9264bbf0923d798e5cd443c65291781e3b2feb3a 1 parent 925db18
Eric Holscher ericholscher authored

Showing 1 changed file with 46 additions and 0 deletions. Show diff stats Hide diff stats

  1. +46 0 bot.py
46 bot.py
... ... @@ -0,0 +1,46 @@
  1 +import gevent
  2 +import redis
  3 +import json
  4 +
  5 +from irc import IRCBot, run_bot
  6 +from gevent import monkey
  7 +
  8 +monkey.patch_all()
  9 +
  10 +r = redis.StrictRedis(host='localhost', port=6379, db=0)
  11 +
  12 +class RelayBot(IRCBot):
  13 +
  14 + def __init__(self, *args, **kwargs):
  15 + super(RelayBot, self).__init__(*args, **kwargs)
  16 + gevent.spawn(self.do_sub)
  17 +
  18 + def do_sub(self):
  19 + r = redis.StrictRedis(host='localhost', port=6379, db=0)
  20 + self.pubsub = r.pubsub()
  21 + self.pubsub.subscribe('out')
  22 + for msg in self.pubsub.listen():
  23 + message = json.loads(msg['data'])
  24 + print "Got %s" % message
  25 + self.respond(message['data']['message'], channel=message['data']['to'])
  26 +
  27 + def do_pub(self, nick, message, channel):
  28 + to_publish = json.dumps({
  29 + 'data': {
  30 + 'to': channel,
  31 + 'message': message,
  32 + }
  33 + })
  34 + r.publish('in', to_publish)
  35 + print "Sending to in %s" % to_publish
  36 +
  37 + def command_patterns(self):
  38 + return (
  39 + ('.*', self.do_pub),
  40 + )
  41 +
  42 +host = 'irc.freenode.net'
  43 +port = 6667
  44 +nick = 'relaybot'
  45 +
  46 +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.