@@ -156,9 +156,6 @@ def cast(file):
156156 )
157157
158158
159- _default_messenger = TeleBot ("" )
160-
161-
162159class UpdateType (Enum ):
163160 """
164161 Represents a type of the telegram update
@@ -184,7 +181,7 @@ class UpdateType(Enum):
184181
185182
186183def telegram_condition (
187- messenger : TeleBot = _default_messenger ,
184+ messenger : TeleBot = None ,
188185 update_type : UpdateType = UpdateType .MESSAGE ,
189186 commands : Optional [List [str ]] = None ,
190187 regexp : Optional [str ] = None ,
@@ -198,7 +195,7 @@ def telegram_condition(
198195
199196 :param messenger:
200197 Messenger to test filters on. Used only for :py:attr:`Telebot.custom_filters`.
201- Defaults to :py:data:`._default_messenger `.
198+ Defaults to the ``messenger`` attribute of :py:attr:`Pipeline.messenger_interface `.
202199 :param update_type:
203200 If set to any `UpdateType` other than `UpdateType.ALL`
204201 it will check that an update is of the same type.
@@ -220,7 +217,7 @@ def telegram_condition(
220217 See `link <https://github.com/eternnoir/pyTelegramBotAPI#general-api-documentation>`__.
221218 """
222219
223- update_handler = messenger ._build_handler_dict (
220+ update_handler = TeleBot ._build_handler_dict (
224221 None ,
225222 False ,
226223 commands = commands ,
@@ -231,7 +228,7 @@ def telegram_condition(
231228 ** kwargs ,
232229 )
233230
234- def condition (ctx : Context , _ : Pipeline , * __ , ** ___ ): # pragma: no cover
231+ def condition (ctx : Context , pipeline : Pipeline , * __ , ** ___ ): # pragma: no cover
235232 last_request = ctx .last_request
236233 if last_request is None :
237234 return False
@@ -241,6 +238,9 @@ def condition(ctx: Context, _: Pipeline, *__, **___): # pragma: no cover
241238 return False
242239 if update_type != UpdateType .ALL and request_update_type != update_type .value :
243240 return False
241+ nonlocal messenger
242+ if messenger is None :
243+ messenger = pipeline .messenger_interface .messenger
244244 test_result = messenger ._test_message_handler (update_handler , update )
245245 return test_result
246246
0 commit comments