mirror of https://github.com/Mikaela/Limnoria.git
Converted to commands.wrap.
This commit is contained in:
parent
ddb914aa71
commit
53f77b790b
|
@ -38,12 +38,13 @@ __author__ = supybot.authors.jemfinch
|
||||||
|
|
||||||
import supybot.plugins as plugins
|
import supybot.plugins as plugins
|
||||||
|
|
||||||
|
import types
|
||||||
import string
|
import string
|
||||||
|
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
|
from supybot.commands import *
|
||||||
import supybot.ircmsgs as ircmsgs
|
import supybot.ircmsgs as ircmsgs
|
||||||
import supybot.ircutils as ircutils
|
import supybot.ircutils as ircutils
|
||||||
import supybot.privmsgs as privmsgs
|
|
||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
|
|
||||||
class Utilities(callbacks.Privmsg):
|
class Utilities(callbacks.Privmsg):
|
||||||
|
@ -55,15 +56,15 @@ class Utilities(callbacks.Privmsg):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def reply(self, irc, msg, args):
|
def reply(self, irc, msg, args, text):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
|
||||||
Replies with <text>. Equivalent to the alias, 'echo $nick: $1'.
|
Replies with <text>. Equivalent to the alias, 'echo $nick: $1'.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
irc.reply(text)
|
irc.reply(text)
|
||||||
|
reply = wrap(reply, ['text'])
|
||||||
|
|
||||||
def success(self, irc, msg, args):
|
def success(self, irc, msg, args, text):
|
||||||
"""[<text>]
|
"""[<text>]
|
||||||
|
|
||||||
Does nothing except to reply with a success message. This is useful
|
Does nothing except to reply with a success message. This is useful
|
||||||
|
@ -72,8 +73,8 @@ class Utilities(callbacks.Privmsg):
|
||||||
course, will break out of this command. <text>, if given, will be
|
course, will break out of this command. <text>, if given, will be
|
||||||
appended to the end of the success message.
|
appended to the end of the success message.
|
||||||
"""
|
"""
|
||||||
text = privmsgs.getArgs(args, required=0, optional=1)
|
|
||||||
irc.replySuccess(text)
|
irc.replySuccess(text)
|
||||||
|
success = wrap(success, [additional('text')])
|
||||||
|
|
||||||
def last(self, irc, msg, args):
|
def last(self, irc, msg, args):
|
||||||
"""<text> [<text> ...]
|
"""<text> [<text> ...]
|
||||||
|
@ -85,7 +86,7 @@ class Utilities(callbacks.Privmsg):
|
||||||
if args:
|
if args:
|
||||||
irc.reply(args[-1])
|
irc.reply(args[-1])
|
||||||
else:
|
else:
|
||||||
raise callbacks.Error
|
raise callbacks.ArgumentError
|
||||||
|
|
||||||
def strlen(self, irc, msg, args):
|
def strlen(self, irc, msg, args):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
@ -98,21 +99,19 @@ class Utilities(callbacks.Privmsg):
|
||||||
total += len(args)-1 # spaces between the arguments.
|
total += len(args)-1 # spaces between the arguments.
|
||||||
irc.reply(str(total))
|
irc.reply(str(total))
|
||||||
|
|
||||||
def echo(self, irc, msg, args):
|
def echo(self, irc, msg, args, text):
|
||||||
"""takes any number of arguments
|
"""<text>
|
||||||
|
|
||||||
Returns the arguments given it. Uses our standard substitute on the
|
Returns the arguments given it. Uses our standard substitute on the
|
||||||
string(s) given to it; $nick (or $who), $randomNick, $randomInt,
|
string(s) given to it; $nick (or $who), $randomNick, $randomInt,
|
||||||
$botnick, $channel, $user, $host, $today, $now, and $randomDate are all
|
$botnick, $channel, $user, $host, $today, $now, and $randomDate are all
|
||||||
handled appropriately.
|
handled appropriately.
|
||||||
"""
|
"""
|
||||||
if not args:
|
|
||||||
raise callbacks.ArgumentError
|
|
||||||
text = privmsgs.getArgs(args)
|
|
||||||
text = plugins.standardSubstitute(irc, msg, text)
|
text = plugins.standardSubstitute(irc, msg, text)
|
||||||
irc.reply(text, prefixName=False)
|
irc.reply(text, prefixName=False)
|
||||||
|
echo = wrap(echo, ['text'])
|
||||||
|
|
||||||
def re(self, irc, msg, args):
|
def re(self, irc, msg, args, ff, text):
|
||||||
"""<regexp> <text>
|
"""<regexp> <text>
|
||||||
|
|
||||||
If <regexp> is of the form m/regexp/flags, returns the portion of
|
If <regexp> is of the form m/regexp/flags, returns the portion of
|
||||||
|
@ -120,33 +119,20 @@ class Utilities(callbacks.Privmsg):
|
||||||
s/regexp/replacement/flags, returns the result of applying such a
|
s/regexp/replacement/flags, returns the result of applying such a
|
||||||
regexp to <text>
|
regexp to <text>
|
||||||
"""
|
"""
|
||||||
(regexp, text) = privmsgs.getArgs(args, required=2)
|
if isinstance(ff, (types.FunctionType, types.MethodType)):
|
||||||
self.log.info('re command called with regexp %r from %s' %
|
f = ff
|
||||||
(regexp, msg.prefix))
|
else:
|
||||||
if len(regexp) > 512:
|
f = lambda s: ff.search(s) and ff.search(s).group(0) or ''
|
||||||
irc.error('Your regexp is just plain too long.')
|
|
||||||
return
|
|
||||||
f = None
|
|
||||||
try:
|
|
||||||
r = utils.perlReToPythonRe(regexp)
|
|
||||||
f = lambda s: r.search(s) and r.search(s).group(0) or ''
|
|
||||||
except ValueError, e:
|
|
||||||
try:
|
|
||||||
f = utils.perlReToReplacer(regexp)
|
|
||||||
except ValueError, e:
|
|
||||||
irc.error('Invalid regexp: %s' % e.args[0])
|
|
||||||
return
|
|
||||||
if f is None:
|
|
||||||
irc.error('Invalid regexp: %s' % e.args[0])
|
|
||||||
return
|
|
||||||
if f('') and len(f(' ')) > len(f(''))+1: # Matches the empty string.
|
if f('') and len(f(' ')) > len(f(''))+1: # Matches the empty string.
|
||||||
s = 'You probably don\'t want to match the empty string.'
|
s = 'You probably don\'t want to match the empty string.'
|
||||||
irc.error(s)
|
irc.error(s)
|
||||||
else:
|
else:
|
||||||
irc.reply(f(text))
|
irc.reply(f(text))
|
||||||
re = privmsgs.checkCapability(re, 'trusted')
|
re = wrap(re, [('checkCapability', 'trusted'),
|
||||||
|
first('regexpMatcher', 'regexpReplacer'),
|
||||||
|
'text'])
|
||||||
|
|
||||||
def apply(self, irc, msg, args):
|
def apply(self, irc, msg, args, command):
|
||||||
"""<command> <text>
|
"""<command> <text>
|
||||||
|
|
||||||
Tokenizes <text> and calls <command> with the resulting arguments.
|
Tokenizes <text> and calls <command> with the resulting arguments.
|
||||||
|
@ -155,12 +141,13 @@ class Utilities(callbacks.Privmsg):
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
command = args.pop(0)
|
command = args.pop(0)
|
||||||
args = [token and token or '""' for token in args]
|
args = [token and token or '""' for token in args]
|
||||||
text = privmsgs.getArgs(args)
|
text = ' '.join(args)
|
||||||
commands = command.split()
|
commands = command.split()
|
||||||
commands = map(callbacks.canonicalName, commands)
|
commands = map(callbacks.canonicalName, commands)
|
||||||
tokens = callbacks.tokenize(text)
|
tokens = callbacks.tokenize(text)
|
||||||
allTokens = commands + tokens
|
allTokens = commands + tokens
|
||||||
self.Proxy(irc, msg, allTokens)
|
self.Proxy(irc, msg, allTokens)
|
||||||
|
apply = wrap(apply, ['something'], allowExtra=True)
|
||||||
|
|
||||||
|
|
||||||
Class = Utilities
|
Class = Utilities
|
||||||
|
|
Loading…
Reference in New Issue