mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 18:44:04 +01:00
Fixed changetopic to use utils.perlReToReplacer and added help/morehelp for all commands.
This commit is contained in:
parent
d5484f620f
commit
481c9f31ac
@ -54,7 +54,11 @@ class Topic(callbacks.Privmsg):
|
|||||||
topicFormatter = '%s (%s)'
|
topicFormatter = '%s (%s)'
|
||||||
topicUnformatter = re.compile('(.*) \((.*)\)')
|
topicUnformatter = re.compile('(.*) \((.*)\)')
|
||||||
def addtopic(self, irc, msg, args):
|
def addtopic(self, irc, msg, args):
|
||||||
"[<channel>] (if not sent in the channel itself) <topic>"
|
"""[<channel>] <topic>
|
||||||
|
|
||||||
|
Adds <topic> to the topics for <channel>. <channel> is only necessary
|
||||||
|
if the message isn't sent in the channel itself.
|
||||||
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
capability = ircdb.makeChannelCapability(channel, 'topic')
|
capability = ircdb.makeChannelCapability(channel, 'topic')
|
||||||
topic = privmsgs.getArgs(args)
|
topic = privmsgs.getArgs(args)
|
||||||
@ -79,7 +83,11 @@ class Topic(callbacks.Privmsg):
|
|||||||
irc.error(msg, conf.replyNoCapability % capability)
|
irc.error(msg, conf.replyNoCapability % capability)
|
||||||
|
|
||||||
def shuffletopic(self, irc, msg, args):
|
def shuffletopic(self, irc, msg, args):
|
||||||
"[<channel>] (if not sent in the channel itself)"
|
"""[<channel>]
|
||||||
|
|
||||||
|
Shuffles the topics in <channel>. <channel> is only necessary if the
|
||||||
|
message isn't sent in the channel itself.
|
||||||
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
capability = ircdb.makeChannelCapability(channel, 'topic')
|
capability = ircdb.makeChannelCapability(channel, 'topic')
|
||||||
if ircdb.checkCapability(msg.prefix, capability):
|
if ircdb.checkCapability(msg.prefix, capability):
|
||||||
@ -90,16 +98,46 @@ class Topic(callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
irc.error(msg, conf.replyNoCapability % capability)
|
irc.error(msg, conf.replyNoCapability % capability)
|
||||||
|
|
||||||
|
def topic(self, irc, msg, args):
|
||||||
|
"""[<channel>] <number>
|
||||||
|
|
||||||
|
Returns topic number <number> from <channel>. <number> is a zero-based
|
||||||
|
index into the topics. <channel> is only necessary if the message
|
||||||
|
isn't sent in the channel itself.
|
||||||
|
"""
|
||||||
|
i = privmsgs.getArgs(args)
|
||||||
|
try:
|
||||||
|
i = int(i)
|
||||||
|
except ValueError:
|
||||||
|
irc.error(msg, 'The argument must be a valid integer.')
|
||||||
|
return
|
||||||
|
topics = irc.state.getTopic(channel).split(self.topicSeparator)
|
||||||
|
try:
|
||||||
|
irc.reply(msg, topics[i])
|
||||||
|
except IndexError:
|
||||||
|
irc.error(msg, 'That\'s not a valid index.')
|
||||||
|
return
|
||||||
|
|
||||||
def changetopic(self, irc, msg, args):
|
def changetopic(self, irc, msg, args):
|
||||||
"[<channel>] <number> <regexp> <replacement>"
|
"""[<channel>] <number> <regexp>
|
||||||
|
|
||||||
|
Changes the topic number <number> on <channel> according to the regular
|
||||||
|
expression <regexp>. <number> is the zero-based index into the topics;
|
||||||
|
<regexp> is a regular expression of the form
|
||||||
|
s/regexp/replacement/flags. <channel> is only necessary if the message
|
||||||
|
isn't sent in the channel itself.
|
||||||
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
(number, regexp, replacement) = privmsgs.getArgs(args, needed=3)
|
(number, regexp) = privmsgs.getArgs(args, needed=2)
|
||||||
try:
|
try:
|
||||||
number = int(number)
|
number = int(number)
|
||||||
r = re.compile(regexp, re.I)
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
irc.error(msg, 'The <number> argument must be a number.')
|
irc.error(msg, 'The <number> argument must be a number.')
|
||||||
return
|
return
|
||||||
|
try:
|
||||||
|
replacer = utils.perlReToReplacer(regexp)
|
||||||
|
except ValueError, e:
|
||||||
|
irc.error(msg, 'The regexp wasn\'t valid: %s' % e.args[0])
|
||||||
except sre_constants.error, e:
|
except sre_constants.error, e:
|
||||||
irc.error(msg, debug.exnToString(e))
|
irc.error(msg, debug.exnToString(e))
|
||||||
return
|
return
|
||||||
@ -110,7 +148,7 @@ class Topic(callbacks.Privmsg):
|
|||||||
not ircdb.checkCapabilities(msg.prfix, ('op', 'admin')):
|
not ircdb.checkCapabilities(msg.prfix, ('op', 'admin')):
|
||||||
irc.error(msg, 'You can only modify your own topics.')
|
irc.error(msg, 'You can only modify your own topics.')
|
||||||
return
|
return
|
||||||
newTopic = self.topicFormatter % (r.sub(replacement, topic), name)
|
newTopic = self.topicFormatter % (replacer(topic), name)
|
||||||
topics.insert(number, newTopic)
|
topics.insert(number, newTopic)
|
||||||
newTopic = self.topicSeparator.join(topics)
|
newTopic = self.topicSeparator.join(topics)
|
||||||
irc.queueMsg(ircmsgs.topic(channel, newTopic))
|
irc.queueMsg(ircmsgs.topic(channel, newTopic))
|
||||||
|
Loading…
Reference in New Issue
Block a user