#!/usr/bin/python import pgdb import time import xchat __module_name__ = "xchatlogger" __module_version__ = "0.1" __module_description__ = "Logs channel messages to a text file and an SQL Server." __module_author__ = "Michael Watters " def connect_db(): try: db = pgdb.connect(host="1.2.3.4", user="user_name", password="password", database="db_name") except: print "Could not connect to database server." return return db def unload_cb(userdata): print "Plugin xchatlogger unloaded!" f.close() def log_event(word, word_eol, userdata): context = xchat.get_context() channel = context.get_info("channel") network = context.get_info("network") # Create DB cursor db = connect_db() cursor = db.cursor() cursor.execute("INSERT INTO irclogs (timestamp, channel, network, nickname, msgtxt) VALUES (now(), %s, %s, %s, %s)", (channel, network, word[0], word_eol[1])) db.commit() ################### try: f.write("%s: <%s> %s\n" %(channel, word[0], word_eol[1])) except: print "Error writing to log file." return xchat.EAT_NONE # Open log file f = open("log.txt", "a") EVENTS = ["Channel Message", "Your Message"] for event in EVENTS: xchat.hook_print(event, log_event) print "Plugin xchatlogger loaded!" xchat.hook_unload(unload_cb) # vim:ts=4:sw=4:et