o
    Zzj�£  ã                   @   sJ  d Z ddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZ zddlmZ ddlmZ dZW n ey;   dZY nw ddlmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZ erzddl m!Z! ertddl"m#Z$ ddl%m&Z& e'e(dƒƒZ)ee*dd�Z+de,de-fdd„Z.G dd„ de	e ƒZ/G dd„ de	e ƒZ#dS )z2This module contains the classes JobQueue and Job.é    N)ÚTYPE_CHECKINGÚAnyÚGenericÚcastÚoverload)ÚAsyncIOExecutor)ÚAsyncIOSchedulerTF)ÚUTCÚlocalize)Ú
get_logger)Úbuild_repr_with_selected_attrs)ÚJSONDict)ÚExtBot)ÚCCTÚJobCallback)ÚIterable)ÚJob)ÚApplicationé   ÚJobQueue)Ú
class_nameÚcallbackÚreturnc                 C   s   t | ddƒp	| jjS )a  Get the name of a callback function or callable object.

    Args:
        callback: A callable object (function, method, or callable class instance)

    Returns:
        The name of the callback, using __name__ if available, otherwise the class name.
    Ú__name__N)ÚgetattrÚ	__class__r   )r   © r   úQ/var/www/kodo/tsheker/venv/lib/python3.10/site-packages/telegram/ext/_jobqueue.pyÚ_get_callback_name7   s   	r   c                   @   s@  e Zd ZdZdZdZdDdd„Zdefdd	„Ze	dEdd„ƒZ
e	defdd„ƒZdejfdd„ZedFdddeddfdd„ƒZe	dFdeejB ejB ejB dedejfdd„ƒZ	dFdeejB ejB ejB dB dedejdB fdd„Z		
		dGdd„ZedHdd „ƒZ					dId!ee d"eejB ejB ejB d#edB d$edB d%edB d&edB d'edB ddfd(d)„Z							dJd!ee d*eejB d+eejB ejB ejB dB d,eejB ejB ejB dB d#edB d$edB d%edB d&edB d'edB ddfd-d.„Z					dId!ee d"ejd/ed#edB d$edB d%edB d&edB d'edB ddfd0d1„Ze dddddfd!ee dejd2e!ed3f d#edB d$edB d%edB d&edB d'edB ddfd4d5„Z"				dKd!ee d'ed#edB d$edB d%edB d&edB ddfd6d7„Z#dDd8d9„Z$dLd;eddfd<d=„Z%dMd>ee&j'e B dB de!d? fd@dA„Z(d$ede!d? fdBdC„Z)dS )Nr   aÀ  This class allows you to periodically perform tasks with the bot. It is a convenience
    wrapper for the APScheduler library.

    This class is a :class:`~typing.Generic` class and accepts one type variable that specifies
    the type of the argument ``context`` of the job callbacks (:paramref:`~run_once.callback`) of
    :meth:`run_once` and the other scheduling methods.

    Important:
        If you want to use this class, you must install PTB with the optional requirement
        ``job-queue``, i.e.

        .. code-block:: bash

           pip install "python-telegram-bot[job-queue]"

    Examples:
        :any:`Timer Bot <examples.timerbot>`

    .. seealso:: :wiki:`Architecture Overview <Architecture>`,
        :wiki:`Job Queue <Extensions---JobQueue>`

    .. versionchanged:: 20.0
        To use this class, PTB must be installed via
        ``pip install "python-telegram-bot[job-queue]"``.

    Attributes:
        scheduler (:class:`apscheduler.schedulers.asyncio.AsyncIOScheduler`): The scheduler.

            Warning:
                This scheduler is configured by :meth:`set_application`. Additional configuration
                settings can be made by users. However, calling
                :meth:`~apscheduler.schedulers.base.BaseScheduler.configure` will delete any
                previous configuration settings. Therefore, please make sure to pass the values
                returned by :attr:`scheduler_configuration` to the method call in addition to your
                custom values.
                Alternatively, you can also use methods like
                :meth:`~apscheduler.schedulers.base.BaseScheduler.add_jobstore` to avoid using
                :meth:`~apscheduler.schedulers.base.BaseScheduler.configure` altogether.

            .. versionchanged:: 20.0
                Uses :class:`~apscheduler.schedulers.asyncio.AsyncIOScheduler` instead of
                :class:`~apscheduler.schedulers.background.BackgroundScheduler`

    )Ú_applicationÚ	_executorÚ	scheduler)ÚsunÚmonÚtueÚwedÚthuÚfriÚsatr   Nc                 C   s0   t stdƒ‚d | _tƒ | _tdi | j¤Ž| _d S )Nz\To use `JobQueue`, PTB must be installed via `pip install "python-telegram-bot[job-queue]"`.r   )ÚAPS_AVAILABLEÚRuntimeErrorr   r   r    r   Úscheduler_configurationr!   ©Úselfr   r   r   Ú__init__t   s   ÿÿzJobQueue.__init__c                 C   s   t | | jd�S )a$  Give a string representation of the JobQueue in the form ``JobQueue[application=...]``.

        As this class doesn't implement :meth:`object.__str__`, the default implementation
        will be used, which is equivalent to :meth:`__repr__`.

        Returns:
            :obj:`str`
        )Úapplication)r   r/   r,   r   r   r   Ú__repr__�   s   	zJobQueue.__repr__ú3Application[Any, CCT, Any, Any, Any, JobQueue[CCT]]c                 C   s.   | j du r	tdƒ‚|   ¡ }|dur|S tdƒ‚)z1The application this JobQueue is associated with.Nz)No application was set for this JobQueue.z,The application instance is no longer alive.)r   r*   ©r-   r/   r   r   r   r/   Œ   s   
zJobQueue.applicationc                 C   sB   t }| jrt| jjtƒr| jjjr| jjjjpt }|d| jidœS )a_  Provides configuration values that are used by :class:`JobQueue` for :attr:`scheduler`.

        Tip:
            Since calling
            :meth:`scheduler.configure() <apscheduler.schedulers.base.BaseScheduler.configure>`
            deletes any previous setting, please make sure to pass these values to the method call
            in addition to your custom values:

            .. code-block:: python

                scheduler.configure(..., **job_queue.scheduler_configuration)

            Alternatively, you can also use methods like
            :meth:`~apscheduler.schedulers.base.BaseScheduler.add_jobstore` to avoid using
            :meth:`~apscheduler.schedulers.base.BaseScheduler.configure` altogether.

        .. versionadded:: 20.7

        Returns:
            dict[:obj:`str`, :obj:`object`]: The configuration values as dictionary.

        Údefault)ÚtimezoneÚ	executors)	r	   r   Ú
isinstancer/   Úbotr   ÚdefaultsÚtzinfor    )r-   r4   r   r   r   r+   –   s   ÿþýþz JobQueue.scheduler_configurationc                 C   s   t j | jj¡S ©N)ÚdtmÚdatetimeÚnowr!   r4   r,   r   r   r   Ú_tz_now»   s   zJobQueue._tz_nowFÚtimeÚ	shift_dayc                 C   ó   d S r:   r   ©r-   r?   r@   r   r   r   Ú_parse_time_input¾   s   zJobQueue._parse_time_inputc                 C   rA   r:   r   rB   r   r   r   rC   Á   s   c                 C   s¼   |d u rd S t |ttB ƒr|  ¡ tj|d� S t |tjƒr#|  ¡ | S t |tjƒr\tj tjj	|j
p5| jjd� ¡ |¡}|j
d u rHt|| jjƒ}|rZ|tj 	t¡krZ|tjdd�7 }|S |S )N)Úseconds)Útzé   )Údays)r6   ÚintÚfloatr>   r;   Ú	timedeltar?   r<   Úcombiner=   r9   r!   r4   Údater
   r	   )r-   r?   r@   Ú	date_timer   r   r   rC   È   s    ÿ
r/   c                 C   s$   t  |¡| _| jjdi | j¤Ž dS )z—Set the application to be used by this JobQueue.

        Args:
            application (:class:`telegram.ext.Application`): The application.

        Nr   )ÚweakrefÚrefr   r!   Ú	configurer+   r2   r   r   r   Úset_applicationà   s   	zJobQueue.set_applicationÚ	job_queueúJobQueue[CCT]ÚjobúJob[CCT]c                 Ã   s   �|  | j¡I dH  dS )a‘  This method is used as a callback for the APScheduler jobs.

        More precisely, the ``func`` argument of :class:`apscheduler.job.Job` is set to this method
        and the ``arg`` argument (representing positional arguments to ``func``) is set to a tuple
        containing the :class:`JobQueue` itself and the :class:`~telegram.ext.Job` instance.

        Tip:
            This method is a static method rather than a bound method. This makes the arguments
            more transparent and allows for easier handling of PTBs integration of APScheduler
            when utilizing advanced features of APScheduler.

        Hint:
            This method is effectively a wrapper for :meth:`telegram.ext.Job.run`.

        .. versionadded:: 20.4

        Args:
            job_queue (:class:`JobQueue`): The job queue that created the job.
            job (:class:`~telegram.ext.Job`): The job to run.
        N)Úrunr/   )rR   rT   r   r   r   Újob_callbackì   s   €zJobQueue.job_callbackr   ÚwhenÚdataÚnameÚchat_idÚuser_idÚ
job_kwargsc                 C   sn   |si }|p	t |ƒ}t|||||d�}| j|dd�}	| jj| jf|d|	| |f|	jp,| jjdœ|¤Ž}
|
|_|S )a·  Creates a new :class:`Job` instance that runs once and adds it to the queue.

        Args:
            callback (:term:`coroutine function`): The callback function that should be executed by
                the new job. Callback signature::

                    async def callback(context: CallbackContext)

            when (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta` |                                           :obj:`datetime.datetime` | :obj:`datetime.time`):
                Time in or at which the job should run. This parameter will be interpreted
                depending on its type.

                * :obj:`int` or :obj:`float` will be interpreted as "seconds from now" in which the
                  job should run.
                * :obj:`datetime.timedelta` will be interpreted as "time from now" in which the
                  job should run.
                * :obj:`datetime.datetime` will be interpreted as a specific date and time at
                  which the job should run. If the timezone (:attr:`datetime.datetime.tzinfo`) is
                  :obj:`None`, the default timezone of the bot will be used, which is UTC unless
                  :attr:`telegram.ext.Defaults.tzinfo` is used.
                * :obj:`datetime.time` will be interpreted as a specific time of day at which the
                  job should run. This could be either today or, if the time has already passed,
                  tomorrow. If the timezone (:attr:`datetime.time.tzinfo`) is :obj:`None`, the
                  default timezone of the bot will be used, which is UTC unless
                  :attr:`telegram.ext.Defaults.tzinfo` is used.

            chat_id (:obj:`int`, optional): Chat id of the chat associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.chat_data` will
                be available in the callback.

                .. versionadded:: 20.0

            user_id (:obj:`int`, optional): User id of the user associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.user_data` will
                be available in the callback.

                .. versionadded:: 20.0
            data (:obj:`object`, optional): Additional data needed for the callback function.
                Can be accessed through :attr:`Job.data` in the callback. Defaults to
                :obj:`None`.

                .. versionchanged:: 20.0
                    Renamed the parameter ``context`` to :paramref:`data`.
            name (:obj:`str`, optional): The name of the new job. Defaults to
                :external:attr:`callback.__name__ <definition.__name__>`.
            job_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to pass to the
                :meth:`apscheduler.schedulers.base.BaseScheduler.add_job()`.

        Returns:
            :class:`telegram.ext.Job`: The new :class:`Job` instance that has been added to the job
            queue.

        ©r   rY   rZ   r[   r\   T)r@   rL   )rZ   ÚtriggerÚrun_dateÚargsr4   )	r   r   rC   r!   Úadd_jobrW   r9   r4   Ú_job)r-   r   rX   rY   rZ   r[   r\   r]   rT   rM   Újr   r   r   Úrun_once  s$   @ÿúù
zJobQueue.run_onceÚintervalÚfirstÚlastc
              	   C   s˜   |	si }	|p	t |ƒ}t|||||d�}
|  |¡}|  |¡}|r)|r)||k r)tdƒ‚t|tjƒr3| ¡ }| jj	| j
fd| |
f||||dœ|	¤Ž}||
_|
S )a~  Creates a new :class:`Job` instance that runs at specified intervals and adds it to the
        queue.

        Note:
            For a note about DST, please see the documentation of `APScheduler`_.

        .. _`APScheduler`: https://apscheduler.readthedocs.io/en/stable/modules/triggers/cron.html
                           #daylight-saving-time-behavior

        Args:
            callback (:term:`coroutine function`): The callback function that should be executed by
                the new job. Callback signature::

                    async def callback(context: CallbackContext)

            interval (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta`): The interval in which
                the job will run. If it is an :obj:`int` or a :obj:`float`, it will be interpreted
                as seconds.
            first (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta` |                                           :obj:`datetime.datetime` | :obj:`datetime.time`, optional):
                Time in or at which the job should run. This parameter will be interpreted
                depending on its type.

                * :obj:`int` or :obj:`float` will be interpreted as "seconds from now" in which the
                  job should run.
                * :obj:`datetime.timedelta` will be interpreted as "time from now" in which the
                  job should run.
                * :obj:`datetime.datetime` will be interpreted as a specific date and time at
                  which the job should run. If the timezone (:attr:`datetime.datetime.tzinfo`) is
                  :obj:`None`, the default timezone of the bot will be used.
                * :obj:`datetime.time` will be interpreted as a specific time of day at which the
                  job should run. This could be either today or, if the time has already passed,
                  tomorrow. If the timezone (:attr:`datetime.time.tzinfo`) is :obj:`None`, the
                  default timezone of the bot will be used, which is UTC unless
                  :attr:`telegram.ext.Defaults.tzinfo` is used.

                Defaults to :paramref:`interval`

                Note:
                    Setting :paramref:`first` to ``0``, ``datetime.datetime.now()`` or another
                    value that indicates that the job should run immediately will not work due
                    to how the APScheduler library works. If you want to run a job immediately,
                    we recommend to use an approach along the lines of::

                        job = context.job_queue.run_repeating(callback, interval=5)
                        await job.run(context.application)

                    .. seealso:: :meth:`telegram.ext.Job.run`

            last (:obj:`int` | :obj:`float` | :obj:`datetime.timedelta` |                                           :obj:`datetime.datetime` | :obj:`datetime.time`, optional):
                Latest possible time for the job to run. This parameter will be interpreted
                depending on its type. See :paramref:`first` for details.

                If :paramref:`last` is :obj:`datetime.datetime` or :obj:`datetime.time` type
                and ``last.tzinfo`` is :obj:`None`, the default timezone of the bot will be
                assumed, which is UTC unless :attr:`telegram.ext.Defaults.tzinfo` is used.

                Defaults to :obj:`None`.
            data (:obj:`object`, optional): Additional data needed for the callback function.
                Can be accessed through :attr:`Job.data` in the callback. Defaults to
                :obj:`None`.

                .. versionchanged:: 20.0
                    Renamed the parameter ``context`` to :paramref:`data`.
            name (:obj:`str`, optional): The name of the new job. Defaults to
                :external:attr:`callback.__name__ <definition.__name__>`.
            chat_id (:obj:`int`, optional): Chat id of the chat associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.chat_data` will
                be available in the callback.

                .. versionadded:: 20.0

            user_id (:obj:`int`, optional): User id of the user associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.user_data` will
                be available in the callback.

                .. versionadded:: 20.0
            job_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to pass to the
                :meth:`apscheduler.schedulers.base.BaseScheduler.add_job()`.

        Returns:
            :class:`telegram.ext.Job`: The new :class:`Job` instance that has been added to the job
            queue.

        r^   z"'last' must not be before 'first'!rf   )r_   ra   Ú
start_dateÚend_daterD   rZ   )r   r   rC   Ú
ValueErrorr6   r;   rJ   Útotal_secondsr!   rb   rW   rc   )r-   r   rf   rg   rh   rY   rZ   r[   r\   r]   rT   Údt_firstÚdt_lastrd   r   r   r   Úrun_repeatingX  s0   b

ÿùøzJobQueue.run_repeatingÚdayc	                 C   sx   |si }|p	t |ƒ}t|||||d�}	| jj| jfd| |	f||dkr$dn||j|j|j|jp1| jj	dœ|¤Ž}
|
|	_
|	S )a¾	  Creates a new :class:`Job` that runs on a monthly basis and adds it to the queue.

        .. versionchanged:: 20.0
            The ``day_is_strict`` argument was removed. Instead one can now pass ``-1`` to the
            :paramref:`day` parameter to have the job run on the last day of the month.

        Args:
            callback (:term:`coroutine function`): The callback function that should be executed by
                the new job. Callback signature::

                    async def callback(context: CallbackContext)

            when (:obj:`datetime.time`): Time of day at which the job should run. If the timezone
                (``when.tzinfo``) is :obj:`None`, the default timezone of the bot will be used,
                which is UTC unless :attr:`telegram.ext.Defaults.tzinfo` is used.
            day (:obj:`int`): Defines the day of the month whereby the job would run. It should
                be within the range of ``1`` and ``31``, inclusive. If a month has fewer days than
                this number, the job will not run in this month. Passing ``-1`` leads to the job
                running on the last day of the month.
            data (:obj:`object`, optional): Additional data needed for the callback function.
                Can be accessed through :attr:`Job.data` in the callback. Defaults to
                :obj:`None`.

                .. versionchanged:: 20.0
                    Renamed the parameter ``context`` to :paramref:`data`.
            name (:obj:`str`, optional): The name of the new job. Defaults to
                :external:attr:`callback.__name__ <definition.__name__>`.
            chat_id (:obj:`int`, optional): Chat id of the chat associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.chat_data` will
                be available in the callback.

                .. versionadded:: 20.0

            user_id (:obj:`int`, optional): User id of the user associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.user_data` will
                be available in the callback.

                .. versionadded:: 20.0
            job_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to pass to the
                :meth:`apscheduler.schedulers.base.BaseScheduler.add_job()`.

        Returns:
            :class:`telegram.ext.Job`: The new :class:`Job` instance that has been added to the job
            queue.

        r^   Úcronéÿÿÿÿrh   )r_   ra   rZ   rp   ÚhourÚminuteÚsecondr4   )r   r   r!   rb   rW   rs   rt   ru   r9   r4   rc   )r-   r   rX   rp   rY   rZ   r[   r\   r]   rT   rd   r   r   r   Úrun_monthly×  s(   9ÿ÷
özJobQueue.run_monthlyrG   .c	                    s€   |si }|p	t |ƒ}t|||||d�}	ˆ jjˆ jf|ˆ |	fdd ‡ fdd„|D ƒ¡|j|j|j|j	p5ˆ jj
dœ|¤Ž}
|
|	_|	S )aÿ	  Creates a new :class:`Job` that runs on a daily basis and adds it to the queue.

        Note:
            For a note about DST, please see the documentation of `APScheduler`_.

        .. _`APScheduler`: https://apscheduler.readthedocs.io/en/stable/modules/triggers/cron.html
                           #daylight-saving-time-behavior

        Args:
            callback (:term:`coroutine function`): The callback function that should be executed by
                the new job. Callback signature::

                    async def callback(context: CallbackContext)

            time (:obj:`datetime.time`): Time of day at which the job should run. If the timezone
                (:obj:`datetime.time.tzinfo`) is :obj:`None`, the default timezone of the bot will
                be used, which is UTC unless :attr:`telegram.ext.Defaults.tzinfo` is used.
            days (tuple[:obj:`int`], optional): Defines on which days of the week the job should
                run (where ``0-6`` correspond to sunday - saturday). By default, the job will run
                every day.

                .. versionchanged:: 20.0
                    Changed day of the week mapping of 0-6 from monday-sunday to sunday-saturday.

            data (:obj:`object`, optional): Additional data needed for the callback function.
                Can be accessed through :attr:`Job.data` in the callback. Defaults to
                :obj:`None`.

                .. versionchanged:: 20.0
                    Renamed the parameter ``context`` to :paramref:`data`.
            name (:obj:`str`, optional): The name of the new job. Defaults to
                :external:attr:`callback.__name__ <definition.__name__>`.
            chat_id (:obj:`int`, optional): Chat id of the chat associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.chat_data` will
                be available in the callback.

                .. versionadded:: 20.0

            user_id (:obj:`int`, optional): User id of the user associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.user_data` will
                be available in the callback.

                .. versionadded:: 20.0
            job_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to pass to the
                :meth:`apscheduler.schedulers.base.BaseScheduler.add_job()`.

        Returns:
            :class:`telegram.ext.Job`: The new :class:`Job` instance that has been added to the job
            queue.

        r^   rq   ú,c                    s   g | ]}ˆ j | ‘qS r   )Ú_CRON_MAPPING)Ú.0Údr,   r   r   Ú
<listcomp>n  s    z&JobQueue.run_daily.<locals>.<listcomp>)rZ   ra   r_   Úday_of_weekrs   rt   ru   r4   )r   r   r!   rb   rW   Újoinrs   rt   ru   r9   r4   rc   )r-   r   r?   rG   rY   rZ   r[   r\   r]   rT   rd   r   r,   r   Ú	run_daily%  s(   >ÿ÷
özJobQueue.run_dailyc           	      C   sH   |pt |ƒ}t|||||d�}| jj| jf| |f|dœ|¤Ž}||_|S )aL  Creates a new custom defined :class:`Job`.

        Args:
            callback (:term:`coroutine function`): The callback function that should be executed by
                the new job. Callback signature::

                    async def callback(context: CallbackContext)

            job_kwargs (:obj:`dict`): Arbitrary keyword arguments. Used as arguments for
                :meth:`apscheduler.schedulers.base.BaseScheduler.add_job`.
            data (:obj:`object`, optional): Additional data needed for the callback function.
                Can be accessed through :attr:`Job.data` in the callback. Defaults to
                :obj:`None`.

                .. versionchanged:: 20.0
                    Renamed the parameter ``context`` to :paramref:`data`.
            name (:obj:`str`, optional): The name of the new job. Defaults to
                :external:attr:`callback.__name__ <definition.__name__>`.
            chat_id (:obj:`int`, optional): Chat id of the chat associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.chat_data` will
                be available in the callback.

                .. versionadded:: 20.0

            user_id (:obj:`int`, optional): User id of the user associated with this job. If
                passed, the corresponding :attr:`~telegram.ext.CallbackContext.user_data` will
                be available in the callback.

                .. versionadded:: 20.0

        Returns:
            :class:`telegram.ext.Job`: The new :class:`Job` instance that has been added to the job
            queue.

        r^   )ra   rZ   )r   r   r!   rb   rW   rc   )	r-   r   r]   rY   rZ   r[   r\   rT   rd   r   r   r   Ú
run_customy  s
   , zJobQueue.run_customc                 Ã   s   �| j js| j  ¡  dS dS )z+Starts the :class:`~telegram.ext.JobQueue`.N)r!   ÚrunningÚstartr,   r   r   r   r�   ­  s   €ÿzJobQueue.startTÚwaitc                 Ã   sN   �|rt j| jjddiŽI dH  | jjr%| jj|d� t  d¡I dH  dS dS )zÛShuts down the :class:`~telegram.ext.JobQueue`.

        Args:
            wait (:obj:`bool`, optional): Whether to wait until all currently running jobs
                have finished. Defaults to :obj:`True`.

        Úreturn_exceptionsTN)r‚   g{®Gáz„?)ÚasyncioÚgatherr    Ú_pending_futuresr!   r€   ÚshutdownÚsleep)r-   r‚   r   r   r   Ústop³  s   €ÿþüzJobQueue.stopÚpattern)rU   .c                    s:   dd„ | j  ¡ D ƒ}ˆ du rt|ƒS t‡ fdd„|D ƒƒS )a%  Returns a tuple of all *scheduled* jobs that are currently in the :class:`JobQueue`.

        Args:
            pattern (:obj:`str` | :obj:`re.Pattern`, optional): A regular expression pattern. If
                passed, only jobs whose name matches the pattern will be returned.
                Defaults to :obj:`None`.

                Hint:
                    This uses :func:`re.search` and not :func:`re.match`.

                .. versionadded:: 21.10

        Returns:
            tuple[:class:`Job`]: Tuple of all *scheduled* jobs.
        c                 s   s   � | ]}t  |¡V  qd S r:   )r   Úfrom_aps_job©ry   rT   r   r   r   Ú	<genexpr>Ú  s   € 

ÿz JobQueue.jobs.<locals>.<genexpr>Nc                 3   s,   � | ]}|j rt ˆ ¡ |j ¡r|V  qd S r:   )rZ   ÚreÚcompileÚsearchrŒ   ©rŠ   r   r   r�   ß  s   € ÿÿ
ÿ)r!   Úget_jobsÚtuple)r-   rŠ   Újobs_generatorr   r‘   r   ÚjobsÊ  s   ÿÿzJobQueue.jobsc                 C   s   |   dt |¡› d�¡S )af  Returns a tuple of all *scheduled* jobs with the given name that are currently
        in the :class:`JobQueue`.

        Hint:
            This method is a convenience wrapper for :meth:`jobs` with a pattern that matches the
            given name.

        Returns:
            tuple[:class:`Job`]: Tuple of all *scheduled* jobs matching the name.
        ú^ú$)r•   rŽ   Úescape)r-   rZ   r   r   r   Úget_jobs_by_nameã  s   zJobQueue.get_jobs_by_name©r   N)r   r1   )F©r/   r1   r   N)rR   rS   rT   rU   r   N)NNNNN)NNNNNNN©NNNN)Tr:   )*r   Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__rx   r.   Ústrr0   Úpropertyr/   r   r+   r;   r<   r>   r   ÚboolrC   rI   rJ   r?   rQ   ÚstaticmethodrW   r   r   ÚobjectrH   re   ro   rv   Ú	_ALL_DAYSr“   r~   r   r�   r‰   rŽ   ÚPatternr•   r™   r   r   r   r   r   C   s@   -
	$ýþýü	ýþý
üÿ
þøþýüûúùø	
÷Xöþýüûúùø	÷
ö
õ ÷þýüûúùø	÷

öR÷þý
üûúùø	÷

öXùþýüûúù
ø
4&c                   @   s.  e Zd ZdZdZ				d-dee dedB dedB de	dB de	dB f
d	d
„Z
dedefdd„Zdedefdd„Zde	fdd„Zdefdd„Zed.dd„ƒZedefdd„ƒZedefdd„ƒZejdeddfdd„ƒZedejdB fdd „ƒZed/d#d$„ƒZ	%	&		d0d'd(„Z	%	&		d0d)d*„Zd1d+d,„ZdS )2r   aþ
  This class is a convenience wrapper for the jobs held in a :class:`telegram.ext.JobQueue`.
    With the current backend APScheduler, :attr:`job` holds a :class:`apscheduler.job.Job`
    instance.

    Objects of this class are comparable in terms of equality. Two objects of this class are
    considered equal, if their :class:`id <apscheduler.job.Job>` is equal.

    This class is a :class:`~typing.Generic` class and accepts one type variable that specifies
    the type of the argument ``context`` of :paramref:`callback`.

    Important:
        If you want to use this class, you must install PTB with the optional requirement
        ``job-queue``, i.e.

        .. code-block:: bash

           pip install "python-telegram-bot[job-queue]"

    Note:
        All attributes and instance methods of :attr:`job` are also directly available as
        attributes/methods of the corresponding :class:`telegram.ext.Job` object.

    Warning:
        This class should not be instantiated manually.
        Use the methods of :class:`telegram.ext.JobQueue` to schedule jobs.

    .. seealso:: :wiki:`Job Queue <Extensions---JobQueue>`

    .. versionchanged:: 20.0

       * Removed argument and attribute ``job_queue``.
       * Renamed ``Job.context`` to :attr:`Job.data`.
       * Removed argument ``job``
       * To use this class, PTB must be installed via
         ``pip install "python-telegram-bot[job-queue]"``.

    Args:
        callback (:term:`coroutine function`): The callback function that should be executed by the
            new job. Callback signature::

                async def callback(context: CallbackContext)

        data (:obj:`object`, optional): Additional data needed for the :paramref:`callback`
            function. Can be accessed through :attr:`Job.data` in the callback. Defaults to
            :obj:`None`.
        name (:obj:`str`, optional): The name of the new job. Defaults to
            :external:obj:`callback.__name__ <definition.__name__>`.
        chat_id (:obj:`int`, optional): Chat id of the chat that this job is associated with.

            .. versionadded:: 20.0
        user_id (:obj:`int`, optional): User id of the user that this job is associated with.

            .. versionadded:: 20.0
    Attributes:
        callback (:term:`coroutine function`): The callback function that should be executed by the
            new job.
        data (:obj:`object`): Optional. Additional data needed for the :attr:`callback` function.
        name (:obj:`str`): Optional. The name of the new job.
        chat_id (:obj:`int`): Optional. Chat id of the chat that this job is associated with.

            .. versionadded:: 20.0
        user_id (:obj:`int`): Optional. User id of the user that this job is associated with.

            .. versionadded:: 20.0
    )Ú_enabledrc   Ú_removedr   r[   rY   rZ   r\   Nr   rY   rZ   r[   r\   c                 C   sN   t stdƒ‚|| _|| _|pt|ƒ| _|| _|| _d| _d| _	t
dd ƒ| _d S )NzWTo use `Job`, PTB must be installed via `pip install "python-telegram-bot[job-queue]"`.FÚAPSJob)r)   r*   r   rY   r   rZ   r[   r\   r©   r¨   r   rc   )r-   r   rY   rZ   r[   r\   r   r   r   r.   ?  s   ÿzJob.__init__Úitemr   c              
   C   s:   zt | j|ƒW S  ty } z	td|› d�ƒ|‚d}~ww )aú  Overrides :py:meth:`object.__getattr__` to get specific attribute of the
        :class:`telegram.ext.Job` object or of its attribute :class:`apscheduler.job.Job`,
        if exists.

        Args:
           item (:obj:`str`): The name of the attribute.

        Returns:
            :object: The value of the attribute.

        Raises:
            :exc:`AttributeError`: If the attribute does not exist in both
                :class:`telegram.ext.Job` and :class:`apscheduler.job.Job` objects.
        zDNeither 'telegram.ext.Job' nor 'apscheduler.job.Job' has attribute 'ú'N)r   rT   ÚAttributeError)r-   r«   Úexcr   r   r   Ú__getattr__X  s   
ÿþ€ÿzJob.__getattr__Úotherc                 C   s   t || jƒr| j|jkS dS )aP  Defines equality condition for the :class:`telegram.ext.Job` object.
        Two objects of this class are considered to be equal if their
        :class:`id <apscheduler.job.Job>` are equal.

        Returns:
            :obj:`True` if both objects have :paramref:`id` parameters identical.
            :obj:`False` otherwise.
        F)r6   r   Úid)r-   r°   r   r   r   Ú__eq__n  s   	z
Job.__eq__c                 C   s
   t | jƒS )zèBuilds a hash value for this object such that the hash of two objects is
        equal if and only if the objects are equal in terms of :meth:`__eq__`.

        Returns:
            :obj:`int`: The hash value of the object.
        )Úhashr±   r,   r   r   r   Ú__hash__{  s   
zJob.__hash__c                 C   s"   t | | jj| jt| jƒ| jjd�S )a>  Give a string representation of the job in the form
        ``Job[id=..., name=..., callback=..., trigger=...]``.

        As this class doesn't implement :meth:`object.__str__`, the default implementation
        will be used, which is equivalent to :meth:`__repr__`.

        Returns:
            :obj:`str`
        )r±   rZ   r   r_   )r   rT   r±   rZ   r   r   r_   r,   r   r   r   r0   „  s   
ûzJob.__repr__rª   c                 C   ó   | j S )z›:class:`apscheduler.job.Job`: The APS Job this job is a wrapper for.

        .. versionchanged:: 20.0
            This property is now read-only.
        )rc   r,   r   r   r   rT   –  s   zJob.jobc                 C   rµ   )z3:obj:`bool`: Whether this job is due to be removed.)r©   r,   r   r   r   ÚremovedŸ  ó   zJob.removedc                 C   rµ   )z):obj:`bool`: Whether this job is enabled.)r¨   r,   r   r   r   Úenabled¤  r·   zJob.enabledÚstatusc                 C   s$   |r| j  ¡  n| j  ¡  || _d S r:   )rT   ÚresumeÚpauser¨   )r-   r¹   r   r   r   r¸   ©  s   

c                 C   s   | j jS )a³  
        :class:`datetime.datetime`: Datetime for the next job execution.
        Datetime is localized according to :attr:`datetime.datetime.tzinfo`.
        If job is removed or already ran it equals to :obj:`None`.

        Warning:
            This attribute is only available, if the :class:`telegram.ext.JobQueue` this job
            belongs to is already started. Otherwise APScheduler raises an :exc:`AttributeError`.
        )rT   Únext_run_timer,   r   r   r   Únext_t±  s   z
Job.next_tÚaps_jobrU   c                 C   s   |j d }||_|S )a­  Provides the :class:`telegram.ext.Job` that is associated with the given APScheduler
        job.

        Tip:
            This method can be useful when using advanced APScheduler features along with
            :class:`telegram.ext.JobQueue`.

        .. versionadded:: 20.4

        Args:
            aps_job (:class:`apscheduler.job.Job`): The APScheduler job

        Returns:
            :class:`telegram.ext.Job`
        rF   )ra   rc   )Úclsr¾   Úext_jobr   r   r   r‹   ¾  s   
zJob.from_aps_jobr/   r1   c                 Ã   s   �t  |  |¡¡I dH  dS )a…  Executes the callback function independently of the jobs schedule. Also calls
        :meth:`telegram.ext.Application.update_persistence`.

        .. versionchanged:: 20.0
            Calls :meth:`telegram.ext.Application.update_persistence`.

        Args:
            application (:class:`telegram.ext.Application`): The application this job is associated
                with.
        N)r„   ÚshieldÚ_runr2   r   r   r   rV   Ó  s   €zJob.runc              
   Ã   s  �zzz@z
|j j | |¡}W n$ ty1 } ztjd| j|d� W Y d }~W W |j| d� d S d }~ww | ¡ I d H  |  	|¡I d H  W n' tyi } z|j
|jd || d�d| j› d�d�I d H  W Y d }~nd }~ww W |j| d� d S W |j| d� d S |j| d� w )NzEError while building CallbackContext for job %s. Job will not be run.)Úexc_info)rT   zJob:z:run:process_error)rZ   )Úcontext_typesÚcontextÚfrom_jobÚ	ExceptionÚ_LOGGERÚcriticalrc   Ú_mark_for_persistence_updateÚrefresh_datar   Úcreate_taskÚprocess_errorr±   )r-   r/   rÅ   r®   r   r   r   rÂ   ã  s6   €ý€ïþ€ÿÿúzJob._runc                 C   s   | j  ¡  d| _dS )z–
        Schedules this job for removal from the :class:`JobQueue`. It will be removed without
        executing its callback function again.
        TN)rT   Úremover©   r,   r   r   r   Úschedule_removalü  s   

zJob.schedule_removalrœ   )r   rª   )r¾   rª   r   rU   r›   rš   )r   r�   rž   rŸ   r    r   r   r¥   r¡   rH   r.   r¯   r£   r²   r´   r0   r¢   rT   r¶   r¸   Úsetterr;   r<   r½   Úclassmethodr‹   rV   rÂ   rÏ   r   r   r   r   r   ñ  sZ    Búþýüû
ú	ÿ
þÿ
þr   )0rŸ   r„   r<   r;   rŽ   rN   Útypingr   r   r   r   r   Úapscheduler.executors.asyncior   Úapscheduler.schedulers.asyncior   r)   ÚImportErrorÚtelegram._utils.datetimer	   r
   Útelegram._utils.loggingr   Útelegram._utils.reprr   Útelegram._utils.typesr   Útelegram.ext._extbotr   Útelegram.ext._utils.typesr   r   Úcollections.abcr   Úapscheduler.jobr   rª   Útelegram.extr   r“   Úranger¦   r   rÈ   r¥   r¡   r   r   r   r   r   r   Ú<module>   sD   ÿ     3