예제 #1
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
예제 #2
0
파일: help.py 프로젝트: mongolsamurai/MUSS
 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 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)))
예제 #5
0
 def test_multi_word_matching(self):
     perfect, partial = utils.find_by_name("plushie", self.objects.values(),
                                           attributes=["name"])
     self.assertEqual(partial[0],
                      ("ape plushie", self.objects["ape plushie"]))
     name, item = utils.find_one("guide", self.objects.values(),
                                 attributes=["name"])
     self.assertEqual(name, "Fodor's Guide")
     self.assertEqual(item, self.objects["Fodor's Guide"])
예제 #6
0
 def test_multi_word_matching(self):
     perfect, partial = utils.find_by_name("plushie",
                                           self.objects.values(),
                                           attributes=["name"])
     self.assertEqual(partial[0],
                      ("ape plushie", self.objects["ape plushie"]))
     name, item = utils.find_one("guide",
                                 self.objects.values(),
                                 attributes=["name"])
     self.assertEqual(name, "Fodor's Guide")
     self.assertEqual(item, self.objects["Fodor's Guide"])