Permalink
Browse files

The first real checkin

  • Loading branch information...
ericflo committed Jul 26, 2009
1 parent c6cb0e1 commit f46ea0a23f62a611a0ccf94da3d9259f6d4419f7
Showing with 71 additions and 0 deletions.
  1. 0 __init__.py
  2. +70 −0 bot.py
  3. +1 −0 requirements.txt
View
No changes.
View
70 bot.py
@@ -0,0 +1,70 @@
+import re
+import sys
+import logging
+import logging.handlers
+
+from twisted.words.protocols import irc
+from twisted.internet import reactor, protocol
+
+TICKET_RE = re.compile(r'#(\d+)')
+
+LOG_FILE = '/var/log/cassandra/irc-log'
+
+logger = logging.getLogger()
+handler = logging.handlers.TimedRotatingFileHandler(LOG_FILE, 'midnight', 1)
+formatter = logging.Formatter("%(asctime)s %(message)s")
+handler.setFormatter(formatter)
+logger.addHandler(handler)
+logger.setLevel(logging.INFO)
+
+class CassBot(irc.IRCClient):
+ def _get_nickname(self):
+ return self.factory.nickname
+ nickname = property(_get_nickname)
+
+ def signedOn(self):
+ self.join(self.factory.channel)
+ print "Signed on as %s." % (self.nickname,)
+
+ def joined(self, channel):
+ print "Joined %s." % (channel,)
+
+ def ticketCallback(self, user, msg):
+ match = TICKET_RE.search(msg)
+ if not match:
+ return
+ ticket = int(match.group(1))
+ url = 'http://issues.apache.org/jira/browse/CASSANDRA-%s' % (ticket,)
+ self.msg(self.factory.channel, url)
+
+ def logsCallback(self, user, msg):
+ if self.nickname.lower() not in msg.lower():
+ return
+ if 'logs' not in msg.lower():
+ return
+ self.msg(self.factory.channel, 'http://www.eflorenzano.com/cassbot/')
+
+ def privmsg(self, user, channel, msg):
+ if not user:
+ return
+ logging.info('<' + user.split('!')[0] + '> ' + msg)
+ self.ticketCallback(user, msg)
+ self.logsCallback(user, msg)
+
+class CassBotFactory(protocol.ClientFactory):
+ protocol = CassBot
+
+ def __init__(self, channel='#cassandra', nickname='CassBot'):
+ self.channel = channel
+ self.nickname = nickname
+
+ def clientConnectionLost(self, connector, reason):
+ print >> sys.stderr, "Lost connection (%s), reconnecting." % (reason,)
+ connector.connect()
+
+ def clientConnectionFailed(self, connector, reason):
+ print >> sys.stderr, "Could not connect: %s" % (reason,)
+
+if __name__ == "__main__":
+ reactor.connectTCP('irc.freenode.net', 6667, CassBotFactory())
+ reactor.run()
View
@@ -0,0 +1 @@
+Twisted==8.2.0

0 comments on commit f46ea0a

Please sign in to comment.