mirror of
https://github.com/Nick80835/microbot
synced 2025-08-29 05:29:16 +00:00
use an argument for lenient commands, small cleanup/fix
This commit is contained in:
parent
04227f6628
commit
8d4bf479de
@ -351,3 +351,16 @@ class CommandHandler():
|
|||||||
@property
|
@property
|
||||||
def all_incoming_commands(self) -> list[Command]:
|
def all_incoming_commands(self) -> list[Command]:
|
||||||
return self.incoming_commands + self.incoming_lenient_commands
|
return self.incoming_commands + self.incoming_lenient_commands
|
||||||
|
|
||||||
|
def push_incoming_command(self, command: Command, lenient: bool = False):
|
||||||
|
if lenient:
|
||||||
|
self.incoming_lenient_commands.append(command)
|
||||||
|
else:
|
||||||
|
self.incoming_commands.append(command)
|
||||||
|
|
||||||
|
def clear_commands(self):
|
||||||
|
self.incoming_commands = []
|
||||||
|
self.incoming_lenient_commands = []
|
||||||
|
self.inline_photo_commands = []
|
||||||
|
self.inline_article_commands = []
|
||||||
|
self.callback_queries = []
|
||||||
|
@ -55,12 +55,7 @@ class Loader():
|
|||||||
print_exc()
|
print_exc()
|
||||||
|
|
||||||
def reload_all_modules(self):
|
def reload_all_modules(self):
|
||||||
self.command_handler.incoming_commands = []
|
self.command_handler.clear_commands()
|
||||||
self.command_handler.incoming_lenient_commands = []
|
|
||||||
self.command_handler.inline_photo_commands = []
|
|
||||||
self.command_handler.inline_article_commands = []
|
|
||||||
self.command_handler.callback_queries = []
|
|
||||||
|
|
||||||
errors = ""
|
errors = ""
|
||||||
|
|
||||||
for module in self.loaded_modules:
|
for module in self.loaded_modules:
|
||||||
@ -74,32 +69,23 @@ class Loader():
|
|||||||
|
|
||||||
return errors or None
|
return errors or None
|
||||||
|
|
||||||
def add(self, pattern: str = None, **args):
|
def add(self, pattern: str = None, lenient: bool = False, **args):
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
args["pattern"] = args.get("pattern", pattern)
|
args["pattern"] = args.get("pattern", pattern)
|
||||||
self.command_handler.incoming_commands.append(Command(func, args))
|
self.command_handler.push_incoming_command(Command(func, args), lenient)
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
def add_lenient(self, pattern: str = None, **args):
|
def add_list(self, pattern: list = None, lenient: bool = False, **args):
|
||||||
def decorator(func):
|
|
||||||
args["pattern"] = args.get("pattern", pattern)
|
|
||||||
self.command_handler.incoming_lenient_commands.append(Command(func, args))
|
|
||||||
|
|
||||||
return func
|
|
||||||
|
|
||||||
return decorator
|
|
||||||
|
|
||||||
def add_list(self, pattern: list = None, **args):
|
|
||||||
pattern_list = args.get("pattern", pattern)
|
pattern_list = args.get("pattern", pattern)
|
||||||
|
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
for pattern in pattern_list:
|
for pattern in pattern_list:
|
||||||
this_args = args.copy()
|
this_args = args.copy()
|
||||||
this_args["pattern"] = pattern
|
this_args["pattern"] = pattern
|
||||||
self.command_handler.incoming_commands.append(Command(func, this_args))
|
self.command_handler.push_incoming_command(Command(func, this_args), lenient)
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
@ -115,12 +101,12 @@ class Loader():
|
|||||||
this_args = args.copy()
|
this_args = args.copy()
|
||||||
this_args["pattern"] = patt
|
this_args["pattern"] = patt
|
||||||
this_args["extra"] = args.get('extra', extra)
|
this_args["extra"] = args.get('extra', extra)
|
||||||
self.command_handler.incoming_commands.append(Command(func, this_args))
|
self.command_handler.push_incoming_command(Command(func, this_args), args.get("lenient", False))
|
||||||
else:
|
else:
|
||||||
this_args = args.copy()
|
this_args = args.copy()
|
||||||
this_args["pattern"] = pattern
|
this_args["pattern"] = pattern
|
||||||
this_args["extra"] = args.get('extra', extra)
|
this_args["extra"] = args.get('extra', extra)
|
||||||
self.command_handler.incoming_commands.append(Command(func, this_args))
|
self.command_handler.push_incoming_command(Command(func, this_args), args.get("lenient", False))
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
@ -154,7 +140,7 @@ class Loader():
|
|||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
def get_cmds_by_func(self, func) -> list:
|
def get_cmds_by_func(self, func) -> list:
|
||||||
return [i for i in self.command_handler.incoming_commands if i.function == func]
|
return [i for i in self.command_handler.all_incoming_commands if i.function == func]
|
||||||
|
|
||||||
def get_cbs_by_func(self, func) -> list:
|
def get_cbs_by_func(self, func) -> list:
|
||||||
return [i for i in self.command_handler.callback_queries if i.function == func]
|
return [i for i in self.command_handler.callback_queries if i.function == func]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user