Topic: Change behavior of supybot.plugins.Topic.alwaysSetOnJoin to only apply if the actual topic differs from the default.

This commit is contained in:
Valentin Lorentz 2013-08-17 19:30:28 +00:00
parent b57be07f1c
commit 410472c317

View File

@ -184,7 +184,7 @@ class Topic(callbacks.Plugin):
except (KeyError, IndexError): except (KeyError, IndexError):
return None return None
def _sendTopics(self, irc, channel, topics, isDo=False, fit=False): def _formatTopics(self, irc, channel, topics, isDo=False, fit=False):
topics = [s for s in topics if s and not s.isspace()] topics = [s for s in topics if s and not s.isspace()]
self.lastTopics[channel] = topics self.lastTopics[channel] = topics
newTopic = self._joinTopic(channel, topics) newTopic = self._joinTopic(channel, topics)
@ -203,6 +203,16 @@ class Topic(callbacks.Plugin):
Raise=True) Raise=True)
except KeyError: except KeyError:
pass pass
return newTopics
def _sendTopics(self, irc, channel, topics=None, *args, newTopic=None,
**kwargs):
if newTopic is None:
assert topics is None
newTtopic = self.formatTopics(irc, channel, topics, *args,
**kwargs)
else:
assert topics is not None
self._addUndo(channel, topics) self._addUndo(channel, topics)
if not isDo and channel in self.redos: if not isDo and channel in self.redos:
del self.redos[channel] del self.redos[channel]
@ -248,12 +258,15 @@ class Topic(callbacks.Plugin):
self.log.debug('Not trying to restore topic in %s. I\'m not opped ' self.log.debug('Not trying to restore topic in %s. I\'m not opped '
'and %s is +t.', channel, channel) 'and %s is +t.', channel, channel)
return return
if c.topic == '' or self.registryValue('alwaysSetOnJoin', channel):
try: try:
topics = self.lastTopics[channel] topics = self.lastTopics[channel]
self._sendTopics(irc, channel, topics)
except KeyError: except KeyError:
self.log.debug('No topic to auto-restore in %s.', channel) self.log.debug('No topic to auto-restore in %s.', channel)
else:
newTopic = self._formatTopics(irc, channel, topics)
if c.topic == '' or (c.topic != newTopic and
self.registryValue('alwaysSetOnJoin', channel)):
self._sendTopics(irc, channel, newTopic=newTopic)
def do332(self, irc, msg): def do332(self, irc, msg):
if msg.args[1] in self.watchingFor332: if msg.args[1] in self.watchingFor332: