Skip to content

Instantly share code, notes, and snippets.

@orlp
Created December 23, 2011 21:23
Show Gist options
  • Select an option

  • Save orlp/1515388 to your computer and use it in GitHub Desktop.

Select an option

Save orlp/1515388 to your computer and use it in GitHub Desktop.
#! /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