L idZddlZddlmZmZmZmZmZddlm Z ddl m Z ddl m Z mZddlmZddlmZdd lmZmZerdd lmZed ZGd d ee eefZy)z-This module contains the PrefixHandler class.N) TYPE_CHECKINGAnyOptionalTypeVarUnion)Update) DEFAULT_TRUE)SCTDVType)filters) BaseHandler)CCTHandlerCallback) ApplicationRTc eZdZdZdZdefdddeedeedee e e fd e e jd eef fd Zd ed e eeeeee eeeeefffffdZde d e ddde eeeeee effd df dZxZS) PrefixHandleraHandler class to handle custom prefix commands. This is an intermediate handler between :class:`MessageHandler` and :class:`CommandHandler`. It supports configurable commands with the same options as :class:`CommandHandler`. It will respond to every combination of :paramref:`prefix` and :paramref:`command`. It will add a :obj:`list` to the :class:`CallbackContext` named :attr:`CallbackContext.args`, containing a list of strings, which is the text following the command split on single or consecutive whitespace characters. Examples: Single prefix and command: .. code:: python PrefixHandler("!", "test", callback) # will respond to '!test'. Multiple prefixes, single command: .. code:: python PrefixHandler(["!", "#"], "test", callback) # will respond to '!test' and '#test'. Multiple prefixes and commands: .. code:: python PrefixHandler( ["!", "#"], ["test", "help"], callback ) # will respond to '!test', '#test', '!help' and '#help'. By default, the handler listens to messages as well as edited messages. To change this behavior use :attr:`~filters.UpdateType.EDITED_MESSAGE ` Note: * :class:`PrefixHandler` does *not* handle (edited) channel posts. Warning: When setting :paramref:`block` to :obj:`False`, you cannot rely on adding custom attributes to :class:`telegram.ext.CallbackContext`. See its docs for more info. .. versionchanged:: 20.0 * :class:`PrefixHandler` is no longer a subclass of :class:`CommandHandler`. * Removed the attributes ``command`` and ``prefix``. Instead, the new :attr:`commands` contains all commands that this handler listens to as a :class:`frozenset`, which includes the prefixes. * Updating the prefixes and commands this handler listens to is no longer possible. Args: prefix (:obj:`str` | Collection[:obj:`str`]): The prefix(es) that will precede :paramref:`command`. command (:obj:`str` | Collection[:obj:`str`]): The command or list of commands this handler should listen for. Case-insensitive. callback (:term:`coroutine function`): The callback function for this handler. Will be called when :meth:`check_update` has determined that an update should be processed by this handler. Callback signature:: async def callback(update: Update, context: CallbackContext) The return value of the callback is usually ignored except for the special case of :class:`telegram.ext.ConversationHandler`. filters (:class:`telegram.ext.filters.BaseFilter`, optional): A filter inheriting from :class:`telegram.ext.filters.BaseFilter`. Standard filters can be found in :mod:`telegram.ext.filters`. Filters can be combined using bitwise operators (``&`` for :keyword:`and`, ``|`` for :keyword:`or`, ``~`` for :keyword:`not`) block (:obj:`bool`, optional): Determines whether the return value of the callback should be awaited before processing the next handler in :meth:`telegram.ext.Application.process_update`. Defaults to :obj:`True`. .. seealso:: :wiki:`Concurrency` Attributes: commands (frozenset[:obj:`str`]): The commands that this handler will listen for, i.e. the combinations of :paramref:`prefix` and :paramref:`command`. callback (:term:`coroutine function`): The callback function for this handler. filters (:class:`telegram.ext.filters.BaseFilter`): Optional. Only allow updates with these Filters. block (:obj:`bool`): Determines whether the return value of the callback should be awaited before processing the next handler in :meth:`telegram.ext.Application.process_update`. )commandsr NselfzPrefixHandler[CCT, RT]prefixcommandcallbackr blockct |||t|tr|j hn|Dchc]}|j c}}t|tr|j hn|Dchc]}|j c}}t dt j||D|_|||_ ytjj|_ ycc}wcc}w)N)rrc3,K|] \}}||zyw)N).0pcs j/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/ext/_handlers/prefixhandler.py z)PrefixHandler.__init__..s2 aAE2 s) super__init__ isinstancestrlower frozenset itertoolsproductrfilters_module UpdateTypeMESSAGESr ) rrrrr rxprefixesr __class__s r r#zPrefixHandler.__init__~s (%8'1&#'>FLLN#X^D_STQWWYD_(27C(@GMMO$ZaFbUVqwwyFb(12 '//(C2 )  *G 0>0I0I0R0R E`Fbs C&7C+updatereturnc*t|tr|jrw|j}|jr_|jj }|dj |j vry|jj|}|r|dd|fSyy)aDetermines whether an update should be passed to this handler's :attr:`callback`. Args: update (:class:`telegram.Update` | :obj:`object`): Incoming update. Returns: :obj:`list`: The list of args for the handler. rNF) r$reffective_messagetextsplitr&rr check_update)rr0message text_list filter_results r r7zPrefixHandler.check_updates ff %&*B*B..G||#LL..0 Q<%%'t}}< $ 9 9& A  $QR=-77context applicationz)Application[Any, CCT, Any, Any, Any, Any] check_resultct|tr3|d|_t|dtr|j |dyyy)zAdd text after the command to :attr:`CallbackContext.args` as list, split on single whitespaces and add output of data filters to :attr:`CallbackContext` as well. rr3N)r$tupleargsdictr0)rr<r0r=r>s r collect_additional_contextz(PrefixHandler.collect_additional_contextsA lE *'?GL,q/40|A/1 +r;)__name__ __module__ __qualname____doc__ __slots__r r r%rrrrrr* BaseFilterr boolr#objectrr@listrBrr7rC __classcell__)r/s@r rr%sSl(I8<*  & C S "&#r/2  .334  d|  * %eDIxdDcN>R8S/T$TUUV W2 0 0 0A 0 uT5cHTN1J+K%KLM 0  0r;r)rGr(typingrrrrrtelegramrtelegram._utils.defaultvaluer telegram._utils.typesr r telegram.extr r*"telegram.ext._handlers.basehandlerr telegram.ext._utils.typesrrrrrrr;r rUsM&4??5-2::( T]T0KR0T0r;