Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Acceptdatetime.timedelta Input inBot Method Parameters#4651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Bibo-Joshi merged 8 commits intomasterfromfeature/#4575-timedelta-method-input
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletiondocs/substitutions/global.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -96,4 +96,6 @@

.. |allow_paid_broadcast| replace:: Pass True to allow up to :tg-const:`telegram.constants.FloodLimit.PAID_MESSAGES_PER_SECOND` messages per second, ignoring `broadcasting limits <https://core.telegram.org/bots/faq#how-can-i-message-all-of-my-bot-39s-subscribers-at-once>`__ for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance.

.. |tz-naive-dtms| replace:: For timezone naive :obj:`datetime.datetime` objects, the default timezone of the bot will be used, which is UTC unless :attr:`telegram.ext.Defaults.tzinfo` is used.
.. |tz-naive-dtms| replace:: For timezone naive :obj:`datetime.datetime` objects, the default timezone of the bot will be used, which is UTC unless :attr:`telegram.ext.Defaults.tzinfo` is used.

.. |time-period-input| replace:: :class:`datetime.timedelta` objects are accepted in addition to plain :obj:`int` values.
97 changes: 69 additions & 28 deletionstelegram/_bot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,6 +103,7 @@
JSONDict,
ODVInput,
ReplyMarkup,
TimePeriod,
)
from telegram._utils.warnings import warn
from telegram._webhookinfo import WebhookInfo
Expand DownExpand Up@@ -1492,7 +1493,7 @@ async def send_audio(
self,
chat_id: Union[int, str],
audio: Union[FileInput, "Audio"],
duration: Optional[int] = None,
duration: Optional[TimePeriod] = None,
performer: Optional[str] = None,
title: Optional[str] = None,
caption: Optional[str] = None,
Expand DownExpand Up@@ -1554,7 +1555,11 @@ async def send_audio(

.. versionchanged:: 20.0
|sequenceargs|
duration (:obj:`int`, optional): Duration of sent audio in seconds.
duration (:obj:`int` | :class:`datetime.timedelta`, optional): Duration of sent audio
in seconds.

.. versionchanged:: NEXT.VERSION
|time-period-input|
performer (:obj:`str`, optional): Performer.
title (:obj:`str`, optional): Track name.
disable_notification (:obj:`bool`, optional): |disable_notification|
Expand DownExpand Up@@ -1932,7 +1937,7 @@ async def send_video(
self,
chat_id: Union[int, str],
video: Union[FileInput, "Video"],
duration: Optional[int] = None,
duration: Optional[TimePeriod] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
Expand DownExpand Up@@ -1990,7 +1995,11 @@ async def send_video(
.. versionchanged:: 20.0
File paths as input is also accepted for bots *not* running in
:paramref:`~telegram.Bot.local_mode`.
duration (:obj:`int`, optional): Duration of sent video in seconds.
duration (:obj:`int` | :class:`datetime.timedelta`, optional): Duration of sent video
in seconds.

.. versionchanged:: NEXT.VERSION
|time-period-input|
width (:obj:`int`, optional): Video width.
height (:obj:`int`, optional): Video height.
caption (:obj:`str`, optional): Video caption (may also be used when resending videos
Expand DownExpand Up@@ -2111,7 +2120,7 @@ async def send_video_note(
self,
chat_id: Union[int, str],
video_note: Union[FileInput, "VideoNote"],
duration: Optional[int] = None,
duration: Optional[TimePeriod] = None,
length: Optional[int] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
Expand DownExpand Up@@ -2163,7 +2172,11 @@ async def send_video_note(
.. versionchanged:: 20.0
File paths as input is also accepted for bots *not* running in
:paramref:`~telegram.Bot.local_mode`.
duration (:obj:`int`, optional): Duration of sent video in seconds.
duration (:obj:`int` | :class:`datetime.timedelta`, optional): Duration of sent video
in seconds.

.. versionchanged:: NEXT.VERSION
|time-period-input|
length (:obj:`int`, optional): Video width and height, i.e. diameter of the video
message.
disable_notification (:obj:`bool`, optional): |disable_notification|
Expand DownExpand Up@@ -2259,7 +2272,7 @@ async def send_animation(
self,
chat_id: Union[int, str],
animation: Union[FileInput, "Animation"],
duration: Optional[int] = None,
duration: Optional[TimePeriod] = None,
width: Optional[int] = None,
height: Optional[int] = None,
caption: Optional[str] = None,
Expand DownExpand Up@@ -2311,7 +2324,11 @@ async def send_animation(

.. versionchanged:: 13.2
Accept :obj:`bytes` as input.
duration (:obj:`int`, optional): Duration of sent animation in seconds.
duration (:obj:`int` | :class:`datetime.timedelta`, optional): Duration of sent
animation in seconds.

.. versionchanged:: NEXT.VERSION
|time-period-input|
width (:obj:`int`, optional): Animation width.
height (:obj:`int`, optional): Animation height.
caption (:obj:`str`, optional): Animation caption (may also be used when resending
Expand DownExpand Up@@ -2430,7 +2447,7 @@ async def send_voice(
self,
chat_id: Union[int, str],
voice: Union[FileInput, "Voice"],
duration: Optional[int] = None,
duration: Optional[TimePeriod] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
Expand DownExpand Up@@ -2491,7 +2508,11 @@ async def send_voice(

.. versionchanged:: 20.0
|sequenceargs|
duration (:obj:`int`, optional): Duration of the voice message in seconds.
duration (:obj:`int` | :class:`datetime.timedelta`, optional): Duration of the voice
message in seconds.

.. versionchanged:: NEXT.VERSION
|time-period-input|
disable_notification (:obj:`bool`, optional): |disable_notification|
protect_content (:obj:`bool`, optional): |protect_content|

Expand DownExpand Up@@ -2763,7 +2784,7 @@ async def send_location(
longitude: Optional[float] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
live_period: Optional[int] = None,
live_period: Optional[TimePeriod] = None,
horizontal_accuracy: Optional[float] = None,
heading: Optional[int] = None,
proximity_alert_radius: Optional[int] = None,
Expand DownExpand Up@@ -2796,12 +2817,16 @@ async def send_location(
horizontal_accuracy (:obj:`int`, optional): The radius of uncertainty for the location,
measured in meters;
0-:tg-const:`telegram.constants.LocationLimit.HORIZONTAL_ACCURACY`.
live_period (:obj:`int`, optional): Period in seconds for which the location will be
live_period (:obj:`int` | :class:`datetime.timedelta`, optional): Period in seconds for
which the location will be
updated, should be between
:tg-const:`telegram.constants.LocationLimit.MIN_LIVE_PERIOD` and
:tg-const:`telegram.constants.LocationLimit.MAX_LIVE_PERIOD`, or
:tg-const:`telegram.constants.LocationLimit.LIVE_PERIOD_FOREVER` for live
locations that can be edited indefinitely.

.. versionchanged:: NEXT.VERSION
|time-period-input|
heading (:obj:`int`, optional): For live locations, a direction in which the user is
moving, in degrees. Must be between
:tg-const:`telegram.constants.LocationLimit.MIN_HEADING` and
Expand DownExpand Up@@ -2919,7 +2944,7 @@ async def edit_message_live_location(
horizontal_accuracy: Optional[float] = None,
heading: Optional[int] = None,
proximity_alert_radius: Optional[int] = None,
live_period: Optional[int] = None,
live_period: Optional[TimePeriod] = None,
business_connection_id: Optional[str] = None,
*,
location: Optional[Location] = None,
Expand DownExpand Up@@ -2959,7 +2984,8 @@ async def edit_message_live_location(
if specified.
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): An object for a new
inline keyboard.
live_period (:obj:`int`, optional): New period in seconds during which the location
live_period (:obj:`int` | :class:`datetime.timedelta`, optional): New period in seconds
during which the location
can be updated, starting from the message send date. If
:tg-const:`telegram.constants.LocationLimit.LIVE_PERIOD_FOREVER` is specified,
then the location can be updated forever. Otherwise, the new value must not exceed
Expand All@@ -2968,6 +2994,9 @@ async def edit_message_live_location(
remains unchanged

.. versionadded:: 21.2.

.. versionchanged:: NEXT.VERSION
|time-period-input|
business_connection_id (:obj:`str`, optional): |business_id_str_edit|

.. versionadded:: 21.4
Expand DownExpand Up@@ -3623,7 +3652,7 @@ async def answer_inline_query(
results: Union[
Sequence["InlineQueryResult"], Callable[[int], Optional[Sequence["InlineQueryResult"]]]
],
cache_time: Optional[int] = None,
cache_time: Optional[TimePeriod] = None,
is_personal: Optional[bool] = None,
next_offset: Optional[str] = None,
button: Optional[InlineQueryResultsButton] = None,
Expand DownExpand Up@@ -3659,8 +3688,12 @@ async def answer_inline_query(
a callable that accepts the current page index starting from 0. It must return
either a list of :class:`telegram.InlineQueryResult` instances or :obj:`None` if
there are no more results.
cache_time (:obj:`int`, optional): The maximum amount of time in seconds that the
cache_time (:obj:`int` | :class:`datetime.timedelta`, optional): The maximum amount of
time in seconds that the
result of the inline query may be cached on the server. Defaults to ``300``.

.. versionchanged:: NEXT.VERSION
|time-period-input|
is_personal (:obj:`bool`, optional): Pass :obj:`True`, if results may be cached on
the server side only for the user that sent the query. By default,
results may be returned to any user who sends the same query.
Expand DownExpand Up@@ -4076,7 +4109,7 @@ async def answer_callback_query(
text: Optional[str] = None,
show_alert: Optional[bool] = None,
url: Optional[str] = None,
cache_time: Optional[int] = None,
cache_time: Optional[TimePeriod] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand DownExpand Up@@ -4107,9 +4140,13 @@ async def answer_callback_query(
opens your game - note that this will only work if the query comes from a callback
game button. Otherwise, you may use links like t.me/your_bot?start=XXXX that open
your bot with a parameter.
cache_time (:obj:`int`, optional): The maximum amount of time in seconds that the
cache_time (:obj:`int` | :class:`datetime.timedelta`, optional): The maximum amount of
time in seconds that the
result of the callback query may be cached client-side. Defaults to 0.

.. versionchanged:: NEXT.VERSION
|time-period-input|

Returns:
:obj:`bool` On success, :obj:`True` is returned.

Expand DownExpand Up@@ -7261,7 +7298,7 @@ async def send_poll(
reply_markup: Optional[ReplyMarkup] = None,
explanation: Optional[str] = None,
explanation_parse_mode: ODVInput[str] = DEFAULT_NONE,
open_period: Optional[int] = None,
open_period: Optional[TimePeriod] = None,
close_date: Optional[Union[int, dtm.datetime]] = None,
explanation_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
Expand DownExpand Up@@ -7324,10 +7361,14 @@ async def send_poll(

.. versionchanged:: 20.0
|sequenceargs|
open_period (:obj:`int`, optional): Amount of time in seconds the poll will be active
open_period (:obj:`int` | :class:`datetime.timedelta`, optional): Amount of time in
seconds the poll will be active
after creation, :tg-const:`telegram.Poll.MIN_OPEN_PERIOD`-
:tg-const:`telegram.Poll.MAX_OPEN_PERIOD`. Can't be used together with
:paramref:`close_date`.

.. versionchanged:: NEXT.VERSION
|time-period-input|
close_date (:obj:`int` | :obj:`datetime.datetime`, optional): Point in time (Unix
timestamp) when the poll will be automatically closed. Must be at least
:tg-const:`telegram.Poll.MIN_OPEN_PERIOD` and no more than
Expand DownExpand Up@@ -8228,7 +8269,7 @@ async def create_invoice_link(
send_phone_number_to_provider: Optional[bool] = None,
send_email_to_provider: Optional[bool] = None,
is_flexible: Optional[bool] = None,
subscription_period: Optional[Union[int, dtm.timedelta]] = None,
subscription_period: Optional[TimePeriod] = None,
business_connection_id: Optional[str] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
Expand DownExpand Up@@ -8349,11 +8390,7 @@ async def create_invoice_link(
"is_flexible": is_flexible,
"send_phone_number_to_provider": send_phone_number_to_provider,
"send_email_to_provider": send_email_to_provider,
"subscription_period": (
subscription_period.total_seconds()
if isinstance(subscription_period, dtm.timedelta)
else subscription_period
),
"subscription_period": subscription_period,
"business_connection_id": business_connection_id,
}

Expand DownExpand Up@@ -9644,7 +9681,7 @@ async def send_paid_media(
async def create_chat_subscription_invite_link(
self,
chat_id: Union[str, int],
subscription_period:int,
subscription_period:TimePeriod,
subscription_price: int,
name: Optional[str] = None,
*,
Expand All@@ -9665,9 +9702,13 @@ async def create_chat_subscription_invite_link(

Args:
chat_id (:obj:`int` | :obj:`str`): |chat_id_channel|
subscription_period (:obj:`int`): The number of seconds the subscription will be
subscription_period (:obj:`int` | :class:`datetime.timedelta`): The number of seconds
the subscription will be
active for before the next payment. Currently, it must always be
:tg-const:`telegram.constants.ChatSubscriptionLimit.SUBSCRIPTION_PERIOD` (30 days).

.. versionchanged:: NEXT.VERSION
|time-period-input|
subscription_price (:obj:`int`): The number of Telegram Stars a user must pay initially
and after each subsequent subscription period to be a member of the chat;
:tg-const:`telegram.constants.ChatSubscriptionLimit.MIN_PRICE`-
Expand Down
6 changes: 3 additions & 3 deletionstelegram/_callbackquery.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,7 @@
from telegram._user import User
from telegram._utils.argumentparsing import de_json_optional
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput, ReplyMarkup
from telegram._utils.types import JSONDict, ODVInput, ReplyMarkup, TimePeriod

if TYPE_CHECKING:
from telegram import (
Expand DownExpand Up@@ -164,7 +164,7 @@ async def answer(
text: Optional[str] = None,
show_alert: Optional[bool] = None,
url: Optional[str] = None,
cache_time: Optional[int] = None,
cache_time: Optional[TimePeriod] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand DownExpand Up@@ -471,7 +471,7 @@ async def edit_message_live_location(
horizontal_accuracy: Optional[float] = None,
heading: Optional[int] = None,
proximity_alert_radius: Optional[int] = None,
live_period: Optional[int] = None,
live_period: Optional[TimePeriod] = None,
*,
location: Optional[Location] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp