summaryrefslogtreecommitdiff
path: root/logger.py
diff options
context:
space:
mode:
Diffstat (limited to 'logger.py')
-rw-r--r--logger.py353
1 files changed, 174 insertions, 179 deletions
diff --git a/logger.py b/logger.py
index c2bd571..244ce86 100644
--- a/logger.py
+++ b/logger.py
@@ -21,9 +21,12 @@ modemapping = dict(Y="ircop", q="owner",
def LoggerReload(log):
newlog = Logger(logroot=log.logroot)
- for IRC, label in log.labels.items():
- IRC.rmAddon(log)
- IRC.addAddon(newlog, label=label)
+ with newlog.rotatelock, log.rotatelock:
+ newlog.logs = log.logs
+ log.logs = {}
+ for context, label in log.labels.items():
+ context.rmAddon(log)
+ context.addAddon(newlog, label=label)
return newlog
@@ -63,75 +66,80 @@ class Logger(Thread):
if all([not log or log.closed for log in self.logs.values()]):
break
Y, M, D, h, m, s, w, d, dst = now = time.localtime()
- for IRC in self.labels.keys():
- if IRC.connected:
- with IRC.lock:
+ for context in self.labels.keys():
+ if context.connected:
+ with context.lock:
try:
- self.rotateLog(IRC)
+ self.rotateLog(context)
except:
exc, excmsg, tb = sys.exc_info()
- IRC.logwrite(*["!!! [Logger] Exception in module %(module)s" % vars()] + [
- "!!! [Logger] %s" % tbline for tbline in traceback.format_exc().split("\n")])
- if IRC.identity:
- for channel in IRC.identity.channels:
+ context.logwrite(*["!!! [Logger] Exception in module %(module)s" % vars()] + [
+ "!!! [Logger] %s" % tbline for tbline in traceback.format_exc().split("\n")])
+ if context.identity:
+ for channel in context.identity.channels:
try:
self.rotateLog(channel)
except:
exc, excmsg, tb = sys.exc_info()
- IRC.logwrite(*["!!! [Logger] Exception in module %(module)s" % vars()] + [
- "!!! [Logger] %s" % tbline for tbline in traceback.format_exc().split("\n")])
- for user in IRC.users:
+ context.logwrite(*["!!! [Logger] Exception in module %(module)s" % vars()] + [
+ "!!! [Logger] %s" % tbline for tbline in traceback.format_exc().split("\n")])
+ for user in context.users:
if user in self.logs.keys():
try:
self.closeLog(user)
except:
exc, excmsg, tb = sys.exc_info()
- IRC.logwrite(*["!!! [Logger] Exception in module %(module)s" % vars()] + [
- "!!! [Logger] %s" % tbline for tbline in traceback.format_exc().split("\n")])
- IRC.logopen(
- os.path.join(self.logroot, self.labels[IRC], "rawdata-%04d.%02d.%02d.log" % now[:3]))
+ context.logwrite(*["!!! [Logger] Exception in module %(module)s" % vars()] + [
+ "!!! [Logger] %s" % tbline for tbline in traceback.format_exc().split("\n")])
+ context.logopen(
+ os.path.join(self.logroot, self.labels[context], "rawdata-%04d.%02d.%02d.log" % now[:3]))
nextrotate = int(time.mktime((Y, M, D + 1, 0, 0, 0, 0, 0, -1)))
finally:
Thread.__init__(self)
self.daemon = True
- def onAddonAdd(self, IRC, label):
+ def onAddonAdd(self, context, label):
if label in self.labels.values():
raise BaseException, "Label already exists"
- if IRC in self.labels.keys():
+ if context in self.labels.keys():
raise BaseException, "Network already exists"
if not os.path.isdir(os.path.join(self.logroot, label)):
os.mkdir(os.path.join(self.logroot, label))
- self.labels[IRC] = label
- if IRC.connected:
- self.openLog(IRC)
- if IRC.identity:
- for channel in IRC.identity.channels:
+ self.labels[context] = label
+ if context.connected:
+ self.openLog(context)
+ if context.identity:
+ for channel in context.identity.channels:
self.openLog(channel)
now = time.localtime()
timestamp = reduce(lambda x, y: x + ":" + y, [
str(t).rjust(2, "0") for t in now[0:6]])
- IRC.logopen(
- os.path.join(self.logroot, self.labels[IRC], "rawdata-%04d.%02d.%02d.log" % now[:3]))
+ context.logopen(
+ os.path.join(self.logroot, self.labels[context], "rawdata-%04d.%02d.%02d.log" % now[:3]))
- def onAddonRem(self, IRC):
- if IRC.connected:
+ def onAddonRem(self, context):
+ if context.connected:
for channel in self.logs.keys():
- if channel in IRC.channels:
+ if channel in context.channels:
if not self.logs[channel].closed:
self.closeLog(channel)
for user in self.logs.keys():
- if user in IRC.users:
+ if user in context.users:
if not self.logs[user].closed:
self.closeLog(user)
- if not self.logs[IRC].closed:
- self.closeLog(IRC)
- del self.labels[IRC]
+ if context in self.logs.keys() and not self.logs[context].closed:
+ self.closeLog(context)
+ del self.labels[context]
def openLog(self, window):
with self.rotatelock:
if not self.isAlive():
self.start()
+
+ if window in self.logs.keys():
+ # Don't do anything
+ return
+
now = time.localtime()
timestamp = reduce(lambda x, y: x + ":" + y, [
str(t).rjust(2, "0") for t in now[0:6]])
@@ -139,42 +147,27 @@ class Logger(Thread):
log = self.logs[window] = codecs.open(
os.path.join(self.logroot, self.labels[window], "console-%04d.%02d.%02d.log" % now[:3]), "a", encoding="utf8")
print >>log, "%s ### Log file opened" % (irc.timestamp())
+
elif type(window) == irc.Channel:
label = self.labels[window.context]
log = self.logs[window] = codecs.open(os.path.join(self.logroot, label, "channel-%s-%04d.%02d.%02d.log" % (
- (urllib2.quote(window.name.lower()).replace("/", "%2f"),) + now[:3])), "a", encoding="utf8")
+ (urllib2.quote(window.name.lower().decode("utf8")).replace("/", "%2f"),) + now[:3])), "a", encoding="utf8")
print >>log, "%s ### Log file opened" % (irc.timestamp())
self.logs[window].flush()
- if window.context.identity in window.users:
+ if window in window.context.identity.channels:
if window.topic:
- print >>log, "%s <<< :%s 332 %s %s :%s" % (
- irc.timestamp(), window.context.serv, window.context.identity.nick, window.name, window.topic)
- if window.topicsetby and window.topictime:
- print >>log, "%s <<< :%s 333 %s %s %s %s" % (
- irc.timestamp(), window.context.serv, window.context.identity.nick, window.name, window.topicsetby, window.topictime)
+ for line in window.fmttopic():
+ print >>log, "%s <<< %s" % (irc.timestamp(), line)
if window.users:
- secret = "s" in window.modes.keys() and window.modes["s"]
- private = "p" in window.modes.keys() and window.modes["p"]
- namesusers = []
- modes, symbols = window.context.supports["PREFIX"]
- print >>log, "%s <<< :%s 353 %s %s %s :%s" % (irc.timestamp(),
- window.context.serv,
- window.context.identity.nick,
- "@" if secret else (
- "*" if private else "="),
- window.name,
- " ".join(["".join([symbols[k] if modes[k] in window.modes.keys() and user in window.modes[modes[k]] else "" for k in xrange(len(modes))]) + user.nick for user in window.users]))
+ for line in window.fmtnames(sort="mode"):
+ print >>log, "%s <<< %s" % (irc.timestamp(), line)
if window.modes:
- modes = window.modes.keys()
- modestr = "".join([mode for mode in modes if mode not in window.context.supports[
- "CHANMODES"][0] + window.context.supports["PREFIX"][0] and window.modes[mode]])
- params = " ".join([window.modes[mode] for mode in modes if mode in window.context.supports[
- "CHANMODES"][1] + window.context.supports["CHANMODES"][2] and window.modes[mode]])
- print >>log, "%s <<< :%s 324 %s %s +%s %s" % (
- irc.timestamp(), window.context.serv, window.context.identity.nick, window.name, modestr, params)
+ print >>log, "%s <<< %s" % (
+ irc.timestamp(), window.fmtmodes())
if window.created:
- print >>log, "%s <<< :%s 329 %s %s %s" % (
- irc.timestamp(), window.context.serv, window.context.identity.nick, window.name, window.created)
+ print >>log, "%s <<< %s" % (
+ irc.timestamp(), window.fmtchancreated())
+
if type(window) == irc.User:
logname = os.path.join(self.logroot, self.labels[window.context], "query-%s-%04d.%02d.%02d.log" % (
(urllib2.quote(window.nick.lower()).replace("/", "%2f"),) + now[:3]))
@@ -194,7 +187,7 @@ class Logger(Thread):
log.flush()
def closeLog(self, window):
- if window in self.logs.keys() and type(self.logs[window]) == file and not self.logs[window].closed:
+ if window in self.logs.keys() and isinstance(self.logs[window], codecs.StreamReaderWriter) and not self.logs[window].closed:
print >>self.logs[
window], "%s ### Log file closed" % (irc.timestamp())
self.logs[window].close()
@@ -205,56 +198,56 @@ class Logger(Thread):
self.closeLog(window)
self.openLog(window)
- def onConnectAttempt(self, IRC):
- if IRC not in self.logs.keys() or (not self.logs[IRC]) or self.logs[IRC].closed:
- self.openLog(IRC)
+ def onConnectAttempt(self, context):
+ if context not in self.logs.keys() or (not self.logs[context]) or self.logs[context].closed:
+ self.openLog(context)
ts = irc.timestamp()
- print >>self.logs[IRC], "%s *** Attempting connection to %s:%s." % (
- ts, IRC.server, IRC.port)
+ print >>self.logs[context], "%s *** Attempting connection to %s:%s." % (
+ ts, context.server, context.port)
- def onConnect(self, IRC):
- if IRC not in self.logs.keys() or (not self.logs[IRC]) or self.logs[IRC].closed:
- self.openLog(IRC)
+ def onConnect(self, context):
+ if context not in self.logs.keys() or (not self.logs[context]) or self.logs[context].closed:
+ self.openLog(context)
ts = irc.timestamp()
- print >>self.logs[IRC], "%s *** Connection to %s:%s established." % (
- ts, IRC.server, IRC.port)
+ print >>self.logs[context], "%s *** Connection to %s:%s established." % (
+ ts, context.server, context.port)
- def onConnectFail(self, IRC, exc, excmsg, tb):
+ def onConnectFail(self, context, exc, excmsg, tb):
# Called when a connection attempt fails.
- if IRC not in self.logs.keys() or (not self.logs[IRC]) or self.logs[IRC].closed:
- self.openLog(IRC)
+ if context not in self.logs.keys() or (not self.logs[context]) or self.logs[context].closed:
+ self.openLog(context)
ts = irc.timestamp()
- print >>self.logs[IRC], "%s *** Connection to %s:%s failed: %s." % (
- ts, IRC.server, IRC.port, excmsg)
+ print >>self.logs[context], "%s *** Connection to %s:%s failed: %s." % (
+ ts, context.server, context.port, excmsg)
- def onDisconnect(self, IRC, expected=False):
+ def onDisconnect(self, context, expected=False):
ts = irc.timestamp()
for window in self.logs.keys():
- if type(window) in (irc.Channel, irc.User) and window.context == IRC:
+ if type(window) in (irc.Channel, irc.User) and window.context == context:
print >>self.logs[window], "%s *** Connection to %s:%s terminated." % (
- ts, IRC.server, IRC.port)
+ ts, context.server, context.port)
self.logs[window].flush()
self.closeLog(window)
- print >>self.logs[IRC], "%s *** Connection %s:%s terminated." % (
- ts, IRC.server, IRC.port)
- self.logs[IRC].flush()
- self.closeLog(IRC)
+ print >>self.logs[context], "%s *** Connection %s:%s terminated." % (
+ ts, context.server, context.port)
+ self.logs[context].flush()
+ self.closeLog(context)
- def onJoin(self, IRC, user, channel):
+ def onJoin(self, context, user, channel):
# Called when somebody joins a channel, includes bot.
- ts = irc.timestamp()
- if user == IRC.identity:
+ if user == context.identity:
self.openLog(channel)
+ ts = irc.timestamp()
print >>self.logs[channel], "%s <<< :%s!%s@%s JOIN %s" % (
ts, user.nick, user.username, user.host, channel.name)
self.logs[channel].flush()
- def onChanMsg(self, IRC, user, channel, targetprefix, msg):
+ def onChanMsg(self, context, user, channel, targetprefix, msg):
# Called when someone sends a PRIVMSG to channel.
ts = irc.timestamp()
if type(user) == irc.User:
classes = " ".join([modemapping[mode]
- for mode in IRC.supports["PREFIX"][0] if mode in channel.modes.keys() and user in channel.modes[mode]])
+ for mode in context.supports["PREFIX"][0] if mode in channel.modes.keys() and user in channel.modes[mode]])
if classes:
print >>self.logs[channel], "%s %s <<< :%s!%s@%s PRIVMSG %s%s :%s" % (
ts, classes, user.nick, user.username, user.host, targetprefix, channel.name, msg)
@@ -267,16 +260,16 @@ class Logger(Thread):
ts, classes, user, targetprefix, channel.name, msg)
self.logs[channel].flush()
- def onChanAction(self, IRC, user, channel, targetprefix, action):
- self.onChanMsg(
- IRC, user, channel, targetprefix, "\x01ACTION %s\x01" % action)
+ def onChanAction(self, context, user, channel, targetprefix, action):
+ self.onChanMsg(context, user, channel,
+ targetprefix, "\x01ACTION %s\x01" % action)
- def onChanNotice(self, IRC, origin, channel, targetprefix, msg):
+ def onChanNotice(self, context, origin, channel, targetprefix, msg):
# Called when someone sends a NOTICE to channel.
ts = irc.timestamp()
if type(origin) == irc.User:
classes = " ".join([modemapping[mode]
- for mode in IRC.supports["PREFIX"][0] if mode in channel.modes.keys() and origin in channel.modes[mode]])
+ for mode in context.supports["PREFIX"][0] if mode in channel.modes.keys() and origin in channel.modes[mode]])
if classes:
print >>self.logs[channel], "%s %s <<< :%s!%s@%s NOTICE %s%s :%s" % (
ts, classes, origin.nick, origin.username, origin.host, targetprefix, channel.name, msg)
@@ -289,7 +282,7 @@ class Logger(Thread):
ts, classes, origin, targetprefix, channel.name, msg)
self.logs[channel].flush()
- def onPart(self, IRC, user, channel, partmsg):
+ def onPart(self, context, user, channel, partmsg):
# Called when somebody parts the channel, includes bot.
ts = irc.timestamp()
if partmsg:
@@ -299,10 +292,10 @@ class Logger(Thread):
print >>self.logs[channel], "%s <<< :%s!%s@%s PART %s" % (
ts, user.nick, user.username, user.host, channel.name)
self.logs[channel].flush()
- if user == IRC.identity:
+ if user == context.identity:
self.closeLog(channel)
- def onKick(self, IRC, kicker, channel, kicked, kickmsg):
+ def onKick(self, context, kicker, channel, kicked, kickmsg):
# Called when somebody is kicked from the channel, includes bot.
ts = irc.timestamp()
if kickmsg:
@@ -312,60 +305,61 @@ class Logger(Thread):
print >>self.logs[channel], "%s <<< :%s!%s@%s KICK %s %s" % (
ts, user.nick, user.username, user.host, channel.name, kicked.nick)
self.logs[channel].flush()
- if kicked == IRC.identity:
+ if kicked == context.identity:
self.closeLog(channel)
- def onSendChanMsg(self, IRC, origin, channel, targetprefix, msg):
+ def onSendChanMsg(self, context, origin, channel, targetprefix, msg):
# Called when bot sends a PRIVMSG to channel.
# The variable origin refers to a class instance voluntarily
# identifying itself as that which requested data be sent.
ts = irc.timestamp()
classes = " ".join([modemapping[mode]
- for mode in IRC.supports["PREFIX"][0] if mode in channel.modes.keys() and IRC.identity in channel.modes[mode]])
+ for mode in context.supports["PREFIX"][0] if mode in channel.modes.keys() and context.identity in channel.modes[mode]])
if classes:
print >>self.logs[channel], "%s %s >>> :%s!%s@%s PRIVMSG %s%s :%s" % (
- ts, classes, IRC.identity.nick, IRC.identity.username, IRC.identity.host, targetprefix, channel.name, msg)
+ ts, classes, context.identity.nick, context.identity.username, context.identity.host, targetprefix, channel.name, msg)
else:
print >>self.logs[channel], "%s >>> :%s!%s@%s PRIVMSG %s%s :%s" % (
- ts, IRC.identity.nick, IRC.identity.username, IRC.identity.host, targetprefix, channel.name, msg)
+ ts, context.identity.nick, context.identity.username, context.identity.host, targetprefix, channel.name, msg)
self.logs[channel].flush()
- def onSendChanAction(self, IRC, origin, channel, targetprefix, action):
+ def onSendChanAction(self, context, origin, channel, targetprefix, action):
# origin is the source of the channel message
# Called when bot sends an action (/me) to channel.
# The variable origin refers to a class instance voluntarily
# identifying itself as that which requested data be sent.
self.onSendChanMsg(
- IRC, origin, channel, targetprefix, "\x01ACTION %s\x01" % action)
+ context, origin, channel, targetprefix, "\x01ACTION %s\x01" % action)
- def onPrivMsg(self, IRC, user, msg):
+ def onPrivMsg(self, context, user, msg):
# Called when someone sends a PRIVMSG to the bot.
if user not in self.logs.keys():
self.openLog(user)
ts = irc.timestamp()
print >>self.logs[user], "%s <<< :%s!%s@%s PRIVMSG %s :%s" % (
- ts, user.nick, user.username, user.host, IRC.identity.nick, msg)
+ ts, user.nick, user.username, user.host, context.identity.nick, msg)
self.logs[user].flush()
- def onPrivNotice(self, IRC, origin, msg):
+ def onPrivNotice(self, context, origin, msg):
# Called when someone sends a NOTICE to the bot.
ts = irc.timestamp()
if type(origin) == irc.User:
if origin not in self.logs.keys():
self.openLog(origin)
+ ts = irc.timestamp()
print >>self.logs[origin], "%s <<< :%s!%s@%s NOTICE %s :%s" % (
- ts, origin.nick, origin.username, origin.host, IRC.identity.nick, msg)
+ ts, origin.nick, origin.username, origin.host, context.identity.nick, msg)
self.logs[origin].flush()
else:
- print >>self.logs[IRC], "%s <<< :%s NOTICE %s :%s" % (
- ts, origin, IRC.identity.nick, msg)
- self.logs[IRC].flush()
+ print >>self.logs[context], "%s <<< :%s NOTICE %s :%s" % (
+ ts, origin, context.identity.nick, msg)
+ self.logs[context].flush()
- def onPrivAction(self, IRC, user, action):
+ def onPrivAction(self, context, user, action):
# Called when someone sends an action (/me) to the bot.
- self.onPrivMsg(IRC, user, "\x01ACTION %s\x01" % action)
+ self.onPrivMsg(context, user, "\x01ACTION %s\x01" % action)
- def onSendPrivMsg(self, IRC, origin, user, msg):
+ def onSendPrivMsg(self, context, origin, user, msg):
# Called when bot sends a PRIVMSG to a user.
# The variable origin refers to a class instance voluntarily
# identifying itself as that which requested data be sent.
@@ -373,16 +367,16 @@ class Logger(Thread):
self.openLog(user)
ts = irc.timestamp()
print >>self.logs[user], "%s >>> :%s!%s@%s PRIVMSG %s :%s" % (
- ts, IRC.identity.nick, IRC.identity.username, IRC.identity.host, user.nick, msg)
+ ts, context.identity.nick, context.identity.username, context.identity.host, user.nick, msg)
self.logs[user].flush()
- def onSendPrivAction(self, IRC, origin, user, action):
+ def onSendPrivAction(self, context, origin, user, action):
# Called when bot sends an action (/me) to a user.
# The variable origin refers to a class instance voluntarily
# identifying itself as that which requested data be sent.
- self.onSendPrivMsg(IRC, origin, user, "\x01ACTION %s\x01" % action)
+ self.onSendPrivMsg(context, origin, user, "\x01ACTION %s\x01" % action)
- def onNickChange(self, IRC, user, newnick):
+ def onNickChange(self, context, user, newnick):
# Called when somebody changes nickname.
ts = irc.timestamp()
line = "%s <<< :%s!%s@%s NICK %s" % (
@@ -390,29 +384,30 @@ class Logger(Thread):
# Print nick change in each channel the user is in.
for channel in user.channels:
- print >>self.logs[channel], line
- self.logs[channel].flush()
+ if channel in context.identity.channels:
+ print >>self.logs[channel], line
+ self.logs[channel].flush()
# And in the query if open.
if user in self.logs.keys():
print >>self.logs[user], line
self.logs[user].flush()
- def onMeNickChange(self, IRC, newnick):
+ def onMeNickChange(self, context, newnick):
# Called when the bot changes nickname.
# Print nick change to all open queries, except for query with self
# (already done with onNickChange).
ts = irc.timestamp()
line = "%s <<< :%s!%s@%s NICK %s" % (
- ts, IRC.identity.nick, IRC.identity.username, IRC.identity.host, newnick)
+ ts, context.identity.nick, context.identity.username, context.identity.host, newnick)
for (window, log) in self.logs.items():
- if type(window) == irc.User and window != IRC.identity:
+ if type(window) == irc.User and window != context.identity:
print >>log, line
log.flush()
- def onQuit(self, IRC, user, quitmsg):
- # Called when somebody quits IRC.
+ def onQuit(self, context, user, quitmsg):
+ # Called when somebody quits context.
ts = irc.timestamp()
if quitmsg:
line = "%s <<< :%s!%s@%s QUIT :%s" % (
@@ -423,7 +418,7 @@ class Logger(Thread):
# Print quit in each channel the user was in.
for channel in user.channels:
- if channel in self.logs.keys() and not self.logs[channel].closed:
+ if channel in context.identity.channels and channel in self.logs.keys() and not self.logs[channel].closed:
print >>self.logs[channel], line
self.logs[channel].flush()
@@ -433,152 +428,152 @@ class Logger(Thread):
self.logs[user].flush()
self.closeLog(user)
- def onNames(self, IRC, origin, channel, flag, channame, nameslist):
+ def onNames(self, context, origin, channel, flag, channame, nameslist):
# Called when a NAMES list is received.
if channel in self.logs.keys() and not self.logs[channel].closed:
log = self.logs[channel]
else:
- log = self.logs[IRC]
+ log = self.logs[context]
ts = irc.timestamp()
secret = "s" in channel.modes.keys() and channel.modes["s"]
private = "p" in channel.modes.keys() and channel.modes["p"]
modes, symbols = channel.context.supports["PREFIX"]
- print >>log, "%s <<< :%s 353 %s %s %s :%s" % (ts, origin, IRC.identity.nick, flag, channame,
+ print >>log, "%s <<< :%s 353 %s %s %s :%s" % (ts, origin, context.identity.nick, flag, channame,
" ".join(["%s%s!%s@%s" % (prefix, nick, username, host) if username and host else "%s%s" % (prefix, nick) for (prefix, nick, username, host) in nameslist]))
log.flush()
- def onNamesEnd(self, IRC, origin, channel, channame, endmsg):
+ def onNamesEnd(self, context, origin, channel, channame, endmsg):
if channel in self.logs.keys() and not self.logs[channel].closed:
log = self.logs[channel]
else:
- log = self.logs[IRC]
+ log = self.logs[context]
ts = irc.timestamp()
print >>log, "%s <<< :%s 366 %s %s :%s" % (
- ts, origin, IRC.identity.nick, channame, endmsg)
+ ts, origin, context.identity.nick, channame, endmsg)
log.flush()
- def onWhoisStart(self, IRC, origin, user, nickname, username, host, realname):
+ def onWhoisStart(self, context, origin, user, nickname, username, host, realname):
# Called when a WHOIS reply is received.
if user not in self.logs.keys():
self.openLog(user)
print >>self.logs[user], "%s <<< :%s 311 %s %s %s %s * :%s" % (
- irc.timestamp(), origin, IRC.identity.nick, nickname, username, host, realname)
+ irc.timestamp(), origin, context.identity.nick, nickname, username, host, realname)
- def onWhoisRegisteredNick(self, IRC, origin, user, nickname, msg):
+ def onWhoisRegisteredNick(self, context, origin, user, nickname, msg):
# Called when a WHOIS reply is received.
if user not in self.logs.keys():
self.openLog(user)
print >>self.logs[user], "%s <<< :%s 307 %s %s :%s" % (
- irc.timestamp(), origin, IRC.identity.nick, nickname, msg)
+ irc.timestamp(), origin, context.identity.nick, nickname, msg)
- def onWhoisAway(self, IRC, origin, user, nickname, awaymsg):
+ def onWhoisAway(self, context, origin, user, nickname, awaymsg):
# Called when a WHOIS reply is received.
if user not in self.logs.keys():
self.openLog(user)
print >>self.logs[user], "%s <<< :%s 301 %s %s :%s" % (
- irc.timestamp(), origin, IRC.identity.nick, nickname, awaymsg)
+ irc.timestamp(), origin, context.identity.nick, nickname, awaymsg)
- def onWhoisConnectingFrom(self, IRC, origin, user, nickname, msg):
+ def onWhoisConnectingFrom(self, context, origin, user, nickname, msg):
# Called when a WHOIS reply is received.
if user not in self.logs.keys():
self.openLog(user)
print >>self.logs[user], "%s <<< :%s 378 %s %s :%s" % (
- irc.timestamp(), origin, IRC.identity.nick, nickname, msg)
+ irc.timestamp(), origin, context.identity.nick, nickname, msg)
- def onWhoisChannels(self, IRC, origin, user, nickname, chanlist):
+ def onWhoisChannels(self, context, origin, user, nickname, chanlist):
# Called when a WHOIS reply is received.
if user not in self.logs.keys():
self.openLog(user)
print >>self.logs[user], "%s <<< :%s 319 %s %s :%s" % (
- irc.timestamp(), origin, IRC.identity.nick, nickname, " ".join(chanlist))
+ irc.timestamp(), origin, context.identity.nick, nickname, " ".join(chanlist))
- def onWhoisAvailability(self, IRC, origin, user, nickname, msg):
+ def onWhoisAvailability(self, context, origin, user, nickname, msg):
# Called when a WHOIS reply is received.
if user not in self.logs.keys():
self.openLog(user)
print >>self.logs[user], "%s <<< :%s 310 %s %s :%s" % (
- irc.timestamp(), origin, IRC.identity.nick, nickname, msg)
+ irc.timestamp(), origin, context.identity.nick, nickname, msg)
- def onWhoisServer(self, IRC, origin, user, nickname, server, servername):
+ def onWhoisServer(self, context, origin, user, nickname, server, servername):
# Called when a WHOIS reply is received.
if user not in self.logs.keys():
self.openLog(user)
print >>self.logs[user], "%s <<< :%s 312 %s %s %s :%s" % (
- irc.timestamp(), origin, IRC.identity.nick, nickname, server, servername)
+ irc.timestamp(), origin, context.identity.nick, nickname, server, servername)
- def onWhoisOp(self, IRC, origin, user, nickname, msg):
+ def onWhoisOp(self, context, origin, user, nickname, msg):
if user not in self.logs.keys():
self.openLog(user)
print >>self.logs[user], "%s <<< :%s 313 %s %s :%s" % (
- irc.timestamp(), origin, IRC.identity.nick, nickname, msg)
+ irc.timestamp(), origin, context.identity.nick, nickname, msg)
- def onWhoisTimes(self, IRC, origin, user, nickname, idletime, signontime, msg):
+ def onWhoisTimes(self, context, origin, user, nickname, idletime, signontime, msg):
if user not in self.logs.keys():
self.openLog(user)
print >>self.logs[user], "%s <<< :%s 317 %s %s %d %d :%s" % (
- irc.timestamp(), origin, IRC.identity.nick, nickname, idletime, signontime, msg)
+ irc.timestamp(), origin, context.identity.nick, nickname, idletime, signontime, msg)
- def onWhoisSSL(self, IRC, origin, user, nickname, msg):
+ def onWhoisSSL(self, context, origin, user, nickname, msg):
if user not in self.logs.keys():
self.openLog(user)
print >>self.logs[user], "%s <<< :%s 671 %s %s :%s" % (
- irc.timestamp(), origin, IRC.identity.nick, nickname, msg)
+ irc.timestamp(), origin, context.identity.nick, nickname, msg)
- def onWhoisModes(self, IRC, origin, user, nickname, msg):
+ def onWhoisModes(self, context, origin, user, nickname, msg):
if user not in self.logs.keys():
self.openLog(user)
print >>self.logs[user], "%s <<< :%s 339 %s %s :%s" % (
- irc.timestamp(), origin, IRC.identity.nick, nickname, msg)
+ irc.timestamp(), origin, context.identity.nick, nickname, msg)
- def onWhoisLoggedInAs(self, IRC, origin, user, nickname, loggedinas, msg):
+ def onWhoisLoggedInAs(self, context, origin, user, nickname, loggedinas, msg):
if user not in self.logs.keys():
self.openLog(user)
print >>self.logs[user], "%s <<< :%s 330 %s %s %s :%s" % (
- irc.timestamp(), origin, IRC.identity.nick, nickname, loggedinas, msg)
+ irc.timestamp(), origin, context.identity.nick, nickname, loggedinas, msg)
- def onWhoisEnd(self, IRC, origin, user, nickname, msg):
+ def onWhoisEnd(self, context, origin, user, nickname, msg):
if user not in self.logs.keys():
self.openLog(user)
print >>self.logs[user], "%s <<< :%s 318 %s %s :%s" % (
- irc.timestamp(), origin, IRC.identity.nick, nickname, msg)
+ irc.timestamp(), origin, context.identity.nick, nickname, msg)
self.logs[user].flush()
- def onWhoEntry(self, IRC, **kwargs):
+ def onWhoEntry(self, context, **kwargs):
# Called when a WHO list is received.
pass
- def onWhoEnd(self, IRC, **kwargs):
+ def onWhoEnd(self, context, **kwargs):
# Called when a WHO list is received.
pass
- def onList(self, IRC, chanlistbegin, chanlist, endmsg):
+ def onList(self, context, chanlistbegin, chanlist, endmsg):
# Called when a channel list is received.
pass
- def onTopic(self, IRC, origin, channel, topic):
+ def onTopic(self, context, origin, channel, topic):
# Called when channel topic is received via 332 response.
ts = irc.timestamp()
if channel in self.logs.keys() and not self.logs[channel].closed:
log = self.logs[channel]
else:
- log = self.logs[IRC]
+ log = self.logs[context]
print >>log, "%s <<< :%s 332 %s %s :%s" % (
- ts, origin, IRC.identity.nick, channel.name, topic)
+ ts, origin, context.identity.nick, channel.name, topic)
log.flush()
- def onTopicInfo(self, IRC, origin, channel, topicsetby, topictime):
+ def onTopicInfo(self, context, origin, channel, topicsetby, topictime):
# Called when channel topic info is received via 333 response.
ts = irc.timestamp()
if channel in self.logs.keys() and not self.logs[channel].closed:
log = self.logs[channel]
else:
- log = self.logs[IRC]
+ log = self.logs[context]
print >>log, "%s <<< :%s 333 %s %s %s %d" % (
- ts, origin, IRC.identity.nick, channel.name, topicsetby, topictime)
+ ts, origin, context.identity.nick, channel.name, topicsetby, topictime)
log.flush()
- def onTopicSet(self, IRC, user, channel, topic):
+ def onTopicSet(self, context, user, channel, topic):
# Called when channel topic is changed.
ts = irc.timestamp()
if type(user) == irc.User:
@@ -589,7 +584,7 @@ class Logger(Thread):
ts, user, channel.name, topic)
self.logs[channel].flush()
- def onChanModeSet(self, IRC, user, channel, modedelta):
+ def onChanModeSet(self, context, user, channel, modedelta):
# Called when channel modes are changed.
# modedelta is a list of tuples of the format ("+x", parameter), ("+x",
# None) if no parameter is provided.
@@ -620,13 +615,13 @@ class Logger(Thread):
ts, user, channel.name, modestr)
self.logs[channel].flush()
- def onChannelModes(self, IRC, channel, modedelta):
+ def onChannelModes(self, context, origin, channel, modedelta):
# Called when channel modes are received via 324 response.
ts = irc.timestamp()
if channel in self.logs.keys() and not self.logs[channel].closed:
log = self.logs[channel]
else:
- log = self.logs[IRC]
+ log = self.logs[context]
modestr = ""
params = []
sign = ""
@@ -639,24 +634,24 @@ class Logger(Thread):
params.append(param)
if len(params):
print >>log, "%s <<< :%s 324 %s %s %s %s" % (
- ts, IRC.serv, IRC.identity.nick, channel.name, modestr, " ".join(params))
+ ts, origin, context.identity.nick, channel.name, modestr, " ".join(params))
else:
print >>log, "%s <<< :%s 324 %s %s %s" % (
- ts, IRC.serv, IRC.identity.nick, channel.name, modestr)
+ ts, origin, context.identity.nick, channel.name, modestr)
log.flush()
- def onChanCreated(self, IRC, channel, created):
+ def onChanCreated(self, context, origin, channel, created):
# Called when a 329 response is received.
ts = irc.timestamp()
if channel in self.logs.keys() and not self.logs[channel].closed:
log = self.logs[channel]
else:
- log = self.logs[IRC]
+ log = self.logs[context]
print >>log, "%s <<< :%s 329 %s %s %d" % (
- ts, IRC.serv, IRC.identity.nick, channel.name, created)
+ ts, origin, context.identity.nick, channel.name, created)
log.flush()
- def onUnhandled(self, IRC, line, origin, cmd, target, params, extinfo, targetprefix):
+ def onUnhandled(self, context, line, origin, cmd, target, params, extinfo, targetprefix):
ts = irc.timestamp()
- print >>self.logs[IRC], "%s <<< %s" % (ts, line)
- self.logs[IRC].flush()
+ print >>self.logs[context], "%s <<< %s" % (ts, line)
+ self.logs[context].flush()