L iX'dZddlZddlmZmZmZmZmZddlm Z m Z ddl m Z ddl mZmZddlmZddlmZdd lmZmZmZerdd lmZed ZGd d ee eefZy)z.This module contains the CommandHandler class.N) TYPE_CHECKINGAnyOptionalTypeVarUnion) MessageEntityUpdate) DEFAULT_TRUE)SCTDVType)filters) BaseHandler)CCTFilterDataDictHandlerCallback) ApplicationRTc(eZdZdZdZdedfdddeedee e e fde e jd eed e eeeff fd Zd eed e efdZded e eeeeee eeeffffdZde de ddde eeeeee effd df dZxZS)CommandHandlera_Handler class to handle Telegram commands. Commands are Telegram messages that start with a :attr:`telegram.MessageEntity.BOT_COMMAND` (so with ``/``, optionally followed by an ``@`` and the bot's name and/or some additional text). The handler will add a :obj:`list` to the :class:`CallbackContext` named :attr:`CallbackContext.args`. It will contain a list of strings, which is the text following the command split on single or consecutive whitespace characters. By default, the handler listens to messages as well as edited messages. To change this behavior use :attr:`~filters.UpdateType.EDITED_MESSAGE ` in the filter argument. Note: :class:`CommandHandler` does *not* handle (edited) channel posts and does *not* handle commands that are part of a caption. Please use :class:`~telegram.ext.MessageHandler` with a suitable combination of filters (e.g. :attr:`telegram.ext.filters.UpdateType.CHANNEL_POSTS`, :attr:`telegram.ext.filters.CAPTION` and :class:`telegram.ext.filters.Regex`) to handle those messages. Note: If you want to support a different entity in the beginning, e.g. if a command message is wrapped in a :attr:`telegram.MessageEntity.CODE`, use the :class:`telegram.ext.PrefixHandler`. 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. Examples: * :any:`Timer Bot ` * :any:`Error Handler Bot ` .. versionchanged:: 20.0 * Renamed the attribute ``command`` to :attr:`commands`, which now is always a :class:`frozenset` * Updating the commands this handler listens to is no longer possible. Args: command (:obj:`str` | Collection[:obj:`str`]): The command or list of commands this handler should listen for. Case-insensitive. Limitations are the same as for :attr:`telegram.BotCommand.command`. 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` has_args (:obj:`bool` | :obj:`int`, optional): Determines whether the command handler should process the update or not. If :obj:`True`, the handler will process any non-zero number of args. If :obj:`False`, the handler will only process if there are no args. if :obj:`int`, the handler will only process if there are exactly that many args. Defaults to :obj:`None`, which means the handler will process any or no args. .. versionadded:: 20.5 Raises: :exc:`ValueError`: When the command is too long or has illegal chars. Attributes: commands (frozenset[:obj:`str`]): The set of commands this handler should listen for. 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`. has_args (:obj:`bool` | :obj:`int` | None): Optional argument, otherwise all implementations of :class:`CommandHandler` will break. Defaults to :obj:`None`, which means the handler will process any args or no args. .. versionadded:: 20.5 )commandsr has_argsNselfzCommandHandler[CCT, RT]commandcallbackr blockrct|||t|trt |j h}nt d|D}|D]'}t jd|rtd|d||_ ||ntjj|_ ||_t|jtr|jdkr tdyy)N)rc3<K|]}|jyw)N)lower).0xs k/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/ext/_handlers/commandhandler.py z*CommandHandler.__init__..s +E+EF||))+AB/ ' c 2 $$W__%6%?%?@"!$**, =%a(..0GOO4E4N4N4T4T4VV//5 $ 9 9& A  ..r1context 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. rr:N)r%tupler2dictr8)rrKr8rLrMs r!collect_additional_contextz)CommandHandler.collect_additional_contextsA lE *'?GL,q/40|A/1 +r1)__name__ __module__ __qualname____doc__ __slots__r r r&rr rrrr+ BaseFilterr r5rr.r$listr7objectrOrrGrQ __classcell__)r0s@r!rr%s@Un4I 8<*/3 ^'^S^"&#r/2^.334 ^ d| ^ 5s+, ^8  S  htn  (( %eDIxdN>R8S/T$TUUV W(T 0 0 0A 0 uT5cHTN1J+K%KLM 0  0r1r)rUr(typingrrrrrtelegramrr telegram._utils.defaultvaluer telegram._utils.typesr r telegram.extr r+"telegram.ext._handlers.basehandlerrtelegram.ext._utils.typesrrrrrrr1r!rcsP&5 ??*5-2:JJ( T]{0[b1{0r1