mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 18:44:04 +01:00
ChannelLogger && ChannelStats && Limiter && Relay && Seen: Use new QUIT and NICK 'channels' tag instead of copying the state.
This commit is contained in:
parent
3b78fd2424
commit
2937152dc1
@ -61,8 +61,6 @@ class ChannelLogger(callbacks.Plugin):
|
|||||||
def __init__(self, irc):
|
def __init__(self, irc):
|
||||||
self.__parent = super(ChannelLogger, self)
|
self.__parent = super(ChannelLogger, self)
|
||||||
self.__parent.__init__(irc)
|
self.__parent.__init__(irc)
|
||||||
self.lastMsgs = {}
|
|
||||||
self.lastStates = {}
|
|
||||||
self.logs = {}
|
self.logs = {}
|
||||||
self.flusher = self.flush
|
self.flusher = self.flush
|
||||||
world.flushers.append(self.flusher)
|
world.flushers.append(self.flusher)
|
||||||
@ -72,26 +70,10 @@ class ChannelLogger(callbacks.Plugin):
|
|||||||
log.close()
|
log.close()
|
||||||
world.flushers = [x for x in world.flushers if x is not self.flusher]
|
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):
|
def reset(self):
|
||||||
for log in self._logs():
|
for log in self._logs():
|
||||||
log.close()
|
log.close()
|
||||||
self.logs.clear()
|
self.logs.clear()
|
||||||
self.lastMsgs.clear()
|
|
||||||
self.lastStates.clear()
|
|
||||||
|
|
||||||
def _logs(self):
|
def _logs(self):
|
||||||
for logs in self.logs.values():
|
for logs in self.logs.values():
|
||||||
@ -222,10 +204,9 @@ class ChannelLogger(callbacks.Plugin):
|
|||||||
def doNick(self, irc, msg):
|
def doNick(self, irc, msg):
|
||||||
oldNick = msg.nick
|
oldNick = msg.nick
|
||||||
newNick = msg.args[0]
|
newNick = msg.args[0]
|
||||||
for (channel, c) in irc.state.channels.items():
|
for channel in msg.tagged('channels'):
|
||||||
if newNick in c.users:
|
self.doLog(irc, channel,
|
||||||
self.doLog(irc, channel,
|
'*** %s is now known as %s\n', oldNick, newNick)
|
||||||
'*** %s is now known as %s\n', oldNick, newNick)
|
|
||||||
|
|
||||||
def doInvite(self, irc, msg):
|
def doInvite(self, irc, msg):
|
||||||
(target, channel) = msg.args
|
(target, channel) = msg.args
|
||||||
@ -285,16 +266,11 @@ class ChannelLogger(callbacks.Plugin):
|
|||||||
reason = " (%s)" % msg.args[0]
|
reason = " (%s)" % msg.args[0]
|
||||||
else:
|
else:
|
||||||
reason = ""
|
reason = ""
|
||||||
if not isinstance(irc, irclib.Irc):
|
for channel in msg.tagged('channels'):
|
||||||
irc = irc.getRealIrc()
|
|
||||||
if irc not in self.lastStates:
|
|
||||||
return
|
|
||||||
for (channel, chan) in self.lastStates[irc].channels.items():
|
|
||||||
if(self.registryValue('showJoinParts', channel)):
|
if(self.registryValue('showJoinParts', channel)):
|
||||||
if msg.nick in chan.users:
|
self.doLog(irc, channel,
|
||||||
self.doLog(irc, channel,
|
'*** %s <%s> has quit IRC%s\n',
|
||||||
'*** %s <%s> has quit IRC%s\n',
|
msg.nick, msg.prefix, reason)
|
||||||
msg.nick, msg.prefix, reason)
|
|
||||||
|
|
||||||
def outFilter(self, irc, msg):
|
def outFilter(self, irc, msg):
|
||||||
# Gotta catch my own messages *somehow* :)
|
# Gotta catch my own messages *somehow* :)
|
||||||
|
@ -170,8 +170,6 @@ class ChannelStats(callbacks.Plugin):
|
|||||||
def __init__(self, irc):
|
def __init__(self, irc):
|
||||||
self.__parent = super(ChannelStats, self)
|
self.__parent = super(ChannelStats, self)
|
||||||
self.__parent.__init__(irc)
|
self.__parent.__init__(irc)
|
||||||
self.lastmsg = None
|
|
||||||
self.laststate = None
|
|
||||||
self.outFiltering = False
|
self.outFiltering = False
|
||||||
self.db = StatsDB(filename)
|
self.db = StatsDB(filename)
|
||||||
self._flush = self.db.flush
|
self._flush = self.db.flush
|
||||||
@ -183,13 +181,6 @@ class ChannelStats(callbacks.Plugin):
|
|||||||
self.__parent.die()
|
self.__parent.die()
|
||||||
|
|
||||||
def __call__(self, irc, msg):
|
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)
|
self.db.addMsg(msg)
|
||||||
super(ChannelStats, self).__call__(irc, msg)
|
super(ChannelStats, self).__call__(irc, msg)
|
||||||
|
|
||||||
@ -222,15 +213,14 @@ class ChannelStats(callbacks.Plugin):
|
|||||||
id = ircdb.users.getUserId(msg.prefix)
|
id = ircdb.users.getUserId(msg.prefix)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
id = None
|
id = None
|
||||||
for (channel, c) in self.laststate.channels.items():
|
for channel in msg.tagged('channels'):
|
||||||
if msg.nick in c.users:
|
if (channel, 'channelStats') not in self.db:
|
||||||
if (channel, 'channelStats') not in self.db:
|
self.db[channel, 'channelStats'] = ChannelStat()
|
||||||
self.db[channel, 'channelStats'] = ChannelStat()
|
self.db[channel, 'channelStats'].quits += 1
|
||||||
self.db[channel, 'channelStats'].quits += 1
|
if id is not None:
|
||||||
if id is not None:
|
if (channel, id) not in self.db:
|
||||||
if (channel, id) not in self.db:
|
self.db[channel, id] = UserStat()
|
||||||
self.db[channel, id] = UserStat()
|
self.db[channel, id].quits += 1
|
||||||
self.db[channel, id].quits += 1
|
|
||||||
|
|
||||||
def doKick(self, irc, msg):
|
def doKick(self, irc, msg):
|
||||||
(channel, nick, _) = msg.args
|
(channel, nick, _) = msg.args
|
||||||
|
@ -67,7 +67,7 @@ class Limiter(callbacks.Plugin):
|
|||||||
doKick = doJoin
|
doKick = doJoin
|
||||||
|
|
||||||
def doQuit(self, irc, msg):
|
def doQuit(self, irc, msg):
|
||||||
for channel in irc.state.channels:
|
for channel in msg.tagged('channels')
|
||||||
self._enforceLimit(irc, channel)
|
self._enforceLimit(irc, channel)
|
||||||
Limiter = internationalizeDocstring(Limiter)
|
Limiter = internationalizeDocstring(Limiter)
|
||||||
|
|
||||||
|
@ -49,21 +49,9 @@ class Relay(callbacks.Plugin):
|
|||||||
self.__parent = super(Relay, self)
|
self.__parent = super(Relay, self)
|
||||||
self.__parent.__init__(irc)
|
self.__parent.__init__(irc)
|
||||||
self._whois = {}
|
self._whois = {}
|
||||||
self.lastmsg = {}
|
|
||||||
self.ircstates = {}
|
|
||||||
self.queuedTopics = MultiSet()
|
self.queuedTopics = MultiSet()
|
||||||
self.lastRelayMsgs = ircutils.IrcDict()
|
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):
|
def do376(self, irc, msg):
|
||||||
networkGroup = conf.supybot.networks.get(irc.network)
|
networkGroup = conf.supybot.networks.get(irc.network)
|
||||||
for channel in self.registryValue('channels'):
|
for channel in self.registryValue('channels'):
|
||||||
@ -82,19 +70,6 @@ class Relay(callbacks.Plugin):
|
|||||||
# We should allow abbreviations at some point.
|
# We should allow abbreviations at some point.
|
||||||
return irc.network
|
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
|
@internationalizeDocstring
|
||||||
def join(self, irc, msg, args, channel):
|
def join(self, irc, msg, args, channel):
|
||||||
"""[<channel>]
|
"""[<channel>]
|
||||||
@ -392,10 +367,8 @@ class Relay(callbacks.Plugin):
|
|||||||
network = self._getIrcName(irc)
|
network = self._getIrcName(irc)
|
||||||
s = format(_('nick change by %s to %s on %s'), msg.nick,newNick,network)
|
s = format(_('nick change by %s to %s on %s'), msg.nick,newNick,network)
|
||||||
for channel in self.registryValue('channels'):
|
for channel in self.registryValue('channels'):
|
||||||
if channel in irc.state.channels:
|
m = self._msgmaker(channel, s)
|
||||||
if newNick in irc.state.channels[channel].users:
|
self._sendToOthers(irc, m)
|
||||||
m = self._msgmaker(channel, s)
|
|
||||||
self._sendToOthers(irc, m)
|
|
||||||
|
|
||||||
def doTopic(self, irc, msg):
|
def doTopic(self, irc, msg):
|
||||||
irc = self._getRealIrc(irc)
|
irc = self._getRealIrc(irc)
|
||||||
@ -433,10 +406,8 @@ class Relay(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
s = format(_('%s has quit %s.'), msg.nick, network)
|
s = format(_('%s has quit %s.'), msg.nick, network)
|
||||||
for channel in self.registryValue('channels'):
|
for channel in self.registryValue('channels'):
|
||||||
if channel in self.ircstates[irc].channels:
|
m = self._msgmaker(channel, s)
|
||||||
if msg.nick in self.ircstates[irc].channels[channel].users:
|
self._sendToOthers(irc, m)
|
||||||
m = self._msgmaker(channel, s)
|
|
||||||
self._sendToOthers(irc, m)
|
|
||||||
|
|
||||||
def doError(self, irc, msg):
|
def doError(self, irc, msg):
|
||||||
irc = self._getRealIrc(irc)
|
irc = self._getRealIrc(irc)
|
||||||
|
@ -103,7 +103,6 @@ class Seen(callbacks.Plugin):
|
|||||||
self.db = SeenDB(filename)
|
self.db = SeenDB(filename)
|
||||||
self.anydb = SeenDB(anyfilename)
|
self.anydb = SeenDB(anyfilename)
|
||||||
self.lastmsg = {}
|
self.lastmsg = {}
|
||||||
self.ircstates = {}
|
|
||||||
world.flushers.append(self.db.flush)
|
world.flushers.append(self.db.flush)
|
||||||
world.flushers.append(self.anydb.flush)
|
world.flushers.append(self.anydb.flush)
|
||||||
|
|
||||||
@ -121,25 +120,8 @@ class Seen(callbacks.Plugin):
|
|||||||
self.__parent.die()
|
self.__parent.die()
|
||||||
|
|
||||||
def __call__(self, irc, msg):
|
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)
|
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):
|
def doPrivmsg(self, irc, msg):
|
||||||
if ircmsgs.isCtcp(msg) and not ircmsgs.isAction(msg):
|
if ircmsgs.isCtcp(msg) and not ircmsgs.isAction(msg):
|
||||||
return
|
return
|
||||||
@ -169,17 +151,14 @@ class Seen(callbacks.Plugin):
|
|||||||
|
|
||||||
def doQuit(self, irc, msg):
|
def doQuit(self, irc, msg):
|
||||||
said = ircmsgs.prettyPrint(msg)
|
said = ircmsgs.prettyPrint(msg)
|
||||||
if irc not in self.ircstates:
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
id = ircdb.users.getUserId(msg.prefix)
|
id = ircdb.users.getUserId(msg.prefix)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
id = None # Not in the database.
|
id = None # Not in the database.
|
||||||
for channel in self.ircstates[irc].channels:
|
for channel in msg.tagged('channels'):
|
||||||
if msg.nick in self.ircstates[irc].channels[channel].users:
|
self.anydb.update(channel, msg.nick, said)
|
||||||
self.anydb.update(channel, msg.nick, said)
|
if id is not None:
|
||||||
if id is not None:
|
self.anydb.update(channel, id, said)
|
||||||
self.anydb.update(channel, id, said)
|
|
||||||
doNick = doQuit
|
doNick = doQuit
|
||||||
|
|
||||||
def doMode(self, irc, msg):
|
def doMode(self, irc, msg):
|
||||||
|
Loading…
Reference in New Issue
Block a user