1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Fix check of the regexp and commands types

This commit is contained in:
Badiboy 2022-02-19 21:39:02 +03:00
parent fc374ec57a
commit 6c31b53cd9

View File

@ -2741,11 +2741,13 @@ class TeleBot:
""" """
self.add_middleware_handler(callback, update_types) self.add_middleware_handler(callback, update_types)
def __check_commands_input(self, commands, method_name): @staticmethod
def check_commands_input(commands, method_name):
if not isinstance(commands, list) or not all(isinstance(item, str) for item in commands): if not isinstance(commands, list) or not all(isinstance(item, str) for item in commands):
logger.error(f"{method_name}: Commands filter should be list of strings (commands), unknown type supplied to the 'commands' filter list. Not able to use the supplied type.") logger.error(f"{method_name}: Commands filter should be list of strings (commands), unknown type supplied to the 'commands' filter list. Not able to use the supplied type.")
def __check_regexp_input(self, regexp, method_name): @staticmethod
def check_regexp_input(regexp, method_name):
if not isinstance(regexp, str): if not isinstance(regexp, str):
logger.error(f"{method_name}: Regexp filter should be string. Not able to use the supplied type.") logger.error(f"{method_name}: Regexp filter should be string. Not able to use the supplied type.")
@ -2794,10 +2796,12 @@ class TeleBot:
method_name = "message_handler" method_name = "message_handler"
if commands is not None: if commands is not None:
self.__check_commands_input(commands, method_name) self.check_commands_input(commands, method_name)
if isinstance(commands, str):
commands = [commands]
if regexp is not None: if regexp is not None:
self.__check_regexp_input(regexp, method_name) self.check_regexp_input(regexp, method_name)
if isinstance(content_types, str): if isinstance(content_types, str):
logger.warning("message_handler: 'content_types' filter should be List of strings (content types), not string.") logger.warning("message_handler: 'content_types' filter should be List of strings (content types), not string.")
@ -2839,10 +2843,12 @@ class TeleBot:
method_name = "register_message_handler" method_name = "register_message_handler"
if commands is not None: if commands is not None:
self.__check_commands_input(commands, method_name) self.check_commands_input(commands, method_name)
if isinstance(commands, str):
commands = [commands]
if regexp is not None: if regexp is not None:
self.__check_regexp_input(regexp, method_name) self.check_regexp_input(regexp, method_name)
if isinstance(content_types, str): if isinstance(content_types, str):
logger.warning("register_message_handler: 'content_types' filter should be List of strings (content types), not string.") logger.warning("register_message_handler: 'content_types' filter should be List of strings (content types), not string.")
@ -2875,10 +2881,12 @@ class TeleBot:
method_name = "edited_message_handler" method_name = "edited_message_handler"
if commands is not None: if commands is not None:
self.__check_commands_input(commands, method_name) self.check_commands_input(commands, method_name)
if isinstance(commands, str):
commands = [commands]
if regexp is not None: if regexp is not None:
self.__check_regexp_input(regexp, method_name) self.check_regexp_input(regexp, method_name)
if isinstance(content_types, str): if isinstance(content_types, str):
logger.warning("edited_message_handler: 'content_types' filter should be List of strings (content types), not string.") logger.warning("edited_message_handler: 'content_types' filter should be List of strings (content types), not string.")
@ -2920,10 +2928,12 @@ class TeleBot:
method_name = "register_edited_message_handler" method_name = "register_edited_message_handler"
if commands is not None: if commands is not None:
self.__check_commands_input(commands, method_name) self.check_commands_input(commands, method_name)
if isinstance(commands, str):
commands = [commands]
if regexp is not None: if regexp is not None:
self.__check_regexp_input(regexp, method_name) self.check_regexp_input(regexp, method_name)
if isinstance(content_types, str): if isinstance(content_types, str):
logger.warning("register_edited_message_handler: 'content_types' filter should be List of strings (content types), not string.") logger.warning("register_edited_message_handler: 'content_types' filter should be List of strings (content types), not string.")
@ -2956,10 +2966,12 @@ class TeleBot:
method_name = "channel_post_handler" method_name = "channel_post_handler"
if commands is not None: if commands is not None:
self.__check_commands_input(commands, method_name) self.check_commands_input(commands, method_name)
if isinstance(commands, str):
commands = [commands]
if regexp is not None: if regexp is not None:
self.__check_regexp_input(regexp, method_name) self.check_regexp_input(regexp, method_name)
if isinstance(content_types, str): if isinstance(content_types, str):
logger.warning("channel_post_handler: 'content_types' filter should be List of strings (content types), not string.") logger.warning("channel_post_handler: 'content_types' filter should be List of strings (content types), not string.")
@ -2999,10 +3011,12 @@ class TeleBot:
method_name = "register_channel_post_handler" method_name = "register_channel_post_handler"
if commands is not None: if commands is not None:
self.__check_commands_input(commands, method_name) self.check_commands_input(commands, method_name)
if isinstance(commands, str):
commands = [commands]
if regexp is not None: if regexp is not None:
self.__check_regexp_input(regexp, method_name) self.check_regexp_input(regexp, method_name)
if isinstance(content_types, str): if isinstance(content_types, str):
logger.warning("register_channel_post_handler: 'content_types' filter should be List of strings (content types), not string.") logger.warning("register_channel_post_handler: 'content_types' filter should be List of strings (content types), not string.")
@ -3033,10 +3047,12 @@ class TeleBot:
method_name = "edited_channel_post_handler" method_name = "edited_channel_post_handler"
if commands is not None: if commands is not None:
self.__check_commands_input(commands, method_name) self.check_commands_input(commands, method_name)
if isinstance(commands, str):
commands = [commands]
if regexp is not None: if regexp is not None:
self.__check_regexp_input(regexp, method_name) self.check_regexp_input(regexp, method_name)
if isinstance(content_types, str): if isinstance(content_types, str):
logger.warning("edited_channel_post_handler: 'content_types' filter should be List of strings (content types), not string.") logger.warning("edited_channel_post_handler: 'content_types' filter should be List of strings (content types), not string.")
@ -3076,10 +3092,12 @@ class TeleBot:
method_name = "register_edited_channel_post_handler" method_name = "register_edited_channel_post_handler"
if commands is not None: if commands is not None:
self.__check_commands_input(commands, method_name) self.check_commands_input(commands, method_name)
if isinstance(commands, str):
commands = [commands]
if regexp is not None: if regexp is not None:
self.__check_regexp_input(regexp, method_name) self.check_regexp_input(regexp, method_name)
if isinstance(content_types, str): if isinstance(content_types, str):
logger.warning("register_edited_channel_post_handler: 'content_types' filter should be List of strings (content types), not string.") logger.warning("register_edited_channel_post_handler: 'content_types' filter should be List of strings (content types), not string.")