diff --git a/logging.cfg b/logging.cfg index c473aac..1912805 100644 --- a/logging.cfg +++ b/logging.cfg @@ -1,5 +1,5 @@ [loggers] -keys = root,drbotzo,irclib,drbotzo.markov,drbotzo.weather +keys = root,drbotzo,irclib,drbotzo.markov,drbotzo.weather,drbotzo.dispatch [handlers] keys = stdout,logfile @@ -29,6 +29,12 @@ handlers = stdout,logfile propagate = 0 qualname = drbotzo.markov +[logger_drbotzo.dispatch] +level = DEBUG +handlers = stdout,logfile +propagate = 0 +qualname = drbotzo.dispatch + [logger_drbotzo.weather] level = DEBUG handlers = stdout,logfile diff --git a/modules/Dispatch.py b/modules/Dispatch.py index 00e89c1..477f2c5 100644 --- a/modules/Dispatch.py +++ b/modules/Dispatch.py @@ -18,6 +18,9 @@ along with this program. If not, see . """ import MySQLdb as mdb +import os + +from extlib import irclib from Module import Module @@ -94,9 +97,17 @@ class Dispatch(Module): notified = [] for key, dest in self._get_key_and_destination(key): - msg = "[{0:s}] {1:s}".format(key, message.encode('utf-8', 'ignore')) - self.sendmsg(dest, msg) - notified.append(dest) + if irclib.is_channel(dest): + msg = "[{0:s}] {1:s}".format(key, message.encode('utf-8', 'ignore')) + self.sendmsg(dest, msg) + notified.append(dest) + elif dest.find('FILE:') == 0: + filename = dest.replace('FILE:', '') + filename = os.path.abspath(filename) + self.log.info("filename: {0:s}".format(filename)) + msg = "[{0:s}] {1:s}\n".format(key, message.encode('utf-8', 'ignore')) + with open(filename, 'w') as f: + f.write(msg) return notified