Make sure to forward no_channels, no_objs and no_exits flags across cmdset merges. Also changes how system commands are saved across merges. Resolves Issue 243.
This commit is contained in:
parent
c2961ce5e2
commit
44bf35cd81
4 changed files with 42 additions and 16 deletions
|
|
@ -191,7 +191,30 @@ def cmdhandler(caller, raw_string, testing=False):
|
||||||
# This also checks for permissions, so all commands in match
|
# This also checks for permissions, so all commands in match
|
||||||
# are commands the caller is allowed to call.
|
# are commands the caller is allowed to call.
|
||||||
matches = yield _COMMAND_PARSER(raw_string, cmdset, caller)
|
matches = yield _COMMAND_PARSER(raw_string, cmdset, caller)
|
||||||
|
|
||||||
# Deal with matches
|
# Deal with matches
|
||||||
|
|
||||||
|
if len(matches) > 1:
|
||||||
|
# We have a multiple-match
|
||||||
|
syscmd = yield cmdset.get(CMD_MULTIMATCH)
|
||||||
|
sysarg = _("There where multiple matches.")
|
||||||
|
if syscmd:
|
||||||
|
syscmd.matches = matches
|
||||||
|
else:
|
||||||
|
sysarg = yield at_multimatch_cmd(caller, matches)
|
||||||
|
raise ExecSystemCommand(syscmd, sysarg)
|
||||||
|
|
||||||
|
if len(matches) == 1:
|
||||||
|
# We have a unique command match.
|
||||||
|
match = matches[0]
|
||||||
|
cmdname, args, cmd = match[0], match[1], match[2]
|
||||||
|
|
||||||
|
# check if we allow this type of command
|
||||||
|
if cmdset.no_channels and hasattr(cmd, "is_channel") and cmd.is_channel:
|
||||||
|
matches = []
|
||||||
|
if cmdset.no_exits and hasattr(cmd, "is_exit") and cmd.is_exit:
|
||||||
|
matches = []
|
||||||
|
|
||||||
if not matches:
|
if not matches:
|
||||||
# No commands match our entered command
|
# No commands match our entered command
|
||||||
syscmd = yield cmdset.get(CMD_NOMATCH)
|
syscmd = yield cmdset.get(CMD_NOMATCH)
|
||||||
|
|
@ -206,19 +229,6 @@ def cmdhandler(caller, raw_string, testing=False):
|
||||||
sysarg += _(" Type \"help\" for help.")
|
sysarg += _(" Type \"help\" for help.")
|
||||||
raise ExecSystemCommand(syscmd, sysarg)
|
raise ExecSystemCommand(syscmd, sysarg)
|
||||||
|
|
||||||
if len(matches) > 1:
|
|
||||||
# We have a multiple-match
|
|
||||||
syscmd = yield cmdset.get(CMD_MULTIMATCH)
|
|
||||||
sysarg = _("There where multiple matches.")
|
|
||||||
if syscmd:
|
|
||||||
syscmd.matches = matches
|
|
||||||
else:
|
|
||||||
sysarg = yield at_multimatch_cmd(caller, matches)
|
|
||||||
raise ExecSystemCommand(syscmd, sysarg)
|
|
||||||
|
|
||||||
# At this point, we have a unique command match.
|
|
||||||
match = matches[0]
|
|
||||||
cmdname, args, cmd = match[0], match[1], match[2]
|
|
||||||
|
|
||||||
# Check if this is a Channel match.
|
# Check if this is a Channel match.
|
||||||
if hasattr(cmd, 'is_channel') and cmd.is_channel:
|
if hasattr(cmd, 'is_channel') and cmd.is_channel:
|
||||||
|
|
|
||||||
|
|
@ -244,11 +244,15 @@ class CmdSet(object):
|
||||||
if not cmdset_b:
|
if not cmdset_b:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
# preserve system __commands
|
sys_commands_a = self.get_system_cmds()
|
||||||
sys_commands = self.get_system_cmds() + cmdset_b.get_system_cmds()
|
sys_commands_b = cmdset_b.get_system_cmds()
|
||||||
|
|
||||||
if self.priority >= cmdset_b.priority:
|
if self.priority >= cmdset_b.priority:
|
||||||
# A higher or equal priority than B
|
# A higher or equal priority than B
|
||||||
|
|
||||||
|
# preserve system __commands
|
||||||
|
sys_commands = sys_commands_a + [cmd for cmd in sys_commands_b if cmd not in sys_commands_a]
|
||||||
|
|
||||||
mergetype = self.key_mergetypes.get(cmdset_b.key, self.mergetype)
|
mergetype = self.key_mergetypes.get(cmdset_b.key, self.mergetype)
|
||||||
if mergetype == "Intersect":
|
if mergetype == "Intersect":
|
||||||
cmdset_c = self._intersect(self, cmdset_b, cmdset_b.duplicates)
|
cmdset_c = self._intersect(self, cmdset_b, cmdset_b.duplicates)
|
||||||
|
|
@ -258,8 +262,16 @@ class CmdSet(object):
|
||||||
cmdset_c = self._remove(self, cmdset_b, cmdset_b.duplicates)
|
cmdset_c = self._remove(self, cmdset_b, cmdset_b.duplicates)
|
||||||
else: # Union
|
else: # Union
|
||||||
cmdset_c = self._union(self, cmdset_b, cmdset_b.duplicates)
|
cmdset_c = self._union(self, cmdset_b, cmdset_b.duplicates)
|
||||||
|
cmdset_c.no_channels = self.no_channels
|
||||||
|
cmdset_c.no_exits = self.no_exits
|
||||||
|
cmdset_c.no_objs = self.no_objs
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# B higher priority than A
|
# B higher priority than A
|
||||||
|
|
||||||
|
# preserver system __commands
|
||||||
|
sys_commands = sys_commands_b + [cmd for cmd in sys_commands_a if cmd not in sys_commands_b]
|
||||||
|
|
||||||
mergetype = cmdset_b.key_mergetypes.get(self.key, cmdset_b.mergetype)
|
mergetype = cmdset_b.key_mergetypes.get(self.key, cmdset_b.mergetype)
|
||||||
if mergetype == "Intersect":
|
if mergetype == "Intersect":
|
||||||
cmdset_c = self._intersect(cmdset_b, self, self.duplicates)
|
cmdset_c = self._intersect(cmdset_b, self, self.duplicates)
|
||||||
|
|
@ -269,6 +281,9 @@ class CmdSet(object):
|
||||||
cmdset_c = self._remove(self, cmdset_b, self.duplicates)
|
cmdset_c = self._remove(self, cmdset_b, self.duplicates)
|
||||||
else: # Union
|
else: # Union
|
||||||
cmdset_c = self._union(cmdset_b, self, self.duplicates)
|
cmdset_c = self._union(cmdset_b, self, self.duplicates)
|
||||||
|
cmdset_c.no_channels = cmdset_b.no_channels
|
||||||
|
cmdset_c.no_exits = cmdset_b.no_exits
|
||||||
|
cmdset_c.no_objs = cmdset_b.no_objs
|
||||||
|
|
||||||
# we store actual_mergetype since key_mergetypes
|
# we store actual_mergetype since key_mergetypes
|
||||||
# might be different from the main mergetype.
|
# might be different from the main mergetype.
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ class CmdSetHandler(object):
|
||||||
permstring = "perm"
|
permstring = "perm"
|
||||||
string += _(" <%(key)s (%(mergetype)s, prio %(prio)i, %(permstring)s)>: %(keylist)s") % \
|
string += _(" <%(key)s (%(mergetype)s, prio %(prio)i, %(permstring)s)>: %(keylist)s") % \
|
||||||
{"key":self.current.key, "mergetype":mergetype, "prio":self.current.priority, "permstring":permstring,
|
{"key":self.current.key, "mergetype":mergetype, "prio":self.current.priority, "permstring":permstring,
|
||||||
"keylost":", ".join(cmd.key for cmd in sorted(self.current, key=lambda o:o.key))}
|
"keylist":", ".join(cmd.key for cmd in sorted(self.current, key=lambda o:o.key))}
|
||||||
return string.strip()
|
return string.strip()
|
||||||
|
|
||||||
def _import_cmdset(self, cmdset_path, emit_to_obj=None):
|
def _import_cmdset(self, cmdset_path, emit_to_obj=None):
|
||||||
|
|
|
||||||
|
|
@ -828,6 +828,7 @@ class Exit(Object):
|
||||||
locks = "cmd:all()" # should always be set to this.
|
locks = "cmd:all()" # should always be set to this.
|
||||||
obj = None
|
obj = None
|
||||||
arg_regex=r"\s.*?|$"
|
arg_regex=r"\s.*?|$"
|
||||||
|
is_exit = True # this helps cmdhandler disable exits in cmdsets with no_exits=True.
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
"Default exit traverse if no syscommand is defined."
|
"Default exit traverse if no syscommand is defined."
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue