Skip to content

Commit

Permalink
The first real checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
ericflo committed Jul 26, 2009
1 parent c6cb0e1 commit f46ea0a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Empty file added __init__.py
Empty file.
70 changes: 70 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Twisted==8.2.0

0 comments on commit f46ea0a

Please sign in to comment.