mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
Added Topic.fit.
This commit is contained in:
parent
6b75be6e60
commit
14837bc544
@ -135,13 +135,18 @@ class Topic(callbacks.Privmsg):
|
|||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _sendTopics(self, irc, channel, topics, isDo=False):
|
def _sendTopics(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)
|
||||||
try:
|
try:
|
||||||
maxLen = irc.state.supported['topiclen']
|
maxLen = irc.state.supported['topiclen']
|
||||||
if len(newTopic) > maxLen:
|
if fit:
|
||||||
|
while len(newTopic) > maxLen:
|
||||||
|
topics.pop(0)
|
||||||
|
self.lastTopics[channel] = topics
|
||||||
|
newTopic = self._joinTopic(channel, topics)
|
||||||
|
elif len(newTopic) > maxLen:
|
||||||
if self.registryValue('recognizeTopiclen', channel):
|
if self.registryValue('recognizeTopiclen', channel):
|
||||||
irc.error(format('That topic is too long for this server '
|
irc.error(format('That topic is too long for this server '
|
||||||
'(maximum length: %i; this topic: %i).',
|
'(maximum length: %i; this topic: %i).',
|
||||||
@ -185,6 +190,19 @@ class Topic(callbacks.Privmsg):
|
|||||||
self._sendTopics(irc, channel, topics)
|
self._sendTopics(irc, channel, topics)
|
||||||
add = wrap(add, ['canChangeTopic', rest('topic')])
|
add = wrap(add, ['canChangeTopic', rest('topic')])
|
||||||
|
|
||||||
|
def fit(self, irc, msg, args, channel, topic):
|
||||||
|
"""[<channel>] <topic>
|
||||||
|
|
||||||
|
Adds <topic> to the topics for <channel>. If the topic is too long
|
||||||
|
for the server, topics will be popped until there is enough room.
|
||||||
|
<channel> is only necessary if the message isn't sent in the channel
|
||||||
|
itself.
|
||||||
|
"""
|
||||||
|
topics = self._splitTopic(irc.state.getTopic(channel), channel)
|
||||||
|
topics.append(topic)
|
||||||
|
self._sendTopics(irc, channel, topics, fit=True)
|
||||||
|
fit = wrap(fit, ['canChangeTopic', rest('topic')])
|
||||||
|
|
||||||
def replace(self, irc, msg, args, channel, i, topic):
|
def replace(self, irc, msg, args, channel, i, topic):
|
||||||
"""[<channel>] <number> <topic>
|
"""[<channel>] <number> <topic>
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class TopicTestCase(ChannelPluginTestCase):
|
|||||||
self.assertRegexp('topic replace 2 lorem ipsum',
|
self.assertRegexp('topic replace 2 lorem ipsum',
|
||||||
'oof.*lorem ipsum.*zab')
|
'oof.*lorem ipsum.*zab')
|
||||||
self.assertRegexp('topic replace 2 rab', 'oof.*rab.*zab')
|
self.assertRegexp('topic replace 2 rab', 'oof.*rab.*zab')
|
||||||
|
|
||||||
def testGet(self):
|
def testGet(self):
|
||||||
self.assertError('topic get 1')
|
self.assertError('topic get 1')
|
||||||
_ = self.getMsg('topic add foo')
|
_ = self.getMsg('topic add foo')
|
||||||
@ -186,7 +186,7 @@ class TopicTestCase(ChannelPluginTestCase):
|
|||||||
self.assertError('topic swap -3 1')
|
self.assertError('topic swap -3 1')
|
||||||
finally:
|
finally:
|
||||||
conf.supybot.plugins.Topic.format.setValue(original)
|
conf.supybot.plugins.Topic.format.setValue(original)
|
||||||
|
|
||||||
def testDefault(self):
|
def testDefault(self):
|
||||||
self.assertError('topic default')
|
self.assertError('topic default')
|
||||||
try:
|
try:
|
||||||
@ -219,8 +219,20 @@ class TopicTestCase(ChannelPluginTestCase):
|
|||||||
self.assertResponse('topic separator ||', 'foo || bar || baz')
|
self.assertResponse('topic separator ||', 'foo || bar || baz')
|
||||||
finally:
|
finally:
|
||||||
conf.supybot.plugins.Topic.format.setValue(original)
|
conf.supybot.plugins.Topic.format.setValue(original)
|
||||||
|
|
||||||
|
def testFit(self):
|
||||||
|
original = conf.supybot.plugins.Topic.format()
|
||||||
|
try:
|
||||||
|
conf.supybot.plugins.Topic.format.setValue('$topic')
|
||||||
|
self.irc.state.supported['TOPICLEN'] = 20
|
||||||
|
self.assertResponse('topic fit foo', 'foo')
|
||||||
|
self.assertResponse('topic fit bar', 'foo || bar')
|
||||||
|
self.assertResponse('topic fit baz', 'foo || bar || baz')
|
||||||
|
self.assertResponse('topic fit qux', 'bar || baz || qux')
|
||||||
|
finally:
|
||||||
|
conf.supybot.plugins.Topic.format.setValue(original)
|
||||||
|
self.irc.state.supported.pop('TOPICLEN', None)
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user