本文整理汇总了Python中supybot.callbacks.formatCommand函数的典型用法代码示例。如果您正苦于以下问题:Python formatCommand函数的具体用法?Python formatCommand怎么用?Python formatCommand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了formatCommand函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: plugin
def plugin(self, irc, msg, args, command):
"""<command>
Returns the name of the plugin that would be used to call <command>.
If it is not uniquely determined, returns list of all plugins that
contain <command>.
"""
(maxL, cbs) = irc.findCallbacksForArgs(command)
L = []
if maxL == command:
for cb in cbs:
L.append(cb.name())
command = callbacks.formatCommand(command)
if L:
if irc.nested:
irc.reply(format('%L', L))
else:
if len(L) > 1:
plugin = _('plugins')
else:
plugin = _('plugin')
irc.reply(format(_('The %q command is available in the %L '
'%s.'), command, L, plugin))
else:
irc.error(format(_('There is no command %q.'), command))
开发者ID:Ban3,项目名称:Limnoria,代码行数:26,代码来源:plugin.py
示例2: help
def help(self, irc, msg, args, command):
"""[<plugin>] [<command>]
This command gives a useful description of what <command> does.
<plugin> is only necessary if the command is in more than one plugin.
You may also want to use the 'list' command to list all available
plugins and commands.
"""
command = map(callbacks.canonicalName, command)
(maxL, cbs) = irc.findCallbacksForArgs(command)
if maxL == command:
if len(cbs) > 1:
names = sorted([cb.name() for cb in cbs])
irc.error(
format(
_(
"That command exists in the %L plugins. "
"Please specify exactly which plugin command "
"you want help with."
),
names,
)
)
else:
assert cbs, "Odd, maxL == command, but no cbs."
irc.reply(_.__call__(cbs[0].getCommandHelp(command, False)))
else:
irc.error(format(_("There is no command %q."), callbacks.formatCommand(command)))
开发者ID:ki113d,项目名称:Limnoria,代码行数:29,代码来源:plugin.py
示例3: getCommandHelp
def getCommandHelp(self, command, simpleSyntax=None):
method = self.getCommandMethod(command)
if method.im_func.func_name == "learn":
chan = None
if dynamic.msg is not None:
chan = dynamic.msg.args[0]
s = self.registryValue("learnSeparator", chan)
help = callbacks.getHelp
if simpleSyntax is None:
simpleSyntax = conf.get(conf.supybot.reply.showSimpleSyntax, chan)
if simpleSyntax:
help = callbacks.getSyntax
return help(method, doc=method._fake__doc__ % (s, s), name=callbacks.formatCommand(command))
return super(Factoids, self).getCommandHelp(command, simpleSyntax)
开发者ID:EnderBlue,项目名称:supybot,代码行数:14,代码来源:plugin.py
示例4: _callCommand
def _callCommand(self, command, irc, msg, *args, **kwargs):
self.log.info('%s called by %q.', callbacks.formatCommand(command), msg.prefix)
try:
for name in command:
cap = callbacks.checkCommandCapability(msg, self, name)
if cap:
return
try:
self.callingCommand = command
self.callCommand(command, irc, msg, *args, **kwargs)
finally:
self.callingCommand = None
except:
pass
开发者ID:tdfischer,项目名称:supybot-Whatis,代码行数:14,代码来源:plugin.py
示例5: getCommand
def getCommand(self, args):
canonicalName = callbacks.canonicalName
# All the code from here to the 'for' loop is copied from callbacks.py
assert args == map(canonicalName, args)
first = args[0]
for cb in self.cbs:
if first == cb.canonicalName():
return cb.getCommand(args)
if first == self.canonicalName() and len(args) > 1:
ret = self.getCommand(args[1:])
if ret:
return [first] + ret
for i in xrange(len(args), 0, -1):
if self.isCommandMethod(callbacks.formatCommand(args[0:i])):
return args[0:i]
return []
开发者ID:tbjers,项目名称:Limnoria,代码行数:16,代码来源:plugin.py
示例6: getCommand
def getCommand(self, args, check_other_plugins=True):
canonicalName = callbacks.canonicalName
# All the code from here to the 'for' loop is copied from callbacks.py
assert args == list(map(canonicalName, args))
first = args[0]
for cb in self.cbs:
if first == cb.canonicalName():
return cb.getCommand(args[1:])
if first == self.canonicalName() and len(args) > 1:
ret = self.getCommand(args[1:], False)
if ret:
return [first] + ret
max_length = self.registryValue('maximumWordsInName')
for i in xrange(1, min(len(args)+1, max_length)):
if self.isCommandMethod(callbacks.formatCommand(args[0:i])):
return args[0:i]
return []
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:17,代码来源:plugin.py
示例7: plugins
def plugins(self, irc, msg, args, command):
"""<command>
Returns the names of all plugins that contain <command>.
"""
L = self._findCallbacks(irc, command)
command = callbacks.formatCommand(command)
if L:
if irc.nested:
irc.reply(format('%L', L))
else:
if len(L) > 1:
plugin = 'plugins'
else:
plugin = 'plugin'
irc.reply(format('The %q command is available in the %L %s.',
command, L, plugin))
else:
irc.error(format('There is no command %q.', command))
开发者ID:Ban3,项目名称:Limnoria,代码行数:19,代码来源:plugin.py
示例8: help
def help(self, irc, msg, args, command):
"""[<plugin>] [<command>]
This command gives a useful description of what <command> does.
<plugin> is only necessary if the command is in more than one plugin.
"""
command = map(callbacks.canonicalName, command)
(maxL, cbs) = irc.findCallbacksForArgs(command)
if maxL == command:
if len(cbs) > 1:
names = sorted([cb.name() for cb in cbs])
irc.error(format('That command exists in the %L plugins. '
'Please specify exactly which plugin command '
'you want help with.', names))
else:
assert cbs, 'Odd, maxL == command, but no cbs.'
irc.reply(cbs[0].getCommandHelp(command, False))
else:
irc.error(format('There is no command %q.',
callbacks.formatCommand(command)))
开发者ID:MrTiggr,项目名称:supybot_fixes,代码行数:20,代码来源:plugin.py
示例9: plugin
def plugin(self, irc, msg, args, command):
"""<command>
Returns the plugin(s) that <command> is in.
"""
(maxL, cbs) = irc.findCallbacksForArgs(command)
L = []
if maxL == command:
for cb in cbs:
L.append(cb.name())
command = callbacks.formatCommand(command)
if L:
if irc.nested:
irc.reply(format('%L', L))
else:
if len(L) > 1:
plugin = 'plugins'
else:
plugin = 'plugin'
irc.reply(format('The %q command is available in the %L %s.',
command, L, plugin))
else:
irc.error(format('There is no command %q.', command))
开发者ID:Kefkius,项目名称:mazabot,代码行数:23,代码来源:plugin.py
示例10: help
def help(self, irc, msg, args, command):
"""[<plugin>] [<command>]
This command gives a useful description of what <command> does.
<plugin> is only necessary if the command is in more than one plugin.
You may also want to use the 'list' command to list all available
plugins and commands.
"""
if not command:
cHelp = self.registryValue("customHelpString")
if cHelp:
irc.reply(cHelp)
else:
irc.error()
return
command = list(map(callbacks.canonicalName, command))
(maxL, cbs) = irc.findCallbacksForArgs(command)
if maxL == command:
if len(cbs) > 1:
names = sorted([cb.name() for cb in cbs])
irc.error(format(_('That command exists in the %L plugins. '
'Please specify exactly which plugin command '
'you want help with.'), names))
else:
assert cbs, 'Odd, maxL == command, but no cbs.'
irc.reply(_.__call__(cbs[0].getCommandHelp(command, False)))
else:
plugins = [cb.name() for cb in irc.callbacks
if self.isPublic(cb)]
s = format(_('There is no command %q.'),
callbacks.formatCommand(command))
if command[0].lower() in map(str.lower, plugins):
s += (' However, "{0}" is the name of a loaded plugin, and '
'you may be able to find its provided commands '
'using \'list {0}\'.'.format(command[0].title()))
irc.error(s)
开发者ID:ElectroCode,项目名称:Limnoria,代码行数:37,代码来源:plugin.py
示例11: getCommandMethod
def getCommandMethod(self, command):
if len(command) == 1 or command[0] == self.canonicalName():
try:
return self.__parent.getCommandMethod(command)
except AttributeError:
pass
name = callbacks.formatCommand(command)
channel = dynamic.channel or 'global'
original = self._db.get_alias(channel, name)
if not original:
original = self._db.get_alias('global', name)
biggestDollar = findBiggestDollar(original)
biggestAt = findBiggestAt(original)
wildcard = '$*' in original
def f(irc, msg, args):
tokens = callbacks.tokenize(original)
if biggestDollar or biggestAt:
args = getArgs(args, required=biggestDollar, optional=biggestAt,
wildcard=wildcard)
max_len = conf.supybot.reply.maximumLength()
args = list([x[:max_len] for x in args])
def regexpReplace(m):
idx = int(m.group(1))
return args[idx-1]
def replace(tokens, replacer):
for (i, token) in enumerate(tokens):
if isinstance(token, list):
replace(token, replacer)
else:
tokens[i] = replacer(token)
replace(tokens, lambda s: dollarRe.sub(regexpReplace, s))
if biggestAt:
assert not wildcard
args = args[biggestDollar:]
replace(tokens, lambda s: atRe.sub(regexpReplace, s))
if wildcard:
assert not biggestAt
# Gotta remove the things that have already been subbed in.
i = biggestDollar
while i:
args.pop(0)
i -= 1
def everythingReplace(tokens):
for (i, token) in enumerate(tokens):
if isinstance(token, list):
if everythingReplace(token):
return
if token == '$*':
tokens[i:i+1] = args
return True
elif '$*' in token:
tokens[i] = token.replace('$*', ' '.join(args))
return True
return False
everythingReplace(tokens)
maxNesting = conf.supybot.commands.nested.maximum()
if maxNesting and irc.nested+1 > maxNesting:
irc.error(_('You\'ve attempted more nesting than is '
'currently allowed on this bot.'), Raise=True)
self.Proxy(irc, msg, tokens)
if biggestDollar and (wildcard or biggestAt):
flexargs = _(' at least')
else:
flexargs = ''
try:
lock = self._db.get_aka_lock(channel, name)
except AkaError:
lock = self._db.get_aka_lock('global', name)
(locked, locked_by, locked_at) = lock
if locked:
lock = ' ' + _('Locked by %s at %s') % (locked_by, locked_at)
else:
lock = ''
doc = format(_('<an alias,%s %n>\n\nAlias for %q.%s'),
flexargs, (biggestDollar, _('argument')), original, lock)
f = utils.python.changeFunctionName(f, name, doc)
return f
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:77,代码来源:plugin.py
示例12: getCommandMethod
def getCommandMethod(self, command):
if len(command) == 1 or command[0] == self.canonicalName():
try:
return self.__parent.getCommandMethod(command)
except AttributeError:
pass
name = callbacks.formatCommand(command)
channel = dynamic.channel or 'global'
original = self._db.get_alias(channel, name)
if not original:
original = self._db.get_alias('global', name)
biggestDollar = findBiggestDollar(original)
biggestAt = findBiggestAt(original)
wildcard = '$*' in original
def f(irc, msg, args):
tokens = callbacks.tokenize(original)
if biggestDollar or biggestAt:
args = getArgs(args, required=biggestDollar, optional=biggestAt,
wildcard=wildcard)
def regexpReplace(m):
idx = int(m.group(1))
return args[idx-1]
def replace(tokens, replacer):
for (i, token) in enumerate(tokens):
if isinstance(token, list):
replace(token, replacer)
else:
tokens[i] = replacer(token)
replace(tokens, lambda s: dollarRe.sub(regexpReplace, s))
args = args[biggestDollar:]
if biggestAt:
replace(tokens, lambda s: atRe.sub(regexpReplace, s))
if wildcard:
def everythingReplace(tokens):
ret = False
new_tokens = []
for (i, token) in enumerate(tokens):
if isinstance(token, list):
(sub_ret, sub_tokens) = everythingReplace(token)
new_tokens.append(sub_tokens)
if sub_ret:
continue
if token == '$*':
new_tokens.extend(args)
ret = True
else:
new_tokens.append(
token.replace('$*', ' '.join(args)))
ret = True
return (ret, new_tokens)
(ret, tokens) = everythingReplace(tokens)
self.Proxy(irc, msg, tokens)
if biggestDollar and (wildcard or biggestAt):
flexargs = _(' at least')
else:
flexargs = ''
try:
lock = self._db.get_aka_lock(channel, name)
except AkaError:
lock = self._db.get_aka_lock('global', name)
(locked, locked_by, locked_at) = lock
if locked:
lock = ' ' + _('Locked by %s at %s') % (locked_by, locked_at)
else:
lock = ''
doc = format(_('<an alias,%s %n>\n\nAlias for %q.%s'),
flexargs, (biggestDollar, _('argument')), original, lock)
f = utils.python.changeFunctionName(f, name, doc)
return f
开发者ID:tbjers,项目名称:Limnoria,代码行数:69,代码来源:plugin.py
示例13: getCommandMethod
def getCommandMethod(self, command):
if len(command) == 1 or command[0] == self.canonicalName():
try:
return self.__parent.getCommandMethod(command)
except AttributeError:
pass
name = callbacks.formatCommand(command)
channel = dynamic.channel or 'global'
original = self._db.get_alias(channel, name)
if not original:
original = self._db.get_alias('global', name)
biggestDollar = findBiggestDollar(original)
biggestAt = findBiggestAt(original)
wildcard = '$*' in original
def f(irc, msg, args):
tokens = callbacks.tokenize(original)
if biggestDollar or biggestAt:
args = getArgs(args, required=biggestDollar, optional=biggestAt,
wildcard=wildcard)
remaining_len = conf.supybot.reply.maximumLength()
for (i, arg) in enumerate(args):
if remaining_len < len(arg):
arg = arg[0:remaining_len]
args[i+1:] = []
break
remaining_len -= len(arg)
def regexpReplace(m):
idx = int(m.group(1))
return args[idx-1]
def replace(tokens, replacer):
for (i, token) in enumerate(tokens):
if isinstance(token, list):
replace(token, replacer)
else:
tokens[i] = replacer(token)
replace(tokens, lambda s: dollarRe.sub(regexpReplace, s))
if biggestAt:
assert not wildcard
args = args[biggestDollar:]
replace(tokens, lambda s: atRe.sub(regexpReplace, s))
if wildcard:
assert not biggestAt
# Gotta remove the things that have already been subbed in.
i = biggestDollar
args[:] = args[i:]
def everythingReplace(tokens):
skip = 0
for (i, token) in enumerate(tokens):
if skip:
skip -= 1
continue
if isinstance(token, list):
everythingReplace(token)
if token == '$*':
tokens[i:i+1] = args
skip = len(args)-1 # do not make replacements in
# tokens we just added
elif '$*' in token:
tokens[i] = token.replace('$*', ' '.join(args))
everythingReplace(tokens)
maxNesting = conf.supybot.commands.nested.maximum()
if maxNesting and irc.nested+1 > maxNesting:
irc.error(_('You\'ve attempted more nesting than is '
'currently allowed on this bot.'), Raise=True)
self.Proxy(irc, msg, tokens, nested=irc.nested+1)
if biggestDollar and (wildcard or biggestAt):
flexargs = _(' at least')
else:
flexargs = ''
try:
lock = self._db.get_aka_lock(channel, name)
except AkaError:
lock = self._db.get_aka_lock('global', name)
(locked, locked_by, locked_at) = lock
if locked:
lock = ' ' + _('Locked by %s at %s') % (locked_by, locked_at)
else:
lock = ''
escaped_command = original.replace('\\', '\\\\').replace('"', '\\"')
if channel == 'global':
doc = format(_('<a global alias,%s %n>\n\nAlias for %q.%s'),
flexargs, (biggestDollar, _('argument')),
escaped_command, lock)
else:
doc = format(_('<an alias on %s,%s %n>\n\nAlias for %q.%s'),
channel, flexargs, (biggestDollar, _('argument')),
escaped_command, lock)
f = utils.python.changeFunctionName(f, name, doc)
return f
开发者ID:Hoaas,项目名称:Limnoria,代码行数:89,代码来源:plugin.py
注:本文中的supybot.callbacks.formatCommand函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论