diff --git a/game/gamesrc/commands/default/help.py b/game/gamesrc/commands/default/help.py index b50760d561..257302acc7 100644 --- a/game/gamesrc/commands/default/help.py +++ b/game/gamesrc/commands/default/help.py @@ -17,7 +17,9 @@ LIST_ARGS = ["list", "all"] def format_help_entry(title, help_text, aliases=None, suggested=None): - "This visually formats the help entry." + """ + This visually formats the help entry. + """ string = "-"*70 + "\n" if title: string += "Help topic for {w%s{n" % (title.capitalize()) @@ -33,13 +35,17 @@ def format_help_entry(title, help_text, aliases=None, return string def format_help_list(hdict_cmds, hdict_db): - "Output a category-ordered list" - string = "\n\r" + "-"*70 + "\n\r {gCommand help entries{n\n" + "-"*70 - for category in sorted(hdict_cmds.keys()): - string += "\n {w%s{n:\n" % \ - (str(category).capitalize()) - string += fill(", ".join(sorted(hdict_cmds[category]))) - if hdict_db: + """ + Output a category-ordered list. + """ + string = "" + if hdict_cmds and hdict_cmds.values(): + string += "\n\r" + "-"*70 + "\n\r {gCommand help entries{n\n" + "-"*70 + for category in sorted(hdict_cmds.keys()): + string += "\n {w%s{n:\n" % \ + (str(category).capitalize()) + string += fill(", ".join(sorted(hdict_cmds[category]))) + if hdict_db and hdict_db.values(): string += "\n\r\n\r" + "-"*70 + "\n\r {gOther help entries{n\n" + '-'*70 for category in sorted(hdict_db.keys()): string += "\n\r {w%s{n:\n" % (str(category).capitalize()) @@ -78,6 +84,10 @@ class CmdHelp(Command): if not query: query = "all" + + # removing doublets in cmdset, caused by cmdhandler + # having to allow doublet commands to manage exits etc. + cmdset.make_unique(caller) # Listing help entries @@ -129,15 +139,20 @@ class CmdHelp(Command): # Handle result if (not cmdmatches) and (not dbmatches): # no normal match. Check if this is a category match instead - categ_cmdmatches = [cmd for cmd in cmdset + categ_cmdmatches = [cmd.key for cmd in cmdset if query == cmd.help_category and has_perm(caller, cmd, 'cmd')] categ_dbmatches = \ - [topic for topic in + [topic.key for topic in HelpEntry.objects.find_topics_with_category(query) if has_perm(caller, topic, 'view')] - if categ_cmdmatches or categ_dbmatches: - help_entry = format_help_list({query:categ_cmdmatches}, - {query:categ_dbmatches}) + cmddict = None + dbdict = None + if categ_cmdmatches: + cmddict = {query:categ_cmdmatches} + if categ_dbmatches: + dbdict = {query:categ_dbmatches} + if cmddict or dbdict: + help_entry = format_help_list(cmddict, dbdict) else: help_entry = "No help entry found for '%s'" % query diff --git a/game/gamesrc/world/examples/batch_code.py b/game/gamesrc/world/examples/batch_code.py index aabf07154e..1998b524fc 100644 --- a/game/gamesrc/world/examples/batch_code.py +++ b/game/gamesrc/world/examples/batch_code.py @@ -70,8 +70,6 @@ caller.msg("A %s was created." % red_button.key) # again (so as to avoid duplicate objects when testing the script many # times). -caller.msg(limbo.key) - # the python variables we assign to must match the ones given in the # header for the system to be able to delete them afterwards during a # debugging run. diff --git a/src/commands/cmdset.py b/src/commands/cmdset.py index bca773bb5d..cb93d9cc99 100644 --- a/src/commands/cmdset.py +++ b/src/commands/cmdset.py @@ -259,7 +259,27 @@ class CmdSet(object): cmdset.key_mergetypes = copy.deepcopy(self.key_mergetypes) return cmdset - + def make_unique(self, caller): + """ + This is an unsafe command meant to clean out a cmdset of + doublet commands after it has been created. It is useful + for commands inheriting cmdsets from the cmdhandler where + obj-based cmdsets always are added double. Doublets will + be weeded out with preference to commands defined on caller, + otherwise just by first-come-first-served. + """ + unique = {} + for cmd in self.commands: + if cmd.key in unique: + ocmd = unique[cmd.key] + if (hasattr(cmd, 'obj') and cmd.obj == caller) and not \ + (hasattr(ocmd, 'obj') and ocmd.obj == caller): + unique[cmd.key] = cmd + else: + unique[cmd.key] = cmd + self.commands = unique.values() + + def __str__(self): """ Show all commands in cmdset when printing it.