Пример #1
0
 def execute(self, player, args):
     if args.get("command"):
         try:
             name, command = utils.find_one(
                 args["command"],
                 handler.all_commands(),
                 attributes=["names", "nospace_names"])
         except parser.NotFoundError as e:
             e.token = "command"
             raise e
         name_list = ""
         other_names = command().names + command().nospace_names
         if len(other_names) > 1:
             other_names = [a for a in other_names if a != name]
             other_names.sort()
             name_list = " ({})".format(", ".join(other_names))
         player.send("{}{}".format(name, name_list).upper())
         player.send("Usage:")
         Usage().execute(player, {"command": (name, command)}, tabs=True)
         if hasattr(command, "help_text"):
             player.send("")
             player.send(command.help_text)
     else:
         # when we get command storage sorted out, this'll be replaced
         all_names = []
         for command in handler.all_commands():
             all_names.extend(command().names)
             all_names.extend(command().nospace_names)
         all_names = sorted(set(all_names))
         player.send('Available commands: {}\nUse \"help <command>\" for '
                     'more information about a specific command.'
                     .format(", ".join(all_names)))
Пример #2
0
 def execute(self, player, args):
     if args.get("command"):
         try:
             name, command = utils.find_one(
                 args["command"],
                 handler.all_commands(),
                 attributes=["names", "nospace_names"])
         except parser.NotFoundError as e:
             e.token = "command"
             raise e
         name_list = ""
         other_names = command().names + command().nospace_names
         if len(other_names) > 1:
             other_names = [a for a in other_names if a != name]
             other_names.sort()
             name_list = " ({})".format(", ".join(other_names))
         player.send("{}{}".format(name, name_list).upper())
         player.send("Usage:")
         Usage().execute(player, {"command": (name, command)}, tabs=True)
         if hasattr(command, "help_text"):
             player.send("")
             player.send(command.help_text)
     else:
         # when we get command storage sorted out, this'll be replaced
         all_names = []
         for command in handler.all_commands():
             all_names.extend(command().names)
             all_names.extend(command().nospace_names)
         all_names = sorted(set(all_names))
         player.send('Available commands: {}\nUse \"help <command>\" for '
                     'more information about a specific command.'.format(
                         ", ".join(all_names)))
Пример #3
0
 def parseImpl(self, instring, loc, doActions=True):
     loc, text = super(CommandName, self).parseImpl(instring, loc,
                                                    doActions)
     test_name = text.lower()
     try:
         if self.fullOnly:
             attributes = ["names"]
         else:
             attributes = ["names", "nospace_names"]
         from muss.handler import all_commands
         perfect_matches, partial_matches = utils.find_by_name(
             test_name, all_commands(), attributes=attributes)
         adjusted_perfect = [x[1] for x in perfect_matches]
         adjusted_partial = []
         for match_tuple in partial_matches:
             name, command = match_tuple
             if not command.require_full:
                 adjusted_partial.append(command)
         matches = adjusted_perfect + adjusted_partial
         command_tuple = utils.find_one(test_name,
                                        matches,
                                        attributes=attributes)
         return loc, (command_tuple, )
     except MatchError as exc:
         exc.token = "command"
         exc.pstr = test_name
         raise exc
Пример #4
0
 def parseImpl(self, instring, loc, doActions=True):
     loc, text = super(CommandName, self).parseImpl(instring, loc, doActions)
     test_name = text.lower()
     try:
         if self.fullOnly:
             attributes = ["names"]
         else:
             attributes = ["names", "nospace_names"]
         from muss.handler import all_commands
         perfect_matches, partial_matches = utils.find_by_name(
             test_name, all_commands(), attributes=attributes)
         adjusted_perfect = [x[1] for x in perfect_matches]
         adjusted_partial = []
         for match_tuple in partial_matches:
             name, command = match_tuple
             if not command.require_full:
                 adjusted_partial.append(command)
         matches = adjusted_perfect + adjusted_partial
         command_tuple = utils.find_one(test_name, matches,
                                        attributes=attributes)
         return loc, (command_tuple,)
     except MatchError as exc:
         exc.token = "command"
         exc.pstr = test_name
         raise exc
Пример #5
0
    def test_help(self):
        from muss.handler import all_commands
        from muss.commands.help import Help

        for command in all_commands():
            names = [] + command().names + command().nospace_names
            send_count = len(command().usages) + 4

            for name in names:
                try:
                    self.run_command(Help, name)
                except parser.AmbiguityError:
                    # It's not a failure of the help system
                    # if command names are ambiguous.
                    continue
                help_sends = self.player.response_stack(send_count)
                usage_list = ["\t" + u for u in command().usages]

                self.assertEqual(help_sends[0][:len(name)], name.upper())
                self.assertEqual(help_sends[1], "Usage:")
                self.assertEqual(help_sends[2:-2], usage_list)
                self.assertEqual(help_sends[-2], "")
                self.assertEqual(help_sends[-1], command.help_text)