Created
December 23, 2011 21:23
-
-
Save orlp/1515388 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #! /usr/bin/env python | |
| import ircbot | |
| import time | |
| TIMESTAMP = "%d-%m-%Y %H:%M" | |
| class IrcLogger(ircbot.SingleServerIRCBot): | |
| def __init__(self, filename, channel, nickname, server, port=6667): | |
| ircbot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname) | |
| self.channel = channel | |
| self.outfile = open(filename, "a") | |
| def start(self, *args): | |
| self.outfile.write("--- Started logging on %s ---\n" % time.strftime(TIMESTAMP, time.gmtime())) | |
| try: | |
| ircbot.SingleServerIRCBot.start(self, *args) | |
| finally: | |
| self.outfile.write("--- Stopped logging on %s ---\n" % time.strftime(TIMESTAMP, time.gmtime())) | |
| self.outfile.close() | |
| def on_welcome(self, conn, event): | |
| conn.join(self.channel) | |
| def on_pubmsg(self, conn, event): | |
| self.outfile.write("%s <%s>: %s\n" % (time.strftime(TIMESTAMP, time.gmtime()), event.source(), event.arguments()[0])) | |
| bot = IrcLogger("gg2.log", "#gg2", "nc-bot", "irc.esper.net", 6667) | |
| bot.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment