mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-29 22:29:24 +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):
|
||||
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()]
|
||||
self.lastTopics[channel] = topics
|
||||
newTopic = self._joinTopic(channel, topics)
|
||||
try:
|
||||
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):
|
||||
irc.error(format('That topic is too long for this server '
|
||||
'(maximum length: %i; this topic: %i).',
|
||||
@ -185,6 +190,19 @@ class Topic(callbacks.Privmsg):
|
||||
self._sendTopics(irc, channel, topics)
|
||||
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):
|
||||
"""[<channel>] <number> <topic>
|
||||
|
||||
|
@ -220,6 +220,18 @@ class TopicTestCase(ChannelPluginTestCase):
|
||||
finally:
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user