Fix active command handlers for multi-instance plugins
This commit is contained in:
parent
9d38c43576
commit
b926f1e59d
1 changed files with 19 additions and 4 deletions
|
@ -55,8 +55,27 @@ class CommandHandler:
|
||||||
self.__mb_event_handler__: bool = True
|
self.__mb_event_handler__: bool = True
|
||||||
self.__mb_event_type__: EventType = EventType.ROOM_MESSAGE
|
self.__mb_event_type__: EventType = EventType.ROOM_MESSAGE
|
||||||
self.__mb_msgtypes__: List[MessageType] = (MessageType.TEXT,)
|
self.__mb_msgtypes__: List[MessageType] = (MessageType.TEXT,)
|
||||||
|
self.__instance_vars: Dict[str, CommandHandler] = {}
|
||||||
self.__class_instance: Any = None
|
self.__class_instance: Any = None
|
||||||
|
|
||||||
|
def __copy__(self) -> 'CommandHandler':
|
||||||
|
new_ch = type(self)(self.__mb_func__)
|
||||||
|
keys = ["parent", "subcommands", "arguments", "help", "get_name", "is_command_match",
|
||||||
|
"require_subcommand", "arg_fallthrough", "event_handler", "event_type", "msgtypes"]
|
||||||
|
for key in keys:
|
||||||
|
key = f"__mb_${key}__"
|
||||||
|
setattr(new_ch, key, getattr(self, key))
|
||||||
|
return new_ch
|
||||||
|
|
||||||
|
def __get__(self, instance, instancetype):
|
||||||
|
try:
|
||||||
|
return self.__instance_vars[instance]
|
||||||
|
except KeyError:
|
||||||
|
copy = self.__copy__()
|
||||||
|
copy.__class_instance = instance
|
||||||
|
self.__instance_vars[instance] = copy
|
||||||
|
return copy
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __command_match_unset(self, val: str) -> str:
|
def __command_match_unset(self, val: str) -> str:
|
||||||
raise NotImplementedError("Hmm")
|
raise NotImplementedError("Hmm")
|
||||||
|
@ -117,10 +136,6 @@ class CommandHandler:
|
||||||
return False, remaining_val
|
return False, remaining_val
|
||||||
return True, remaining_val
|
return True, remaining_val
|
||||||
|
|
||||||
def __get__(self, instance, instancetype):
|
|
||||||
self.__class_instance = instance
|
|
||||||
return self
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __mb_full_help__(self) -> str:
|
def __mb_full_help__(self) -> str:
|
||||||
usage = self.__mb_usage_without_subcommands__ + "\n\n"
|
usage = self.__mb_usage_without_subcommands__ + "\n\n"
|
||||||
|
|
Loading…
Reference in a new issue