From 072d480439f355ed48db06b37baf5cf0e69f13db Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 27 Jun 2020 12:56:58 +0200 Subject: [PATCH] Fix cmdset merge with systemcmd. Resolves #2146 --- evennia/commands/cmdhandler.py | 8 ++++---- evennia/commands/cmdset.py | 15 ++++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/evennia/commands/cmdhandler.py b/evennia/commands/cmdhandler.py index a0d9be8842..e0a3d86f87 100644 --- a/evennia/commands/cmdhandler.py +++ b/evennia/commands/cmdhandler.py @@ -472,13 +472,13 @@ def get_and_merge_cmdsets(caller, session, account, obj, callertype, raw_string) tempmergers[prio] = cmdset # sort cmdsets after reverse priority (highest prio are merged in last) - cmdsets = yield sorted(list(tempmergers.values()), key=lambda x: x.priority) + sorted_cmdsets = yield sorted(list(tempmergers.values()), key=lambda x: x.priority) # Merge all command sets into one, beginning with the lowest-prio one - cmdset = cmdsets[0] - for merging_cmdset in cmdsets[1:]: + cmdset = sorted_cmdsets[0] + for merging_cmdset in sorted_cmdsets[1:]: cmdset = yield cmdset + merging_cmdset - # store the full sets for diagnosis + # store the original, ungrouped set for diagnosis cmdset.merged_from = cmdsets # cache _CMDSET_MERGE_CACHE[mergehash] = cmdset diff --git a/evennia/commands/cmdset.py b/evennia/commands/cmdset.py index f124bbbb06..f296982905 100644 --- a/evennia/commands/cmdset.py +++ b/evennia/commands/cmdset.py @@ -443,12 +443,12 @@ class CmdSet(object, metaclass=_CmdSetMeta): # print "__add__ for %s (prio %i) called with %s (prio %i)." % (self.key, self.priority, cmdset_a.key, cmdset_a.priority) # return the system commands to the cmdset - cmdset_c.add(sys_commands) + cmdset_c.add(sys_commands, allow_duplicates=True) return cmdset_c - def add(self, cmd): + def add(self, cmd, allow_duplicates=False): """ - Add a new command or commands to this CmdSetcommand, a list of + Add a new command or commands to this CmdSet, a list of commands or a cmdset to this cmdset. Note that this is *not* a merge operation (that is handled by the + operator). @@ -456,6 +456,9 @@ class CmdSet(object, metaclass=_CmdSetMeta): cmd (Command, list, Cmdset): This allows for adding one or more commands to this Cmdset in one go. If another Cmdset is given, all its commands will be added. + allow_duplicates (bool, optional): If set, will not try to remove + duplicate cmds in the set. This is needed during the merge process + to avoid wiping commands coming from cmdsets with duplicate=True. Notes: If cmd already exists in set, it will replace the old one @@ -498,8 +501,10 @@ class CmdSet(object, metaclass=_CmdSetMeta): commands[ic] = cmd # replace except ValueError: commands.append(cmd) - # extra run to make sure to avoid doublets - self.commands = list(set(commands)) + self.commands = commands + if not allow_duplicates: + # extra run to make sure to avoid doublets + self.commands = list(set(self.commands)) # add system_command to separate list as well, # for quick look-up if cmd.key.startswith("__"):