From d35e67046bf92192893b5f5eb57ecc407b98b500 Mon Sep 17 00:00:00 2001 From: Julian Paul Glass Date: Fri, 21 Nov 2014 02:07:52 +0000 Subject: [PATCH 1/3] Add refresh command --- plugins/Topic/plugin.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/Topic/plugin.py b/plugins/Topic/plugin.py index 4c79575b4..f94e59fda 100644 --- a/plugins/Topic/plugin.py +++ b/plugins/Topic/plugin.py @@ -522,6 +522,23 @@ class Topic(callbacks.Plugin): self._sendTopics(irc, channel, topics) restore = wrap(restore, ['canChangeTopic']) + @internationalizeDocstring + def refresh(self, irc, msg, args, channel): + """[] + Refreshes current topic set by anyone. Restores topic if empty. + is only necessary if the message isn't sent in the channel + itself. + """ + if not self._checkManageCapabilities(irc, msg, channel): + capabilities = self.registryValue('requireManageCapability') + irc.errorNoCapability(capabilities, raise=True) + topic = irc.state.channels[channel].topic + if topic: + self._sendTopics(irc, channel, topic) + else: + self.restore(self, irc, msg, args, channel) + set = wrap(refresh, ['canChangeTopic']) + @internationalizeDocstring def undo(self, irc, msg, args, channel): """[] From 54ee1e767013cc2dd114675267447e63fbad9307 Mon Sep 17 00:00:00 2001 From: Julian Paul Glass Date: Fri, 21 Nov 2014 03:24:10 +0000 Subject: [PATCH 2/3] added refresh command to Topic plugin --- plugins/Topic/plugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/Topic/plugin.py b/plugins/Topic/plugin.py index f94e59fda..f8594c3a6 100644 --- a/plugins/Topic/plugin.py +++ b/plugins/Topic/plugin.py @@ -531,13 +531,13 @@ class Topic(callbacks.Plugin): """ if not self._checkManageCapabilities(irc, msg, channel): capabilities = self.registryValue('requireManageCapability') - irc.errorNoCapability(capabilities, raise=True) + irc.errorNoCapability(capabilities, Raise=True) topic = irc.state.channels[channel].topic if topic: self._sendTopics(irc, channel, topic) else: - self.restore(self, irc, msg, args, channel) - set = wrap(refresh, ['canChangeTopic']) + self.restore(irc, msg, args, channel) + set = wrap(refresh, ['canChangetopic']) @internationalizeDocstring def undo(self, irc, msg, args, channel): From 16ffdf69ebc06aded9840caa3f003affd6cae4f1 Mon Sep 17 00:00:00 2001 From: Julian Paul Glass Date: Fri, 21 Nov 2014 04:50:33 +0000 Subject: [PATCH 3/3] tests.py: wAdded Refresh and Restore tests. plugin.py: Empty lastTopics[channel] raise a KeyError for testing purposes. --- plugins/Topic/plugin.py | 16 +++++++++++++--- plugins/Topic/test.py | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/plugins/Topic/plugin.py b/plugins/Topic/plugin.py index f8594c3a6..f091df6a4 100644 --- a/plugins/Topic/plugin.py +++ b/plugins/Topic/plugin.py @@ -515,6 +515,8 @@ class Topic(callbacks.Plugin): irc.errorNoCapability(capabilities, Raise=True) try: topics = self.lastTopics[channel] + if not topics: + raise KeyError except KeyError: irc.error(format(_('I haven\'t yet set the topic in %s.'), channel)) @@ -535,9 +537,17 @@ class Topic(callbacks.Plugin): topic = irc.state.channels[channel].topic if topic: self._sendTopics(irc, channel, topic) - else: - self.restore(irc, msg, args, channel) - set = wrap(refresh, ['canChangetopic']) + return + try: + topics = self.lastTopics[channel] + if not topics: + raise KeyError + except KeyError: + irc.error(format(_('I haven\'t yet set the topic in %s.'), + channel)) + return + self._sendTopics(irc, channel, topics) + refresh = wrap(refresh, ['canChangeTopic']) @internationalizeDocstring def undo(self, irc, msg, args, channel): diff --git a/plugins/Topic/test.py b/plugins/Topic/test.py index 2f82cf363..70f6cad8e 100644 --- a/plugins/Topic/test.py +++ b/plugins/Topic/test.py @@ -162,6 +162,20 @@ class TopicTestCase(ChannelPluginTestCase): finally: conf.supybot.plugins.Topic.format.setValue(orig) + def testRestore(self): + self.getMsg('topic set foo') + self.assertResponse('topic restore', 'foo') + self.getMsg('topic remove 1') + restoreError = 'Error: I haven\'t yet set the topic in #test.' + self.assertResponse('topic restore', restoreError) + + def testRefresh(self): + self.getMsg('topic set foo') + self.assertResponse('topic refresh', 'foo') + self.getMsg('topic remove 1') + refreshError = 'Error: I haven\'t yet set the topic in #test.' + self.assertResponse('topic refresh', refreshError) + def testUndo(self): try: original = conf.supybot.plugins.Topic.format()