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))
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 = 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: irc.error( format(_('There is no command %q.'), callbacks.formatCommand(command)))
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)))
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))
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.reply( _("Use the 'list' command to list all plugins, and " "'list <plugin>' to list all commands in a plugin. " "To show the help of a command, use 'help <command>'. ")) 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): if "Plugin" in plugins: template = _( " However, '{0}' is the name of a loaded plugin, and " "you may be able to find its help using " "'plugin help {0}' and its provided commands using " "'list {0}'.") else: template = _( " However, '{0}' is the name of a loaded plugin, and " "you may be able to find its provided commands using " "'list {0}'.") s += template.format(command[0].title()) irc.error(s)
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
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)
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 []
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)
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 []
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 range(1, min(len(args)+1, max_length)): if self.isCommandMethod(callbacks.formatCommand(args[0:i])): return args[0:i] return []
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))
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)))
def getCommandHelp(self, command, simpleSyntax=None): method = self.getCommandMethod(command) if method.__func__.__name__ == 'learn': chan = None network = None if dynamic.msg is not None: chan = dynamic.msg.channel if dynamic.irc is not None: network = dynamic.irc.network s = self.registryValue('learnSeparator', chan, network) help = callbacks.getHelp if simpleSyntax is None: simpleSyntax = conf.supybot.reply.showSimpleSyntax.getSpecific( dynamic.irc.network, 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)
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))
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)
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
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
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
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
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