ChannelLogger && ChannelStats && Limiter && Relay && Seen: Use new QUIT and NICK 'channels' tag instead of copying the state.

This commit is contained in:
Valentin Lorentz 2015-12-04 13:30:07 +01:00
parent 3b78fd2424
commit 2937152dc1
5 changed files with 24 additions and 108 deletions

View File

@ -61,8 +61,6 @@ class ChannelLogger(callbacks.Plugin):
def __init__(self, irc):
self.__parent = super(ChannelLogger, self)
self.__parent.__init__(irc)
self.lastMsgs = {}
self.lastStates = {}
self.logs = {}
self.flusher = self.flush
world.flushers.append(self.flusher)
@ -72,26 +70,10 @@ class ChannelLogger(callbacks.Plugin):
log.close()
world.flushers = [x for x in world.flushers if x is not self.flusher]
def __call__(self, irc, msg):
try:
# I don't know why I put this in, but it doesn't work, because it
# doesn't call doNick or doQuit.
# if msg.args and irc.isChannel(msg.args[0]):
self.__parent.__call__(irc, msg)
if irc in self.lastMsgs:
if irc not in self.lastStates:
self.lastStates[irc] = irc.state.copy()
self.lastStates[irc].addMsg(irc, self.lastMsgs[irc])
finally:
# We must make sure this always gets updated.
self.lastMsgs[irc] = msg
def reset(self):
for log in self._logs():
log.close()
self.logs.clear()
self.lastMsgs.clear()
self.lastStates.clear()
def _logs(self):
for logs in self.logs.values():
@ -222,10 +204,9 @@ class ChannelLogger(callbacks.Plugin):
def doNick(self, irc, msg):
oldNick = msg.nick
newNick = msg.args[0]
for (channel, c) in irc.state.channels.items():
if newNick in c.users:
self.doLog(irc, channel,
'*** %s is now known as %s\n', oldNick, newNick)
for channel in msg.tagged('channels'):
self.doLog(irc, channel,
'*** %s is now known as %s\n', oldNick, newNick)
def doInvite(self, irc, msg):
(target, channel) = msg.args
@ -285,16 +266,11 @@ class ChannelLogger(callbacks.Plugin):
reason = " (%s)" % msg.args[0]
else:
reason = ""
if not isinstance(irc, irclib.Irc):
irc = irc.getRealIrc()
if irc not in self.lastStates:
return
for (channel, chan) in self.lastStates[irc].channels.items():
for channel in msg.tagged('channels'):
if(self.registryValue('showJoinParts', channel)):
if msg.nick in chan.users:
self.doLog(irc, channel,
'*** %s <%s> has quit IRC%s\n',
msg.nick, msg.prefix, reason)
self.doLog(irc, channel,
'*** %s <%s> has quit IRC%s\n',
msg.nick, msg.prefix, reason)
def outFilter(self, irc, msg):
# Gotta catch my own messages *somehow* :)

View File

@ -170,8 +170,6 @@ class ChannelStats(callbacks.Plugin):
def __init__(self, irc):
self.__parent = super(ChannelStats, self)
self.__parent.__init__(irc)
self.lastmsg = None
self.laststate = None
self.outFiltering = False
self.db = StatsDB(filename)
self._flush = self.db.flush
@ -183,13 +181,6 @@ class ChannelStats(callbacks.Plugin):
self.__parent.die()
def __call__(self, irc, msg):
try:
if self.lastmsg:
self.laststate.addMsg(irc, self.lastmsg)
else:
self.laststate = irc.state.copy()
finally:
self.lastmsg = msg
self.db.addMsg(msg)
super(ChannelStats, self).__call__(irc, msg)
@ -222,15 +213,14 @@ class ChannelStats(callbacks.Plugin):
id = ircdb.users.getUserId(msg.prefix)
except KeyError:
id = None
for (channel, c) in self.laststate.channels.items():
if msg.nick in c.users:
if (channel, 'channelStats') not in self.db:
self.db[channel, 'channelStats'] = ChannelStat()
self.db[channel, 'channelStats'].quits += 1
if id is not None:
if (channel, id) not in self.db:
self.db[channel, id] = UserStat()
self.db[channel, id].quits += 1
for channel in msg.tagged('channels'):
if (channel, 'channelStats') not in self.db:
self.db[channel, 'channelStats'] = ChannelStat()
self.db[channel, 'channelStats'].quits += 1
if id is not None:
if (channel, id) not in self.db:
self.db[channel, id] = UserStat()
self.db[channel, id].quits += 1
def doKick(self, irc, msg):
(channel, nick, _) = msg.args

View File

@ -67,7 +67,7 @@ class Limiter(callbacks.Plugin):
doKick = doJoin
def doQuit(self, irc, msg):
for channel in irc.state.channels:
for channel in msg.tagged('channels')
self._enforceLimit(irc, channel)
Limiter = internationalizeDocstring(Limiter)

View File

@ -49,21 +49,9 @@ class Relay(callbacks.Plugin):
self.__parent = super(Relay, self)
self.__parent.__init__(irc)
self._whois = {}
self.lastmsg = {}
self.ircstates = {}
self.queuedTopics = MultiSet()
self.lastRelayMsgs = ircutils.IrcDict()
def __call__(self, irc, msg):
try:
irc = self._getRealIrc(irc)
if irc not in self.ircstates:
self._addIrc(irc)
self.ircstates[irc].addMsg(irc, self.lastmsg[irc])
finally:
self.lastmsg[irc] = msg
self.__parent.__call__(irc, msg)
def do376(self, irc, msg):
networkGroup = conf.supybot.networks.get(irc.network)
for channel in self.registryValue('channels'):
@ -82,19 +70,6 @@ class Relay(callbacks.Plugin):
# We should allow abbreviations at some point.
return irc.network
def _addIrc(self, irc):
# Let's just be extra-special-careful here.
if irc not in self.ircstates:
self.ircstates[irc] = irclib.IrcState()
if irc not in self.lastmsg:
self.lastmsg[irc] = ircmsgs.ping('this is just a fake message')
if irc.afterConnect:
# We've probably been reloaded. Let's send some messages to get
# our IrcState objects up to current.
for channel in self.registryValue('channels'):
irc.queueMsg(ircmsgs.who(channel))
irc.queueMsg(ircmsgs.names(channel))
@internationalizeDocstring
def join(self, irc, msg, args, channel):
"""[<channel>]
@ -392,10 +367,8 @@ class Relay(callbacks.Plugin):
network = self._getIrcName(irc)
s = format(_('nick change by %s to %s on %s'), msg.nick,newNick,network)
for channel in self.registryValue('channels'):
if channel in irc.state.channels:
if newNick in irc.state.channels[channel].users:
m = self._msgmaker(channel, s)
self._sendToOthers(irc, m)
m = self._msgmaker(channel, s)
self._sendToOthers(irc, m)
def doTopic(self, irc, msg):
irc = self._getRealIrc(irc)
@ -433,10 +406,8 @@ class Relay(callbacks.Plugin):
else:
s = format(_('%s has quit %s.'), msg.nick, network)
for channel in self.registryValue('channels'):
if channel in self.ircstates[irc].channels:
if msg.nick in self.ircstates[irc].channels[channel].users:
m = self._msgmaker(channel, s)
self._sendToOthers(irc, m)
m = self._msgmaker(channel, s)
self._sendToOthers(irc, m)
def doError(self, irc, msg):
irc = self._getRealIrc(irc)

View File

@ -103,7 +103,6 @@ class Seen(callbacks.Plugin):
self.db = SeenDB(filename)
self.anydb = SeenDB(anyfilename)
self.lastmsg = {}
self.ircstates = {}
world.flushers.append(self.db.flush)
world.flushers.append(self.anydb.flush)
@ -121,25 +120,8 @@ class Seen(callbacks.Plugin):
self.__parent.die()
def __call__(self, irc, msg):
try:
if irc not in self.ircstates:
self._addIrc(irc)
self.ircstates[irc].addMsg(irc, self.lastmsg[irc])
finally:
self.lastmsg[irc] = msg
self.__parent.__call__(irc, msg)
def _addIrc(self, irc):
# Let's just be extra-special-careful here.
if irc not in self.ircstates:
self.ircstates[irc] = irclib.IrcState()
if irc not in self.lastmsg:
self.lastmsg[irc] = ircmsgs.ping('this is just a fake message')
if not world.testing:
for channel in irc.state.channels:
irc.queueMsg(ircmsgs.who(channel))
irc.queueMsg(ircmsgs.names(channel))
def doPrivmsg(self, irc, msg):
if ircmsgs.isCtcp(msg) and not ircmsgs.isAction(msg):
return
@ -169,17 +151,14 @@ class Seen(callbacks.Plugin):
def doQuit(self, irc, msg):
said = ircmsgs.prettyPrint(msg)
if irc not in self.ircstates:
return
try:
id = ircdb.users.getUserId(msg.prefix)
except KeyError:
id = None # Not in the database.
for channel in self.ircstates[irc].channels:
if msg.nick in self.ircstates[irc].channels[channel].users:
self.anydb.update(channel, msg.nick, said)
if id is not None:
self.anydb.update(channel, id, said)
for channel in msg.tagged('channels'):
self.anydb.update(channel, msg.nick, said)
if id is not None:
self.anydb.update(channel, id, said)
doNick = doQuit
def doMode(self, irc, msg):