index : logbot | |
Archlinux32 log bot | gitolite user |
summaryrefslogtreecommitdiff |
author | Chris Oliver <excid3@gmail.com> | 2012-06-08 17:12:36 -0700 |
---|---|---|
committer | Chris Oliver <excid3@gmail.com> | 2012-06-08 17:12:36 -0700 |
commit | 82814fa304d4130005ff61563370bd15ce06b791 (patch) | |
tree | 6aeb0e41896cd227bda4b56cb44fa4362314f70f /logbot.py | |
parent | 0be9eac469c7eb7699042288060d9b65eea48a53 (diff) | |
parent | 9b30109af83121b675b03c9b27dc895fc8426fe4 (diff) |
-rwxr-xr-x[-rw-r--r--] | logbot.py | 35 |
diff --git a/logbot.py b/logbot.py index 8691d9d..3e54ec8 100644..100755 --- a/logbot.py +++ b/logbot.py @@ -199,11 +199,14 @@ class Logbot(SingleServerIRCBot): def write_event(self, name, event, params={}): # Format the event properly - chans = event.target() + if name == 'nick' or name == 'quit': + chans = params["%chan%"] + else: + chans = event.target() msg = self.format_event(name, event, params) msg = urlify2(msg) - # Quit goes across all channels + # In case there are still events that don't supply a channel name (like /quit and /nick did) if not chans or not chans.startswith("#"): chans = self.chans else: @@ -246,6 +249,9 @@ class Logbot(SingleServerIRCBot): def append_log_msg(self, channel, msg): print "%s >>> %s" % (channel, msg) + #Make sure the channel is always lowercase to prevent logs with other capitalisations to be created + channel_title = channel + channel = channel.lower() # Create the channel path if necessary chan_path = "%s/%s" % (LOG_FOLDER, channel) @@ -253,10 +259,10 @@ class Logbot(SingleServerIRCBot): os.makedirs(chan_path) # Create channel index - write_string("%s/index.html" % chan_path, html_header.replace("%title%", "%s | Logs" % channel)) + write_string("%s/index.html" % chan_path, html_header.replace("%title%", "%s | Logs" % channel_title)) # Append channel to log index - append_line("%s/index.html" % LOG_FOLDER, '<a href="%s/index.html">%s</a>' % (channel.replace("#", "%23"), channel)) + append_line("%s/index.html" % LOG_FOLDER, '<a href="%s/index.html">%s</a>' % (channel.replace("#", "%23"), channel_title)) # Current log time = strftime("%H:%M:%S") @@ -265,7 +271,7 @@ class Logbot(SingleServerIRCBot): # Create the log date index if it doesnt exist if not os.path.exists(log_path): - write_string(log_path, html_header.replace("%title%", "%s | Logs for %s" % (channel, date))) + write_string(log_path, html_header.replace("%title%", "%s | Logs for %s" % (channel_title, date))) # Append date log append_line("%s/index.html" % chan_path, '<a href="%s.html">%s</a>' % (date, date)) @@ -323,10 +329,15 @@ class Logbot(SingleServerIRCBot): }) def on_nick(self, c, e): - self.write_event("nick", e, - {"%old%" : nm_to_n(e.source()), - "%new%" : e.target(), - }) + old_nick = nm_to_n(e.source()) + # Only write the event on channels that actually had the user in the channel + for chan in self.channels: + if old_nick in [x.lstrip('~%&@+') for x in self.channels[chan].users()]: + self.write_event("nick", e, + {"%old%" : old_nick, + "%new%" : e.target(), + "%chan%": chan, + }) def on_part(self, c, e): self.write_event("part", e) @@ -344,7 +355,11 @@ class Logbot(SingleServerIRCBot): c.privmsg(nm_to_n(e.source()), self.format["help"]) def on_quit(self, c, e): - self.write_event("quit", e) + nick = nm_to_n(e.source()) + # Only write the event on channels that actually had the user in the channel + for chan in self.channels: + if nick in [x.lstrip('~%&@+') for x in self.channels[chan].users()]: + self.write_event("quit", e, {"%chan%" : chan}) def on_topic(self, c, e): self.write_event("topic", e) |