mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Added Topic.reorder
This commit is contained in:
parent
8fb158d434
commit
d91cc33c58
@ -124,6 +124,42 @@ class Topic(callbacks.Privmsg, configurable.Mixin):
|
|||||||
irc.queueMsg(ircmsgs.topic(channel, newtopic))
|
irc.queueMsg(ircmsgs.topic(channel, newtopic))
|
||||||
shuffle = privmsgs.checkChannelCapability(shuffle, 'topic')
|
shuffle = privmsgs.checkChannelCapability(shuffle, 'topic')
|
||||||
|
|
||||||
|
def reorder(self, irc, msg, args, channel):
|
||||||
|
"""[<channel>] <number> [<number> ...]
|
||||||
|
|
||||||
|
Reorders the topics from <channel> in the order of the specified
|
||||||
|
<number> arguments. <number> is a one-based index into the topics.
|
||||||
|
<channel> is only necessary if the message isn't sent in the channel
|
||||||
|
itself.
|
||||||
|
"""
|
||||||
|
topics = self._splitTopic(irc.state.getTopic(channel), channel)
|
||||||
|
if topics:
|
||||||
|
num = len(topics)
|
||||||
|
order = ('',)*num
|
||||||
|
order = privmsgs.getArgs(args, required=num)
|
||||||
|
for i,p in enumerate(order):
|
||||||
|
try:
|
||||||
|
p = int(p)
|
||||||
|
if p > 0:
|
||||||
|
order[i] = p - 1
|
||||||
|
elif p == 0:
|
||||||
|
irc.error(msg, '0 is not a valid topic number.')
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
order[i] = num + p
|
||||||
|
except ValueError:
|
||||||
|
irc.error(msg, 'The positions must be valid integers.')
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
newtopics = [topics[i] for i in order]
|
||||||
|
newtopic = self._joinTopic(newtopics, channel)
|
||||||
|
irc.queueMsg(ircmsgs.topic(channel, newtopic))
|
||||||
|
except IndexError:
|
||||||
|
irc.error(msg, 'An invalid topic number was specified.')
|
||||||
|
else:
|
||||||
|
irc.error(msg, 'There are no topics to reorder.')
|
||||||
|
reorder = privmsgs.checkChannelCapability(reorder, 'topic')
|
||||||
|
|
||||||
def get(self, irc, msg, args, channel):
|
def get(self, irc, msg, args, channel):
|
||||||
"""[<channel>] <number>
|
"""[<channel>] <number>
|
||||||
|
|
||||||
|
@ -86,6 +86,14 @@ class TopicTestCase(ChannelPluginTestCase, PluginDocumentation):
|
|||||||
m = self.getMsg('topic add bar')
|
m = self.getMsg('topic add bar')
|
||||||
self.failUnless('<==>' in m.args[1])
|
self.failUnless('<==>' in m.args[1])
|
||||||
|
|
||||||
|
def testReorder(self):
|
||||||
|
_ = self.getMsg('topic add foo')
|
||||||
|
_ = self.getMsg('topic add bar')
|
||||||
|
_ = self.getMsg('topic add baz')
|
||||||
|
self.assertHelp('topic reorder')
|
||||||
|
self.assertRegexp('topic reorder 2 1 3', r'bar.*foo.*baz')
|
||||||
|
self.assertRegexp('topic reorder 3 -2 1', r'baz.*foo.*bar')
|
||||||
|
self.assertError('topic reorder 0 1 2')
|
||||||
|
|
||||||
# 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