Check all hooks for a command and pick the first applicable one, to allow for
private_only and channel_only commands to share the same command string (commands.py)
This commit is contained in:
parent
b197a537f0
commit
8a832b7230
1 changed files with 26 additions and 17 deletions
|
@ -140,24 +140,33 @@ class Module(ModuleManager.BaseModule):
|
||||||
if ignore:
|
if ignore:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
hook = None
|
||||||
|
target = None
|
||||||
|
for potential_hook in self.get_hook(command):
|
||||||
hook = self.get_hook(command)
|
hook = self.get_hook(command)
|
||||||
alias_of = self._get_alias_of(hook)
|
alias_of = self._get_alias_of(hook)
|
||||||
if alias_of:
|
if alias_of:
|
||||||
if self.has_command(alias_of):
|
if self.has_command(alias_of):
|
||||||
hook = self.get_hook(alias_of)
|
hook = self.get_hook(alias_of)
|
||||||
else:
|
else:
|
||||||
raise ValueError("'%s' is an alias of unknown command '%s'"
|
raise ValueError(
|
||||||
|
"'%s' is an alias of unknown command '%s'"
|
||||||
% (command.lower(), alias_of.lower()))
|
% (command.lower(), alias_of.lower()))
|
||||||
|
|
||||||
is_channel = False
|
is_channel = False
|
||||||
|
if not is_channel and hook.kwargs.get("channel_only"):
|
||||||
|
continue
|
||||||
|
if is_channel and hook.kwargs.get("private_only"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
hook = potential_hook
|
||||||
if "channel" in event:
|
if "channel" in event:
|
||||||
target = event["channel"]
|
target = event["channel"]
|
||||||
is_channel = True
|
is_channel = True
|
||||||
else:
|
else:
|
||||||
target = event["user"]
|
target = event["user"]
|
||||||
if not is_channel and hook.kwargs.get("channel_only"):
|
|
||||||
return
|
if not hook:
|
||||||
if is_channel and hook.kwargs.get("private_only"):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
module_name = self._get_prefix(hook) or ""
|
module_name = self._get_prefix(hook) or ""
|
||||||
|
|
Loading…
Reference in a new issue