Compare commits
179 Commits
Author | SHA1 | Date |
---|---|---|
_run | e10517e088 | |
Artin GH | 1946393c36 | |
Badiboy | 0f52ca688f | |
Badiboy | b18bcd494a | |
Badiboy | 8f41df0ee4 | |
Kourva | cb7f6a8c99 | |
_run | 3960115ec7 | |
_run | 916569cdc5 | |
_run | 75d3fa2eba | |
_run | 67e3774e8e | |
_run | f799157314 | |
coder2020official | af3a98057f | |
_run | 447fc1d461 | |
_run | fb98df3dfe | |
Badiboy | 0b34da3900 | |
Artem Lukin | 5ea1abaadd | |
Badiboy | 5a81353420 | |
dependabot[bot] | eaf90cce7f | |
Badiboy | b219218c8d | |
Badiboy | 2dac17aa75 | |
Badiboy | 48377ac905 | |
Alexey Isaev | 14294d1aa3 | |
_run | ea3c159044 | |
AmirW | 58d53e1a54 | |
Badiboy | abec3dc60e | |
coder2020official | ecb5d9b4f6 | |
coder2020official | 26575dc5e7 | |
coder2020official | be69feb252 | |
coder2020official | 1d62adc262 | |
coder2020official | 77e1928628 | |
coder2020official | d6f4987197 | |
coder2020official | 966b451869 | |
coder2020official | d1417e5616 | |
_run | a7cafd1f24 | |
Badiboy | 92907ced30 | |
Badiboy | 1b2ed0e2f7 | |
_run | 370f0370c7 | |
Cub11k | e4bddd91cb | |
Cub11k | d466da3542 | |
Badiboy | e64c06b7bc | |
Badiboy | 7d168ebbd8 | |
Francisco Griman | c5689f383b | |
Francisco Griman | 8796168efb | |
_run | 100659fecd | |
_run | 7bf87a306a | |
_run | 351d021e01 | |
Badiboy | 4ffe0f8833 | |
Badiboy | 3f07dc4ce8 | |
Badiboy | 2e589ab6e1 | |
Badiboy | 8b63f6a6ef | |
Badiboy | dc98aca173 | |
Badiboy | 39360e0640 | |
Badiboy | b1c172c421 | |
Badiboy | 6b5c263ee8 | |
Badiboy | 46100edd97 | |
Badiboy | 018b89cdc0 | |
Badiboy | f3486b3730 | |
Badiboy | b0e64d828c | |
Badiboy | 14434b398e | |
_run | 1d62bf2ac8 | |
Badiboy | fe2e9a7a30 | |
Badiboy | c9ef0d71f0 | |
Badiboy | b0740a920a | |
Badiboy | 6a9c25cf80 | |
Badiboy | e56c60ac00 | |
Badiboy | 7c7a063fb6 | |
Mike Lei | bd69492ed4 | |
C̷̱̺͙͓̪͔̹͉͉̯̖̟̀͆́̽̔̈̚͠͝o̶̥̻̻̖̮͚͒̂̒͌̾̇͗͘͝d̸̢̡͈̮̦͈͙̖͔̦̭̩̰͎͉̣̰͆̈́͘͝e̸͖͆̎̏͒̀̈́͛́̍̀̀̿̚͝B̵̨̯̹̝͙͉̲̟̳̟͎̪̫̪̤̒͋̉̑̐̒̅̅̋͜y̵̞͚͕̭̤̱͖̟̫̜̓͐̏̕ͅZ̸͎̫̖͍̪̓̐͆e̶͈͇̽̔͂̉͊̈́ņ̶̣̣͎̤̯͖͉͍̳͇͈̘̳̗͚́̄̊̂̊̏̄͐͐̿̓́̽̃̄̚͝ | 37cdb52ed2 | |
C̷̱̺͙͓̪͔̹͉͉̯̖̟̀͆́̽̔̈̚͠͝o̶̥̻̻̖̮͚͒̂̒͌̾̇͗͘͝d̸̢̡͈̮̦͈͙̖͔̦̭̩̰͎͉̣̰͆̈́͘͝e̸͖͆̎̏͒̀̈́͛́̍̀̀̿̚͝B̵̨̯̹̝͙͉̲̟̳̟͎̪̫̪̤̒͋̉̑̐̒̅̅̋͜y̵̞͚͕̭̤̱͖̟̫̜̓͐̏̕ͅZ̸͎̫̖͍̪̓̐͆e̶͈͇̽̔͂̉͊̈́ņ̶̣̣͎̤̯͖͉͍̳͇͈̘̳̗͚́̄̊̂̊̏̄͐͐̿̓́̽̃̄̚͝ | d8569394b0 | |
_run | da57174635 | |
_run | 776ce0a7eb | |
coder2020official | 886806135e | |
coder2020official | 1e450ebd15 | |
_run | 41521f5618 | |
_run | 603a7cf9f2 | |
_run | 535a14ca0c | |
_run | 67a52b2e98 | |
Arash Nemat Zadeh | c47c26d2b0 | |
coder2020official | 9d2f7c02a4 | |
coder2020official | 991679bedc | |
coder2020official | 3b4e6fed04 | |
coder2020official | 5c6b867582 | |
coder2020official | 715aabaf49 | |
coder2020official | 9fa5b91e58 | |
coder2020official | de5a32e45c | |
coder2020official | db087427fc | |
coder2020official | 385fc6a6da | |
coder2020official | ac0b386625 | |
coder2020official | ae44b0022d | |
coder2020official | 73135d6012 | |
coder2020official | 19dcce0d5b | |
coder2020official | f527fc91f6 | |
coder2020official | c0185dad44 | |
coder2020official | 8a858cac4e | |
coder2020official | f30457bd75 | |
coder2020official | 54caf30f69 | |
coder2020official | 09e4a2a437 | |
coder2020official | 9b81a29a6a | |
coder2020official | 65dcd67140 | |
coder2020official | c84b771e5a | |
_run | 2bd81a5f5c | |
Badiboy | 5d9a76b0dd | |
Badiboy | 6459f13f25 | |
Badiboy | c9b6d3f868 | |
Badiboy | 80c1a4798d | |
Dmitry | 7a67d5f9f9 | |
zeldpol | d12ea91e12 | |
orocane | 4f2c89c4a8 | |
_run | fb7d60f09d | |
coder2020official | 8dc4e77287 | |
Badiboy | a999161384 | |
Badiboy | b4196f5891 | |
Badiboy | e55fe962ca | |
Badiboy | 3d2c5c9590 | |
_run | 40567570e8 | |
coder2020official | 4179e502c3 | |
coder2020official | a9b878107c | |
coder2020official | 2094120ec7 | |
coder2020official | d1348606e3 | |
coder2020official | d0d03d0c09 | |
Badiboy | fdd82a5e4b | |
coder2020official | 9e68f76f5d | |
coder2020official | 4000c9fb48 | |
coder2020official | ae42d0b1fe | |
coder2020official | a3891ff363 | |
coder2020official | 4d7f5310fb | |
_run | 3e0d69f7f4 | |
coder2020official | 2e5fb10430 | |
_run | c39c050abf | |
Muhammad Aadil | ed6d6cc03f | |
Muhammad Aadil | 10a80e1cfa | |
Badiboy | d99f48f975 | |
_run | dae2790c61 | |
Badiboy | f5eac56afa | |
_run | 268c3a9210 | |
Muhammad Aadil | ad7e4bbaf7 | |
Artem Lavrenov | b9bedef73f | |
Badiboy | 9fb5f89f18 | |
Oleg Belov | 409ff49603 | |
Albert | 5e0da40fcd | |
Badiboy | b743aa5813 | |
Cub11k | 1797f076dc | |
_run | 68c1fe8cb5 | |
Cub11k | 1eda7cafd4 | |
Badiboy | 291566908b | |
Ilya Krivoshein | bef29d9318 | |
Badiboy | a5af586a46 | |
Cub11k | 93dcbbeb02 | |
Badiboy | bd94d8d91c | |
_run | 6b399ab8cd | |
_run | 8744402efc | |
Badiboy | d5bbaa900e | |
Konstantin Ostashenko | 02ae255701 | |
Cub11k | c27f60b94b | |
Badiboy | a781929a2d | |
Cub11k | e6f8acadf4 | |
Cub11k | c298d95d0f | |
Cub11k | 8aee5372ee | |
_run | df105ab1d8 | |
Cub11k | b93ec5d0e0 | |
Cub11k | f201df3275 | |
_run | 206e4e024b | |
coder2020official | bd1290592b | |
_run | 9b9eb775f7 | |
Konstantin Ostashenko | 3cfa24f9c0 | |
Konstantin Ostashenko | b540a6c4d4 | |
Cub11k | a0ba5ae9af | |
Cub11k | 651db29cb2 | |
Cub11k | 490168f3f6 | |
Cub11k | bf38071e8f | |
Konstantin Ostashenko | e8aaa524fe | |
Konstantin Ostashenko | e2e754fdff | |
_run | d64f305fd4 | |
coder2020official | 611bf4235c | |
Konstantin Ostashenko | fe0dc6930c | |
Konstantin Ostashenko | 6d4d3f8005 | |
Cub11k | 0f7464e8c4 | |
Cub11k | dd50273c95 | |
Cub11k | 8e9d566d5c |
|
@ -0,0 +1,22 @@
|
|||
# .readthedocs.yaml
|
||||
# Read the Docs configuration file
|
||||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
||||
|
||||
# Required
|
||||
version: 2
|
||||
|
||||
# Set the version of Python and other tools you might need
|
||||
build:
|
||||
os: ubuntu-22.04
|
||||
tools:
|
||||
python: "3.9"
|
||||
|
||||
# Build documentation in the docs/ directory with Sphinx
|
||||
sphinx:
|
||||
configuration: docs/conf.py
|
||||
|
||||
# We recommend specifying your dependencies to enable reproducible builds:
|
||||
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
|
||||
python:
|
||||
install:
|
||||
- requirements: docs/requirements.txt
|
11
README.md
11
README.md
|
@ -2,7 +2,6 @@
|
|||
[![PyPi Package Version](https://img.shields.io/pypi/v/pyTelegramBotAPI.svg)](https://pypi.python.org/pypi/pyTelegramBotAPI)
|
||||
[![Supported Python versions](https://img.shields.io/pypi/pyversions/pyTelegramBotAPI.svg)](https://pypi.python.org/pypi/pyTelegramBotAPI)
|
||||
[![Documentation Status](https://readthedocs.org/projects/pytba/badge/?version=latest)](https://pytba.readthedocs.io/en/latest/?badge=latest)
|
||||
[![Build Status](https://travis-ci.org/eternnoir/pyTelegramBotAPI.svg?branch=master)](https://travis-ci.org/eternnoir/pyTelegramBotAPI)
|
||||
[![PyPi downloads](https://img.shields.io/pypi/dm/pyTelegramBotAPI.svg)](https://pypi.org/project/pyTelegramBotAPI/)
|
||||
[![PyPi status](https://img.shields.io/pypi/status/pytelegrambotapi.svg?style=flat-square)](https://pypi.python.org/pypi/pytelegrambotapi)
|
||||
|
||||
|
@ -11,9 +10,10 @@
|
|||
<p align="center">A simple, but extensible Python implementation for the <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.</p>
|
||||
<p align="center">Both synchronous and asynchronous.</p>
|
||||
|
||||
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#december-30-2022">6.4</a>!
|
||||
## <p align="center">Supported Bot API version: <a href="https://core.telegram.org/bots/api#april-21-2023">6.7</a>!
|
||||
|
||||
<h2><a href='https://pytba.readthedocs.io/en/latest/index.html'>Official documentation</a></h2>
|
||||
<h2><a href='https://pytba.readthedocs.io/ru/latest/index.html'>Official ru documentation</a></h2>
|
||||
|
||||
## Contents
|
||||
|
||||
|
@ -265,7 +265,7 @@ def test_callback(call): # <- passes a CallbackQuery type object to your functio
|
|||
|
||||
#### Shipping Query Handler
|
||||
Handle shipping queries
|
||||
`@bot.shipping_query_handeler() # <- passes a ShippingQuery type object to your function`
|
||||
`@bot.shipping_query_handler() # <- passes a ShippingQuery type object to your function`
|
||||
|
||||
#### Pre Checkout Query Handler
|
||||
Handle pre checkoupt queries
|
||||
|
@ -887,5 +887,10 @@ Here are some examples of template:
|
|||
* [Feedback-bot](https://github.com/coder2020official/feedbackbot) A feedback bot for user-admin communication. Made on AsyncTeleBot, using [template](https://github.com/coder2020official/asynctelebot_template).
|
||||
* [TeleServ](https://github.com/ablakely/TeleServ) by [ablakely](https://github.com/ablakely) This is a Telegram to IRC bridge which links as an IRC server and makes Telegram users appear as native IRC users.
|
||||
* [Simple Store Bot](https://github.com/AntonGlyzin/myshopbot) by [Anton Glyzin](https://github.com/AntonGlyzin) This is a simple telegram-store with an admin panel. Designed according to a template.
|
||||
* [Media Rating Bot](https://t.me/mediaratingbot) ([source](https://github.com/CommanderCRM/MediaRatingBot))by [CommanderCRM](https://github.com/CommanderCRM). This bot aggregates media (movies, TV series, etc.) ratings from IMDb, Rotten Tomatoes, Metacritic, TheMovieDB, FilmAffinity and also provides number of votes of said media on IMDb.
|
||||
* [Spot Seek Bot](https://t.me/SpotSeekBot) ([source](https://github.com/arashnm80/spot-seek-bot)) by [Arashnm80](https://github.com/arashnm80). This is a free & open source telegram bot for downloading tracks, albums or playlists from spotify.
|
||||
* [CalendarIT Bot](https://t.me/calendarit_bot) ([source](https://github.com/codebyzen/CalendarIT_Telegram_Bot))by [CodeByZen](https://github.com/codebyzen). A simple, but extensible Python Telegram bot, can post acquainted with what is happening today, tomorrow or what happened 20 years ago to channel.
|
||||
* [DownloadMusicBOT](https://github.com/fcoagz/DownloadMusicBOT) by *Francisco Griman* - It is a simple bot that downloads audio from YouTube videos on Telegram.
|
||||
* [AwesomeChatGPTBot](https://github.com/Kourva/AwesomeChatGPTBot) - Simple ChatGTP-3.5 bot. It is FREE and can remember chat history for a while With pre-defined roles!
|
||||
|
||||
**Want to have your bot listed here? Just make a pull request. Only bots with public source code are accepted.**
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = 'pyTelegramBotAPI Documentation'
|
||||
copyright = '2022, coder2020official'
|
||||
copyright = '2022-2023, coder2020official'
|
||||
author = 'coder2020official'
|
||||
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = '4.9.0'
|
||||
release = '4.12.0'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -9,7 +9,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: pyTelegramBotAPI Documentation \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2022-11-29 14:44+0400\n"
|
||||
"POT-Creation-Date: 2023-07-08 23:07+0500\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -18,19 +18,19 @@ msgstr ""
|
|||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Generated-By: Babel 2.9.1\n"
|
||||
|
||||
#: ../../util.rst:3
|
||||
#: ../../source/util.rst:3
|
||||
msgid "Utils"
|
||||
msgstr ""
|
||||
|
||||
#: ../../util.rst:5
|
||||
#: ../../source/util.rst:5
|
||||
msgid "Utils in pyTelegramBotAPI"
|
||||
msgstr ""
|
||||
|
||||
#: ../../util.rst:5
|
||||
#: ../../source/util.rst:5
|
||||
msgid "ptba, pytba, pyTelegramBotAPI, utils, guide"
|
||||
msgstr ""
|
||||
|
||||
#: ../../util.rst:11
|
||||
#: ../../source/util.rst:11
|
||||
msgid "util file"
|
||||
msgstr ""
|
||||
|
||||
|
@ -40,9 +40,10 @@ msgid ""
|
|||
"error. Example:"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.antiflood telebot.util.escape telebot.util.extract_arguments
|
||||
#: telebot.util.extract_command telebot.util.is_bytes telebot.util.is_command
|
||||
#: telebot.util.is_dict telebot.util.is_pil_image
|
||||
#: of telebot.service_utils.is_bytes telebot.service_utils.is_dict
|
||||
#: telebot.service_utils.is_pil_image telebot.util.antiflood
|
||||
#: telebot.util.escape telebot.util.extract_arguments
|
||||
#: telebot.util.extract_command telebot.util.is_command
|
||||
#: telebot.util.parse_web_app_data telebot.util.quick_markup
|
||||
#: telebot.util.smart_split telebot.util.split_string telebot.util.user_link
|
||||
#: telebot.util.validate_web_app_data telebot.util.webhook_google_functions
|
||||
|
@ -54,28 +55,33 @@ msgid "The function to call"
|
|||
msgstr ""
|
||||
|
||||
#: of telebot.util.antiflood:13
|
||||
msgid "The arguments to pass to the function"
|
||||
msgid "Number of retries to send"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.antiflood:16
|
||||
msgid "The keyword arguments to pass to the function"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.antiflood telebot.util.escape telebot.util.extract_arguments
|
||||
#: telebot.util.extract_command telebot.util.generate_random_token
|
||||
#: telebot.util.is_bytes telebot.util.is_command telebot.util.is_dict
|
||||
#: telebot.util.is_pil_image telebot.util.parse_web_app_data
|
||||
#: telebot.util.quick_markup telebot.util.smart_split telebot.util.split_string
|
||||
#: telebot.util.user_link telebot.util.validate_web_app_data
|
||||
#: telebot.util.webhook_google_functions
|
||||
msgid "Returns"
|
||||
msgid "The arguments to pass to the function"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.antiflood:19
|
||||
msgid "The keyword arguments to pass to the function"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.service_utils.generate_random_token
|
||||
#: telebot.service_utils.is_bytes telebot.service_utils.is_dict
|
||||
#: telebot.service_utils.is_pil_image telebot.util.antiflood
|
||||
#: telebot.util.escape telebot.util.extract_arguments
|
||||
#: telebot.util.extract_command telebot.util.is_command
|
||||
#: telebot.util.parse_web_app_data telebot.util.quick_markup
|
||||
#: telebot.util.smart_split telebot.util.split_string telebot.util.user_link
|
||||
#: telebot.util.validate_web_app_data telebot.util.webhook_google_functions
|
||||
msgid "Returns"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.antiflood:22
|
||||
msgid "None"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.chunks:1
|
||||
#: of telebot.service_utils.chunks:1
|
||||
msgid "Yield successive n-sized chunks from lst."
|
||||
msgstr ""
|
||||
|
||||
|
@ -117,9 +123,10 @@ msgstr ""
|
|||
msgid "the arguments if `text` is a command (according to is_command), else None."
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.extract_arguments telebot.util.extract_command
|
||||
#: telebot.util.generate_random_token telebot.util.is_bytes
|
||||
#: telebot.util.is_command telebot.util.is_dict telebot.util.is_pil_image
|
||||
#: of telebot.service_utils.generate_random_token
|
||||
#: telebot.service_utils.is_bytes telebot.service_utils.is_dict
|
||||
#: telebot.service_utils.is_pil_image telebot.util.extract_arguments
|
||||
#: telebot.util.extract_command telebot.util.is_command
|
||||
#: telebot.util.quick_markup telebot.util.smart_split telebot.util.split_string
|
||||
#: telebot.util.user_link
|
||||
msgid "Return type"
|
||||
|
@ -143,35 +150,35 @@ msgstr ""
|
|||
msgid "the command if `text` is a command (according to is_command), else None."
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.generate_random_token:1
|
||||
#: of telebot.service_utils.generate_random_token:1
|
||||
msgid ""
|
||||
"Generates a random token consisting of letters and digits, 16 characters "
|
||||
"long."
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.generate_random_token:3
|
||||
#: of telebot.service_utils.generate_random_token:3
|
||||
msgid "a random token"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.generate_random_token:4 telebot.util.user_link:22
|
||||
#: of telebot.service_utils.generate_random_token:4 telebot.util.user_link:22
|
||||
msgid ":obj:`str`"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.is_bytes:1
|
||||
#: of telebot.service_utils.is_bytes:1
|
||||
msgid "Returns True if the given object is a bytes object."
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.is_bytes:3 telebot.util.is_dict:3
|
||||
#: telebot.util.is_pil_image:3
|
||||
#: of telebot.service_utils.is_bytes:3 telebot.service_utils.is_dict:3
|
||||
#: telebot.service_utils.is_pil_image:3
|
||||
msgid "object to be checked"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.is_bytes:6
|
||||
#: of telebot.service_utils.is_bytes:6
|
||||
msgid "True if the given object is a bytes object."
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.is_bytes:7 telebot.util.is_command:7 telebot.util.is_dict:7
|
||||
#: telebot.util.is_pil_image:7
|
||||
#: of telebot.service_utils.is_bytes:7 telebot.service_utils.is_dict:7
|
||||
#: telebot.service_utils.is_pil_image:7 telebot.util.is_command:7
|
||||
msgid ":obj:`bool`"
|
||||
msgstr ""
|
||||
|
||||
|
@ -189,23 +196,23 @@ msgstr ""
|
|||
msgid "True if `text` is a command, else False."
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.is_dict:1
|
||||
#: of telebot.service_utils.is_dict:1
|
||||
msgid "Returns True if the given object is a dictionary."
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.is_dict:6
|
||||
#: of telebot.service_utils.is_dict:6
|
||||
msgid "True if the given object is a dictionary."
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.is_pil_image:1
|
||||
#: of telebot.service_utils.is_pil_image:1
|
||||
msgid "Returns True if the given object is a PIL.Image.Image object."
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.is_pil_image:6
|
||||
#: of telebot.service_utils.is_pil_image:6
|
||||
msgid "True if the given object is a PIL.Image.Image object."
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.is_string:1
|
||||
#: of telebot.service_utils.is_string:1
|
||||
msgid "Returns True if the given object is a string."
|
||||
msgstr ""
|
||||
|
||||
|
@ -240,21 +247,21 @@ msgstr ""
|
|||
msgid "Using quick_markup:"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.quick_markup:29
|
||||
#: of telebot.util.quick_markup:31
|
||||
msgid ""
|
||||
"a dict containing all buttons to create in this format: {text: kwargs} "
|
||||
"{str:}"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.quick_markup:32
|
||||
msgid "int row width"
|
||||
#: of telebot.util.quick_markup:34
|
||||
msgid "number of :class:`telebot.types.InlineKeyboardButton` objects on each row"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.quick_markup:35
|
||||
#: of telebot.util.quick_markup:37
|
||||
msgid "InlineKeyboardMarkup"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.quick_markup:36
|
||||
#: of telebot.util.quick_markup:38
|
||||
msgid ":obj:`types.InlineKeyboardMarkup`"
|
||||
msgstr ""
|
||||
|
||||
|
@ -343,3 +350,6 @@ msgstr ""
|
|||
msgid "The response object"
|
||||
msgstr ""
|
||||
|
||||
#~ msgid "int row width"
|
||||
#~ msgstr ""
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -20,38 +20,40 @@ msgstr ""
|
|||
|
||||
#: ../../calldata.rst:4
|
||||
msgid "Callback data factory"
|
||||
msgstr ""
|
||||
msgstr "Фабрика callback data"
|
||||
|
||||
#: ../../calldata.rst:6
|
||||
msgid "Callback data factory in pyTelegramBotAPI"
|
||||
msgstr ""
|
||||
msgstr "Фабрика callback data в pyTelegramBotAPI"
|
||||
|
||||
#: ../../calldata.rst:6
|
||||
msgid ""
|
||||
"ptba, pytba, pyTelegramBotAPI, callbackdatafactory, guide, callbackdata, "
|
||||
"factory"
|
||||
msgstr ""
|
||||
"ptba, pytba, pyTelegramBotAPI, callbackdatafactory, гайд, callbackdata, "
|
||||
"фабрика"
|
||||
|
||||
#: ../../calldata.rst:12
|
||||
msgid "callback\\_data file"
|
||||
msgstr ""
|
||||
msgstr "Файл callback\\_data"
|
||||
|
||||
#: of telebot.callback_data:1
|
||||
msgid "Callback data factory's file."
|
||||
msgstr ""
|
||||
msgstr "Файл фабрики callback data."
|
||||
|
||||
#: of telebot.callback_data.CallbackData:1
|
||||
#: telebot.callback_data.CallbackDataFilter:1
|
||||
msgid "Bases: :py:class:`object`"
|
||||
msgstr ""
|
||||
msgstr "Базовые классы: :py:class:`object`"
|
||||
|
||||
#: of telebot.callback_data.CallbackData:1
|
||||
msgid "Callback data factory This class will help you to work with CallbackQuery"
|
||||
msgstr ""
|
||||
msgstr "Фабрика Callback data. Этот класс поможет вам в работе с CallbackQuery"
|
||||
|
||||
#: of telebot.callback_data.CallbackData.filter:1
|
||||
msgid "Generate filter"
|
||||
msgstr ""
|
||||
msgstr "Сгенерировать фильтр"
|
||||
|
||||
#: of telebot.callback_data.CallbackData.filter
|
||||
#: telebot.callback_data.CallbackData.new
|
||||
|
@ -62,7 +64,7 @@ msgstr ""
|
|||
|
||||
#: of telebot.callback_data.CallbackData.filter:3
|
||||
msgid "specified named parameters will be checked with CallbackQuery.data"
|
||||
msgstr ""
|
||||
msgstr "заданные именованные параметры будут проверены в CallbackQuery.data"
|
||||
|
||||
#: of telebot.callback_data.CallbackData.filter
|
||||
#: telebot.callback_data.CallbackData.new
|
||||
|
@ -73,19 +75,19 @@ msgstr ""
|
|||
|
||||
#: of telebot.callback_data.CallbackData.filter:4
|
||||
msgid "CallbackDataFilter class"
|
||||
msgstr ""
|
||||
msgstr "Класс CallbackDataFilter"
|
||||
|
||||
#: of telebot.callback_data.CallbackData.new:1
|
||||
msgid "Generate callback data"
|
||||
msgstr ""
|
||||
msgstr "Сгенерировать callback data"
|
||||
|
||||
#: of telebot.callback_data.CallbackData.new:3
|
||||
msgid "positional parameters of CallbackData instance parts"
|
||||
msgstr ""
|
||||
msgstr "позиционные параметры экземпляра CallbackData"
|
||||
|
||||
#: of telebot.callback_data.CallbackData.new:4
|
||||
msgid "named parameters"
|
||||
msgstr ""
|
||||
msgstr "именованные параметры"
|
||||
|
||||
#: of telebot.callback_data.CallbackData.new:5
|
||||
msgid "str"
|
||||
|
@ -93,25 +95,27 @@ msgstr ""
|
|||
|
||||
#: of telebot.callback_data.CallbackData.parse:1
|
||||
msgid "Parse data from the callback data"
|
||||
msgstr ""
|
||||
msgstr "Получить данные из callback data"
|
||||
|
||||
#: of telebot.callback_data.CallbackData.parse:3
|
||||
msgid ""
|
||||
"string, use to telebot.types.CallbackQuery to parse it from string to a "
|
||||
"dict"
|
||||
msgstr ""
|
||||
"string, примените к telebot.types.CallbackQuery, чтобы преобразовать "
|
||||
"callback_data из строки (str) в словарь (dict)"
|
||||
|
||||
#: of telebot.callback_data.CallbackData.parse:4
|
||||
msgid "dict parsed from callback data"
|
||||
msgstr ""
|
||||
msgstr "словарь (dict), полученный из callback data"
|
||||
|
||||
#: of telebot.callback_data.CallbackDataFilter:1
|
||||
msgid "Filter for CallbackData."
|
||||
msgstr ""
|
||||
msgstr "Фильтр для CallbackData."
|
||||
|
||||
#: of telebot.callback_data.CallbackDataFilter.check:1
|
||||
msgid "Checks if query.data appropriates to specified config"
|
||||
msgstr ""
|
||||
msgstr "Проверяет, соответствует ли query.data заданной конфигурации"
|
||||
|
||||
#: of telebot.callback_data.CallbackDataFilter.check:3
|
||||
msgid "telebot.types.CallbackQuery"
|
||||
|
@ -119,9 +123,8 @@ msgstr ""
|
|||
|
||||
#: of telebot.callback_data.CallbackDataFilter.check:6
|
||||
msgid "True if query.data appropriates to specified config"
|
||||
msgstr ""
|
||||
msgstr "True, если query.data соответствует заданной конфигурации"
|
||||
|
||||
#: of telebot.callback_data.CallbackDataFilter.check
|
||||
msgid "Return type"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -20,15 +20,15 @@ msgstr ""
|
|||
|
||||
#: ../../index.rst:8
|
||||
msgid "Welcome to pyTelegramBotAPI's documentation!"
|
||||
msgstr ""
|
||||
msgstr "Добро пожаловать в документацию pyTelegramBotAPI!"
|
||||
|
||||
#: ../../index.rst:10
|
||||
msgid "Official documentation of pyTelegramBotAPI"
|
||||
msgstr ""
|
||||
msgstr "Официальная документация pyTelegramBotAPI"
|
||||
|
||||
#: ../../index.rst:10
|
||||
msgid "ptba, pytba, pyTelegramBotAPI, documentation, guide"
|
||||
msgstr ""
|
||||
msgstr "ptba, pytba, pyTelegramBotAPI, документация, гайд"
|
||||
|
||||
#: ../../index.rst:17
|
||||
msgid "TeleBot"
|
||||
|
@ -39,26 +39,32 @@ msgid ""
|
|||
"TeleBot is synchronous and asynchronous implementation of `Telegram Bot "
|
||||
"API <https://core.telegram.org/bots/api>`_."
|
||||
msgstr ""
|
||||
"TeleBot это синхронная и асинхронная реализация `Telegram Bot "
|
||||
"API <https://core.telegram.org/bots/api>`_."
|
||||
|
||||
#: ../../index.rst:21
|
||||
msgid "Chats"
|
||||
msgstr ""
|
||||
msgstr "Чаты"
|
||||
|
||||
#: ../../index.rst:22
|
||||
msgid ""
|
||||
"English chat: `Private chat "
|
||||
"<https://telegram.me/joinchat/Bn4ixj84FIZVkwhk2jag6A>`__"
|
||||
msgstr ""
|
||||
"Англоязычный чат: `Private chat "
|
||||
"<https://telegram.me/joinchat/Bn4ixj84FIZVkwhk2jag6A>`__"
|
||||
|
||||
#: ../../index.rst:24
|
||||
msgid ""
|
||||
"Russian chat: `@pytelegrambotapi_talks_ru "
|
||||
"<https://t.me/pytelegrambotapi_talks_ru>`__"
|
||||
msgstr ""
|
||||
"Русскоязычный чат: `@pytelegrambotapi_talks_ru "
|
||||
"<https://t.me/pytelegrambotapi_talks_ru>`__"
|
||||
|
||||
#: ../../index.rst:26
|
||||
msgid "News: `@pyTelegramBotAPI <https://t.me/pytelegrambotapi>`__"
|
||||
msgstr ""
|
||||
msgstr "Новости: `@pyTelegramBotAPI <https://t.me/pytelegrambotapi>`__"
|
||||
|
||||
#: ../../index.rst:28
|
||||
msgid "Pypi: `Pypi <https://pypi.org/project/pyTelegramBotAPI/>`__"
|
||||
|
@ -69,42 +75,44 @@ msgid ""
|
|||
"Source: `Github repository "
|
||||
"<https://github.com/eternnoir/pyTelegramBotAPI>`__"
|
||||
msgstr ""
|
||||
"Исходники: `Github repository "
|
||||
"<https://github.com/eternnoir/pyTelegramBotAPI>`__"
|
||||
|
||||
#: ../../index.rst:33
|
||||
msgid "Some features:"
|
||||
msgstr ""
|
||||
msgstr "Некоторые особенности:"
|
||||
|
||||
#: ../../index.rst:34
|
||||
msgid "Easy to learn and use."
|
||||
msgstr ""
|
||||
msgstr "Простой в изучении и использовании."
|
||||
|
||||
#: ../../index.rst:36
|
||||
msgid "Easy to understand."
|
||||
msgstr ""
|
||||
msgstr "Простой в понимании."
|
||||
|
||||
#: ../../index.rst:38
|
||||
msgid "Both sync and async."
|
||||
msgstr ""
|
||||
msgstr "И синхронный, и асинхронный."
|
||||
|
||||
#: ../../index.rst:40
|
||||
msgid "Examples on features."
|
||||
msgstr ""
|
||||
msgstr "Примеры возможностей."
|
||||
|
||||
#: ../../index.rst:42
|
||||
msgid "States"
|
||||
msgstr ""
|
||||
msgstr "Состояния (стейты, FSM)"
|
||||
|
||||
#: ../../index.rst:44
|
||||
msgid "And more..."
|
||||
msgstr ""
|
||||
msgstr "И другое..."
|
||||
|
||||
#: ../../index.rst:47
|
||||
msgid "Content"
|
||||
msgstr ""
|
||||
msgstr "Содержимое"
|
||||
|
||||
#: ../../index.rst:63
|
||||
msgid "Indices and tables"
|
||||
msgstr ""
|
||||
msgstr "Ссылки"
|
||||
|
||||
#: ../../index.rst:65
|
||||
msgid ":ref:`genindex`"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -9,7 +9,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: pyTelegramBotAPI Documentation \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2022-11-29 14:44+0400\n"
|
||||
"POT-Creation-Date: 2023-07-08 23:07+0500\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -18,19 +18,19 @@ msgstr ""
|
|||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Generated-By: Babel 2.9.1\n"
|
||||
|
||||
#: ../../util.rst:3
|
||||
#: ../../source/util.rst:3
|
||||
msgid "Utils"
|
||||
msgstr "Утилиты"
|
||||
|
||||
#: ../../util.rst:5
|
||||
#: ../../source/util.rst:5
|
||||
msgid "Utils in pyTelegramBotAPI"
|
||||
msgstr "Утилиты в pyTelegramBotAPI"
|
||||
|
||||
#: ../../util.rst:5
|
||||
#: ../../source/util.rst:5
|
||||
msgid "ptba, pytba, pyTelegramBotAPI, utils, guide"
|
||||
msgstr "ptba, pytba, pyTelegramBotAPI, утилиты, гайд"
|
||||
|
||||
#: ../../util.rst:11
|
||||
#: ../../source/util.rst:11
|
||||
msgid "util file"
|
||||
msgstr "Файл util"
|
||||
|
||||
|
@ -38,11 +38,14 @@ msgstr "Файл util"
|
|||
msgid ""
|
||||
"Use this function inside loops in order to avoid getting TooManyRequests "
|
||||
"error. Example:"
|
||||
msgstr "Используйте эту функцию в циклах, чтобы избежать ошибки TooManyRequests. Пример:"
|
||||
msgstr ""
|
||||
"Используйте эту функцию в циклах, чтобы избежать ошибки TooManyRequests. "
|
||||
"Пример:"
|
||||
|
||||
#: of telebot.util.antiflood telebot.util.escape telebot.util.extract_arguments
|
||||
#: telebot.util.extract_command telebot.util.is_bytes telebot.util.is_command
|
||||
#: telebot.util.is_dict telebot.util.is_pil_image
|
||||
#: of telebot.service_utils.is_bytes telebot.service_utils.is_dict
|
||||
#: telebot.service_utils.is_pil_image telebot.util.antiflood
|
||||
#: telebot.util.escape telebot.util.extract_arguments
|
||||
#: telebot.util.extract_command telebot.util.is_command
|
||||
#: telebot.util.parse_web_app_data telebot.util.quick_markup
|
||||
#: telebot.util.smart_split telebot.util.split_string telebot.util.user_link
|
||||
#: telebot.util.validate_web_app_data telebot.util.webhook_google_functions
|
||||
|
@ -54,28 +57,33 @@ msgid "The function to call"
|
|||
msgstr "Вызываемая функция"
|
||||
|
||||
#: of telebot.util.antiflood:13
|
||||
msgid "Number of retries to send"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.antiflood:16
|
||||
msgid "The arguments to pass to the function"
|
||||
msgstr "Аргументы, для передачи в функцию"
|
||||
|
||||
#: of telebot.util.antiflood:16
|
||||
#: of telebot.util.antiflood:19
|
||||
msgid "The keyword arguments to pass to the function"
|
||||
msgstr "Именованные аргументы для передачи в функцию"
|
||||
|
||||
#: of telebot.util.antiflood telebot.util.escape telebot.util.extract_arguments
|
||||
#: telebot.util.extract_command telebot.util.generate_random_token
|
||||
#: telebot.util.is_bytes telebot.util.is_command telebot.util.is_dict
|
||||
#: telebot.util.is_pil_image telebot.util.parse_web_app_data
|
||||
#: telebot.util.quick_markup telebot.util.smart_split telebot.util.split_string
|
||||
#: telebot.util.user_link telebot.util.validate_web_app_data
|
||||
#: telebot.util.webhook_google_functions
|
||||
#: of telebot.service_utils.generate_random_token
|
||||
#: telebot.service_utils.is_bytes telebot.service_utils.is_dict
|
||||
#: telebot.service_utils.is_pil_image telebot.util.antiflood
|
||||
#: telebot.util.escape telebot.util.extract_arguments
|
||||
#: telebot.util.extract_command telebot.util.is_command
|
||||
#: telebot.util.parse_web_app_data telebot.util.quick_markup
|
||||
#: telebot.util.smart_split telebot.util.split_string telebot.util.user_link
|
||||
#: telebot.util.validate_web_app_data telebot.util.webhook_google_functions
|
||||
msgid "Returns"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.antiflood:19
|
||||
#: of telebot.util.antiflood:22
|
||||
msgid "None"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.chunks:1
|
||||
#: of telebot.service_utils.chunks:1
|
||||
msgid "Yield successive n-sized chunks from lst."
|
||||
msgstr "Генерирует последовательные части списка, состоящие из n элементов."
|
||||
|
||||
|
@ -91,8 +99,9 @@ msgstr "Содержит все виды сервисных сообщений,
|
|||
msgid ""
|
||||
"Replaces the following chars in `text` ('&' with '&', '<' with '<'"
|
||||
" and '>' with '>')."
|
||||
msgstr "Заменяет следующие символы в `text` ('&' на '&', '<' на '<'"
|
||||
" и '>' на '>')."
|
||||
msgstr ""
|
||||
"Заменяет следующие символы в `text` ('&' на '&', '<' на '<' и '>' "
|
||||
"на '>')."
|
||||
|
||||
#: of telebot.util.escape:3
|
||||
msgid "the text to escape"
|
||||
|
@ -116,11 +125,14 @@ msgstr "Строка для извлечения аргументов коман
|
|||
|
||||
#: of telebot.util.extract_arguments:13
|
||||
msgid "the arguments if `text` is a command (according to is_command), else None."
|
||||
msgstr "Аргументы, если `text` является командой (согласно is_command), в остальных случаях None."
|
||||
msgstr ""
|
||||
"Аргументы, если `text` является командой (согласно is_command), в "
|
||||
"остальных случаях None."
|
||||
|
||||
#: of telebot.util.extract_arguments telebot.util.extract_command
|
||||
#: telebot.util.generate_random_token telebot.util.is_bytes
|
||||
#: telebot.util.is_command telebot.util.is_dict telebot.util.is_pil_image
|
||||
#: of telebot.service_utils.generate_random_token
|
||||
#: telebot.service_utils.is_bytes telebot.service_utils.is_dict
|
||||
#: telebot.service_utils.is_pil_image telebot.util.extract_arguments
|
||||
#: telebot.util.extract_command telebot.util.is_command
|
||||
#: telebot.util.quick_markup telebot.util.smart_split telebot.util.split_string
|
||||
#: telebot.util.user_link
|
||||
msgid "Return type"
|
||||
|
@ -135,8 +147,9 @@ msgid ""
|
|||
"Extracts the command from `text` (minus the '/') if `text` is a command "
|
||||
"(see is_command). If `text` is not a command, this function returns None."
|
||||
msgstr ""
|
||||
"Извлекает команду из `text` (исключает '/') если `text` является командой "
|
||||
"(см. is_command). Если `text` не является командой, эта функция возвращает None."
|
||||
"Извлекает команду из `text` (исключает '/') если `text` является командой"
|
||||
" (см. is_command). Если `text` не является командой, эта функция "
|
||||
"возвращает None."
|
||||
|
||||
#: of telebot.util.extract_command:12
|
||||
msgid "String to extract the command from"
|
||||
|
@ -144,37 +157,41 @@ msgstr "Строка, из которой нужно извлечь команд
|
|||
|
||||
#: of telebot.util.extract_command:15
|
||||
msgid "the command if `text` is a command (according to is_command), else None."
|
||||
msgstr "Команда, если `text` является командой (согласно is_command), в остальных случаях None."
|
||||
msgstr ""
|
||||
"Команда, если `text` является командой (согласно is_command), в остальных"
|
||||
" случаях None."
|
||||
|
||||
#: of telebot.util.generate_random_token:1
|
||||
#: of telebot.service_utils.generate_random_token:1
|
||||
msgid ""
|
||||
"Generates a random token consisting of letters and digits, 16 characters "
|
||||
"long."
|
||||
msgstr "Генерирует рандомный токен, состоящий из латинских букв и цифр длиной 16 символов."
|
||||
msgstr ""
|
||||
"Генерирует рандомный токен, состоящий из латинских букв и цифр длиной 16 "
|
||||
"символов."
|
||||
|
||||
#: of telebot.util.generate_random_token:3
|
||||
#: of telebot.service_utils.generate_random_token:3
|
||||
msgid "a random token"
|
||||
msgstr "Сгенерированный токен"
|
||||
|
||||
#: of telebot.util.generate_random_token:4 telebot.util.user_link:22
|
||||
#: of telebot.service_utils.generate_random_token:4 telebot.util.user_link:22
|
||||
msgid ":obj:`str`"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.is_bytes:1
|
||||
#: of telebot.service_utils.is_bytes:1
|
||||
msgid "Returns True if the given object is a bytes object."
|
||||
msgstr "Возвращает True если полученный объект является bytes."
|
||||
|
||||
#: of telebot.util.is_bytes:3 telebot.util.is_dict:3
|
||||
#: telebot.util.is_pil_image:3
|
||||
#: of telebot.service_utils.is_bytes:3 telebot.service_utils.is_dict:3
|
||||
#: telebot.service_utils.is_pil_image:3
|
||||
msgid "object to be checked"
|
||||
msgstr "Объект для проверки"
|
||||
|
||||
#: of telebot.util.is_bytes:6
|
||||
#: of telebot.service_utils.is_bytes:6
|
||||
msgid "True if the given object is a bytes object."
|
||||
msgstr "True, если полученный объект является bytes."
|
||||
|
||||
#: of telebot.util.is_bytes:7 telebot.util.is_command:7 telebot.util.is_dict:7
|
||||
#: telebot.util.is_pil_image:7
|
||||
#: of telebot.service_utils.is_bytes:7 telebot.service_utils.is_dict:7
|
||||
#: telebot.service_utils.is_pil_image:7 telebot.util.is_command:7
|
||||
msgid ":obj:`bool`"
|
||||
msgstr ""
|
||||
|
||||
|
@ -183,8 +200,8 @@ msgid ""
|
|||
"Checks if `text` is a command. Telegram chat commands start with the '/' "
|
||||
"character."
|
||||
msgstr ""
|
||||
"Проверяет, является ли `text` командой. Команды в Telegram начинаются "
|
||||
"с символа '/'."
|
||||
"Проверяет, является ли `text` командой. Команды в Telegram начинаются с "
|
||||
"символа '/'."
|
||||
|
||||
#: of telebot.util.is_command:3
|
||||
msgid "Text to check."
|
||||
|
@ -194,23 +211,23 @@ msgstr "Текст для проверки."
|
|||
msgid "True if `text` is a command, else False."
|
||||
msgstr "True, если `text` является командой, иначе False."
|
||||
|
||||
#: of telebot.util.is_dict:1
|
||||
#: of telebot.service_utils.is_dict:1
|
||||
msgid "Returns True if the given object is a dictionary."
|
||||
msgstr "Возвращает True, если полученный объект является словарём (dict)."
|
||||
|
||||
#: of telebot.util.is_dict:6
|
||||
#: of telebot.service_utils.is_dict:6
|
||||
msgid "True if the given object is a dictionary."
|
||||
msgstr "True, если полученный объект является словарём (dict)."
|
||||
|
||||
#: of telebot.util.is_pil_image:1
|
||||
#: of telebot.service_utils.is_pil_image:1
|
||||
msgid "Returns True if the given object is a PIL.Image.Image object."
|
||||
msgstr "Возвращает True, если полученный объект является PIL.Image.Image."
|
||||
|
||||
#: of telebot.util.is_pil_image:6
|
||||
#: of telebot.service_utils.is_pil_image:6
|
||||
msgid "True if the given object is a PIL.Image.Image object."
|
||||
msgstr "True, если полученный объект является PIL.Image.Image."
|
||||
|
||||
#: of telebot.util.is_string:1
|
||||
#: of telebot.service_utils.is_string:1
|
||||
msgid "Returns True if the given object is a string."
|
||||
msgstr "Возвращает True, если полученный объект является строкой (str)."
|
||||
|
||||
|
@ -236,9 +253,9 @@ msgid ""
|
|||
"is useful to avoid always typing 'btn1 = InlineKeyboardButton(...)' 'btn2"
|
||||
" = InlineKeyboardButton(...)'"
|
||||
msgstr ""
|
||||
"Возвращает reply markup из словаря следующего формата: {'text': kwargs}. Удобно "
|
||||
"использовать вместо постоянного использования 'btn1 = InlineKeyboardButton(...)' 'btn2"
|
||||
" = InlineKeyboardButton(...)'"
|
||||
"Возвращает reply markup из словаря следующего формата: {'text': kwargs}. "
|
||||
"Удобно использовать вместо постоянного использования 'btn1 = "
|
||||
"InlineKeyboardButton(...)' 'btn2 = InlineKeyboardButton(...)'"
|
||||
|
||||
#: of telebot.util.quick_markup:4 telebot.util.user_link:5
|
||||
msgid "Example:"
|
||||
|
@ -248,7 +265,7 @@ msgstr "Пример:"
|
|||
msgid "Using quick_markup:"
|
||||
msgstr "Используя quick_markup:"
|
||||
|
||||
#: of telebot.util.quick_markup:29
|
||||
#: of telebot.util.quick_markup:31
|
||||
msgid ""
|
||||
"a dict containing all buttons to create in this format: {text: kwargs} "
|
||||
"{str:}"
|
||||
|
@ -256,15 +273,15 @@ msgstr ""
|
|||
"Словарь, содержащий все кнопки для создания reply markup в следующем "
|
||||
"формате: {text: kwargs} {str:}"
|
||||
|
||||
#: of telebot.util.quick_markup:32
|
||||
msgid "int row width"
|
||||
msgstr "Количество кнопок в одной строке, int"
|
||||
#: of telebot.util.quick_markup:34
|
||||
msgid "number of :class:`telebot.types.InlineKeyboardButton` objects on each row"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.quick_markup:35
|
||||
#: of telebot.util.quick_markup:37
|
||||
msgid "InlineKeyboardMarkup"
|
||||
msgstr ""
|
||||
|
||||
#: of telebot.util.quick_markup:36
|
||||
#: of telebot.util.quick_markup:38
|
||||
msgid ":obj:`types.InlineKeyboardMarkup`"
|
||||
msgstr ""
|
||||
|
||||
|
@ -276,10 +293,11 @@ msgid ""
|
|||
" `chars_per_string` = 4096. Splits by '\\n', '. ' or ' ' in exactly this "
|
||||
"priority."
|
||||
msgstr ""
|
||||
"Разбивает строку на несколько, каждая из которых будет не длиннее `characters_per_string`. "
|
||||
"Удобно использовать для разбиения одного гигантского сообщения на несколько. "
|
||||
"Если `chars_per_string` > 4096: `chars_per_string` = 4096. Разбивает строку по '\\n', '. ' или ' ' "
|
||||
"именно в таком порядке."
|
||||
"Разбивает строку на несколько, каждая из которых будет не длиннее "
|
||||
"`characters_per_string`. Удобно использовать для разбиения одного "
|
||||
"гигантского сообщения на несколько. Если `chars_per_string` > 4096: "
|
||||
"`chars_per_string` = 4096. Разбивает строку по '\\n', '. ' или ' ' именно"
|
||||
" в таком порядке."
|
||||
|
||||
#: of telebot.util.smart_split:6 telebot.util.split_string:4
|
||||
msgid "The text to split"
|
||||
|
@ -287,7 +305,9 @@ msgstr "Текст для разбиения"
|
|||
|
||||
#: of telebot.util.smart_split:9
|
||||
msgid "The number of maximum characters per part the text is split to."
|
||||
msgstr "Максимальное количество символов в части текста, на которые он будет разбит."
|
||||
msgstr ""
|
||||
"Максимальное количество символов в части текста, на которые он будет "
|
||||
"разбит."
|
||||
|
||||
#: of telebot.util.smart_split:12 telebot.util.split_string:10
|
||||
msgid "The splitted text as a list of strings."
|
||||
|
@ -303,8 +323,9 @@ msgid ""
|
|||
"`chars_per_string` characters per string. This is very useful for "
|
||||
"splitting one giant message into multiples."
|
||||
msgstr ""
|
||||
"Разбивает одну строку на несколько, каждая из которых будет не длиннее `characters_per_string`. "
|
||||
"Удобно использовать для разбиения одного гигантского сообщения на несколько."
|
||||
"Разбивает одну строку на несколько, каждая из которых будет не длиннее "
|
||||
"`characters_per_string`. Удобно использовать для разбиения одного "
|
||||
"гигантского сообщения на несколько."
|
||||
|
||||
#: of telebot.util.split_string:7
|
||||
msgid "The number of characters per line the text is split into."
|
||||
|
@ -312,15 +333,17 @@ msgstr "Количество символов в одной строке, на
|
|||
|
||||
#: ../../docstring of telebot.util.update_types:1
|
||||
msgid "All update types, should be used for allowed_updates parameter in polling."
|
||||
msgstr "Все виды апдейтов, рекомендуется использовать в качестве параметра allowed_updates функции polling."
|
||||
msgstr ""
|
||||
"Все виды апдейтов, рекомендуется использовать в качестве параметра "
|
||||
"allowed_updates функции polling."
|
||||
|
||||
#: of telebot.util.user_link:1
|
||||
msgid ""
|
||||
"Returns an HTML user link. This is useful for reports. Attention: Don't "
|
||||
"forget to set parse_mode to 'HTML'!"
|
||||
msgstr ""
|
||||
"Возвращает HTML ссылку на пользователя. Удобно использовать для отчетов. Важно: Не "
|
||||
"забудьте установить значение 'HTML' в parse_mode!"
|
||||
"Возвращает HTML ссылку на пользователя. Удобно использовать для отчетов. "
|
||||
"Важно: Не забудьте установить значение 'HTML' в parse_mode!"
|
||||
|
||||
#: of telebot.util.user_link:11
|
||||
msgid ""
|
||||
|
@ -328,9 +351,10 @@ msgid ""
|
|||
"links, and etc.) This method is kept for backward compatibility, and it "
|
||||
"is recommended to use formatting.* for more options."
|
||||
msgstr ""
|
||||
"Вы можете использовать formatting.* во всех остальных вариантах форматирования(bold, italic, "
|
||||
"links, и прочее). Этот метод сохранён для обратной совместимости, рекомендуется "
|
||||
"использовать formatting.* для большего количества вариантов."
|
||||
"Вы можете использовать formatting.* во всех остальных вариантах "
|
||||
"форматирования(bold, italic, links, и прочее). Этот метод сохранён для "
|
||||
"обратной совместимости, рекомендуется использовать formatting.* для "
|
||||
"большего количества вариантов."
|
||||
|
||||
#: of telebot.util.user_link:15
|
||||
msgid "the user (not the user_id)"
|
||||
|
@ -364,3 +388,6 @@ msgstr "HTTP-запрос"
|
|||
msgid "The response object"
|
||||
msgstr "Объект, полученный в качестве ответа"
|
||||
|
||||
#~ msgid "int row width"
|
||||
#~ msgstr "Количество кнопок в одной строке, int"
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# This is an example file to create quiz polls
|
||||
import telebot
|
||||
|
||||
API_TOKEN = "<api_token>"
|
||||
|
||||
bot = telebot.TeleBot(API_TOKEN)
|
||||
|
||||
|
||||
@bot.message_handler(commands=["poll"])
|
||||
def create_poll(message):
|
||||
bot.send_message(message.chat.id, "English Article Test")
|
||||
answer_options = ["a", "an", "the", "-"]
|
||||
|
||||
bot.send_poll(
|
||||
chat_id=message.chat.id,
|
||||
question="We are going to '' park.",
|
||||
options=answer_options,
|
||||
type="quiz",
|
||||
correct_option_id=2,
|
||||
is_anonymous=False,
|
||||
)
|
||||
|
||||
|
||||
@bot.poll_answer_handler()
|
||||
def handle_poll(poll):
|
||||
# This handler can be used to log User answers and to send next poll
|
||||
pass
|
||||
|
||||
|
||||
bot.infinity_polling()
|
|
@ -1,4 +1,4 @@
|
|||
pytest
|
||||
requests==2.20.0
|
||||
requests==2.31.0
|
||||
wheel==0.38.1
|
||||
aiohttp>=3.8.0,<3.9.0
|
|
@ -191,7 +191,7 @@ class TeleBot:
|
|||
coloredlogs.install(logger=logger, level=logger.level)
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
'Install colorredlogs module to use colorful_logs option.'
|
||||
'Install coloredlogs module to use colorful_logs option.'
|
||||
)
|
||||
|
||||
# threading-related
|
||||
|
@ -451,7 +451,7 @@ class TeleBot:
|
|||
drop_pending_updates: Optional[bool] = None,
|
||||
timeout: Optional[int]=None,
|
||||
secret_token: Optional[str]=None,
|
||||
secret_token_length: Optional[int]=20,):
|
||||
secret_token_length: Optional[int]=20):
|
||||
"""
|
||||
This class sets webhooks and listens to a given url and port.
|
||||
|
||||
|
@ -1028,7 +1028,7 @@ class TeleBot:
|
|||
:return:
|
||||
"""
|
||||
if none_stop is not None:
|
||||
logger.warning("polling: none_stop parameter is deprecated. Use non_stop instead.")
|
||||
logger.warning('The parameter "none_stop" is deprecated. Use "non_stop" instead.')
|
||||
non_stop = none_stop
|
||||
|
||||
if skip_pending:
|
||||
|
@ -1837,11 +1837,12 @@ class TeleBot:
|
|||
parse_mode: Optional[str]=None,
|
||||
disable_notification: Optional[bool]=None,
|
||||
timeout: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
protect_content: Optional[bool]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,) -> types.Message:
|
||||
"""
|
||||
Use this method to send audio files, if you want Telegram clients to display them in the music player.
|
||||
Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size,
|
||||
|
@ -1887,11 +1888,11 @@ class TeleBot:
|
|||
:param timeout: Timeout in seconds for the request.
|
||||
:type timeout: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
:param thumbnail: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320.
|
||||
Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file,
|
||||
so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>
|
||||
:type thumb: :obj:`str`
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
|
||||
:type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
|
||||
|
@ -1905,6 +1906,9 @@ class TeleBot:
|
|||
:param message_thread_id: Identifier of a message thread, in which the message will be sent
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:param thumb: Deprecated. Use thumbnail instead
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
|
@ -1913,10 +1917,14 @@ class TeleBot:
|
|||
protect_content = self.protect_content if (protect_content is None) else protect_content
|
||||
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')
|
||||
|
||||
return types.Message.de_json(
|
||||
apihelper.send_audio(
|
||||
self.token, chat_id, audio, caption, duration, performer, title, reply_to_message_id,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumb,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumbnail,
|
||||
caption_entities, allow_sending_without_reply, protect_content, message_thread_id))
|
||||
|
||||
# TODO: Rewrite this method like in API.
|
||||
|
@ -2003,13 +2011,14 @@ class TeleBot:
|
|||
parse_mode: Optional[str]=None,
|
||||
disable_notification: Optional[bool]=None,
|
||||
timeout: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
visible_file_name: Optional[str]=None,
|
||||
disable_content_type_detection: Optional[bool]=None,
|
||||
data: Optional[Union[Any, str]]=None,
|
||||
protect_content: Optional[bool]=None, message_thread_id: Optional[int]=None) -> types.Message:
|
||||
protect_content: Optional[bool]=None, message_thread_id: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,) -> types.Message:
|
||||
"""
|
||||
Use this method to send general files.
|
||||
|
||||
|
@ -2042,8 +2051,8 @@ class TeleBot:
|
|||
:param timeout: Timeout in seconds for the request.
|
||||
:type timeout: :obj:`int`
|
||||
|
||||
:param thumb: InputFile or String : Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:param thumbnail: InputFile or String : Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
|
||||
:type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
|
||||
|
@ -2066,6 +2075,9 @@ class TeleBot:
|
|||
:param message_thread_id: The thread to which the message will be sent
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:param thumb: Deprecated. Use thumbnail instead
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
|
@ -2076,13 +2088,18 @@ class TeleBot:
|
|||
|
||||
if data and not(document):
|
||||
# function typo miss compatibility
|
||||
logger.warning('The parameter "data" is deprecated. Use "document" instead.')
|
||||
document = data
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')
|
||||
|
||||
return types.Message.de_json(
|
||||
apihelper.send_data(
|
||||
self.token, chat_id, document, 'document',
|
||||
reply_to_message_id = reply_to_message_id, reply_markup = reply_markup, parse_mode = parse_mode,
|
||||
disable_notification = disable_notification, timeout = timeout, caption = caption, thumb = thumb,
|
||||
disable_notification = disable_notification, timeout = timeout, caption = caption, thumbnail= thumbnail,
|
||||
caption_entities = caption_entities, allow_sending_without_reply = allow_sending_without_reply,
|
||||
disable_content_type_detection = disable_content_type_detection, visible_file_name = visible_file_name,
|
||||
protect_content = protect_content, message_thread_id = message_thread_id))
|
||||
|
@ -2099,7 +2116,8 @@ class TeleBot:
|
|||
allow_sending_without_reply: Optional[bool]=None,
|
||||
protect_content:Optional[bool]=None,
|
||||
data: Union[Any, str]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
emoji: Optional[str]=None) -> types.Message:
|
||||
"""
|
||||
Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers.
|
||||
On success, the sent Message is returned.
|
||||
|
@ -2139,6 +2157,9 @@ class TeleBot:
|
|||
:param message_thread_id: The thread to which the message will be sent
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:param emoji: Emoji associated with the sticker; only for just uploaded stickers
|
||||
:type emoji: :obj:`str`
|
||||
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
|
@ -2148,6 +2169,7 @@ class TeleBot:
|
|||
|
||||
if data and not(sticker):
|
||||
# function typo miss compatibility
|
||||
logger.warning('The parameter "data" is deprecated. Use "sticker" instead.')
|
||||
sticker = data
|
||||
|
||||
return types.Message.de_json(
|
||||
|
@ -2156,14 +2178,14 @@ class TeleBot:
|
|||
reply_to_message_id=reply_to_message_id, reply_markup=reply_markup,
|
||||
disable_notification=disable_notification, timeout=timeout,
|
||||
allow_sending_without_reply=allow_sending_without_reply,
|
||||
protect_content=protect_content, message_thread_id=message_thread_id))
|
||||
protect_content=protect_content, message_thread_id=message_thread_id, emoji=emoji))
|
||||
|
||||
def send_video(
|
||||
self, chat_id: Union[int, str], video: Union[Any, str],
|
||||
duration: Optional[int]=None,
|
||||
width: Optional[int]=None,
|
||||
height: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption: Optional[str]=None,
|
||||
parse_mode: Optional[str]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
|
@ -2176,7 +2198,8 @@ class TeleBot:
|
|||
timeout: Optional[int]=None,
|
||||
data: Optional[Union[Any, str]]=None,
|
||||
message_thread_id: Optional[int]=None,
|
||||
has_spoiler: Optional[bool]=None) -> types.Message:
|
||||
has_spoiler: Optional[bool]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,) -> types.Message:
|
||||
"""
|
||||
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
|
||||
|
||||
|
@ -2197,8 +2220,8 @@ class TeleBot:
|
|||
:param height: Video height
|
||||
:type height: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:param thumbnail: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption: Video caption (may also be used when resending videos by file_id), 0-1024 characters after entities parsing
|
||||
:type caption: :obj:`str`
|
||||
|
@ -2241,6 +2264,9 @@ class TeleBot:
|
|||
:param has_spoiler: Pass True, if the video should be sent as a spoiler
|
||||
:type has_spoiler: :obj:`bool`
|
||||
|
||||
:param thumb: Deprecated. Use thumbnail instead
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
|
@ -2251,12 +2277,17 @@ class TeleBot:
|
|||
|
||||
if data and not(video):
|
||||
# function typo miss compatibility
|
||||
logger.warning('The parameter "data" is deprecated. Use "video" instead.')
|
||||
video = data
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')
|
||||
|
||||
return types.Message.de_json(
|
||||
apihelper.send_video(
|
||||
self.token, chat_id, video, duration, caption, reply_to_message_id, reply_markup,
|
||||
parse_mode, supports_streaming, disable_notification, timeout, thumb, width, height,
|
||||
parse_mode, supports_streaming, disable_notification, timeout, thumbnail, width, height,
|
||||
caption_entities, allow_sending_without_reply, protect_content, message_thread_id, has_spoiler))
|
||||
|
||||
def send_animation(
|
||||
|
@ -2264,7 +2295,7 @@ class TeleBot:
|
|||
duration: Optional[int]=None,
|
||||
width: Optional[int]=None,
|
||||
height: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption: Optional[str]=None,
|
||||
parse_mode: Optional[str]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
|
@ -2275,7 +2306,8 @@ class TeleBot:
|
|||
reply_markup: Optional[REPLY_MARKUP_TYPES]=None,
|
||||
timeout: Optional[int]=None,
|
||||
message_thread_id: Optional[int]=None,
|
||||
has_spoiler: Optional[bool]=None) -> types.Message:
|
||||
has_spoiler: Optional[bool]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,) -> types.Message:
|
||||
"""
|
||||
Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).
|
||||
On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.
|
||||
|
@ -2298,11 +2330,11 @@ class TeleBot:
|
|||
:param height: Animation height
|
||||
:type height: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
:param thumbnail: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320.
|
||||
Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file,
|
||||
so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption: Animation caption (may also be used when resending animation by file_id), 0-1024 characters after entities parsing
|
||||
:type caption: :obj:`str`
|
||||
|
@ -2339,6 +2371,9 @@ class TeleBot:
|
|||
:param has_spoiler: Pass True, if the animation should be sent as a spoiler
|
||||
:type has_spoiler: :obj:`bool`
|
||||
|
||||
:param thumb: Deprecated. Use thumbnail instead
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
|
@ -2347,10 +2382,13 @@ class TeleBot:
|
|||
protect_content = self.protect_content if (protect_content is None) else protect_content
|
||||
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
|
||||
|
||||
if thumbnail is None and thumb is not None:
|
||||
thumbnail = thumb
|
||||
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')
|
||||
return types.Message.de_json(
|
||||
apihelper.send_animation(
|
||||
self.token, chat_id, animation, duration, caption, reply_to_message_id,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumb,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumbnail,
|
||||
caption_entities, allow_sending_without_reply, protect_content, width, height, message_thread_id, has_spoiler))
|
||||
|
||||
# TODO: Rewrite this method like in API.
|
||||
|
@ -2362,10 +2400,11 @@ class TeleBot:
|
|||
reply_markup: Optional[REPLY_MARKUP_TYPES]=None,
|
||||
disable_notification: Optional[bool]=None,
|
||||
timeout: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
protect_content: Optional[bool]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None) -> types.Message:
|
||||
"""
|
||||
As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long.
|
||||
Use this method to send video messages. On success, the sent Message is returned.
|
||||
|
@ -2399,11 +2438,11 @@ class TeleBot:
|
|||
:param timeout: Timeout in seconds for the request.
|
||||
:type timeout: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
:param thumbnail: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320.
|
||||
Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file,
|
||||
so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param allow_sending_without_reply: Pass True, if the message should be sent even if the specified replied-to message is not found
|
||||
:type allow_sending_without_reply: :obj:`bool`
|
||||
|
@ -2414,6 +2453,8 @@ class TeleBot:
|
|||
:param message_thread_id: Identifier of a message thread, in which the video note will be sent
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:param thumb: Deprecated. Use thumbnail instead
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
|
@ -2421,10 +2462,14 @@ class TeleBot:
|
|||
protect_content = self.protect_content if (protect_content is None) else protect_content
|
||||
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
|
||||
|
||||
if thumbnail is None and thumb is not None:
|
||||
thumbnail = thumb
|
||||
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')
|
||||
|
||||
return types.Message.de_json(
|
||||
apihelper.send_video_note(
|
||||
self.token, chat_id, data, duration, length, reply_to_message_id, reply_markup,
|
||||
disable_notification, timeout, thumb, allow_sending_without_reply, protect_content, message_thread_id))
|
||||
disable_notification, timeout, thumbnail, allow_sending_without_reply, protect_content, message_thread_id))
|
||||
|
||||
|
||||
def send_media_group(
|
||||
|
@ -2917,7 +2962,9 @@ class TeleBot:
|
|||
can_add_web_page_previews: Optional[bool]=None,
|
||||
can_change_info: Optional[bool]=None,
|
||||
can_invite_users: Optional[bool]=None,
|
||||
can_pin_messages: Optional[bool]=None) -> bool:
|
||||
can_pin_messages: Optional[bool]=None,
|
||||
permissions: Optional[types.ChatPermissions]=None,
|
||||
use_independent_chat_permissions: Optional[bool]=None) -> bool:
|
||||
"""
|
||||
Use this method to restrict a user in a supergroup.
|
||||
The bot must be an administrator in the supergroup for this to work and must have
|
||||
|
@ -2925,6 +2972,9 @@ class TeleBot:
|
|||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#restrictchatmember
|
||||
|
||||
.. warning::
|
||||
Individual parameters are deprecated and will be removed, use 'permissions' instead.
|
||||
|
||||
:param chat_id: Unique identifier for the target group or username of the target supergroup
|
||||
or channel (in the format @channelusername)
|
||||
:type chat_id: :obj:`int` or :obj:`str`
|
||||
|
@ -2965,15 +3015,34 @@ class TeleBot:
|
|||
:param can_pin_messages: Pass True, if the user is allowed to pin messages. Ignored in public supergroups
|
||||
:type can_pin_messages: :obj:`bool`
|
||||
|
||||
:param use_independent_chat_permissions: Pass True if chat permissions are set independently. Otherwise,
|
||||
the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages,
|
||||
can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and
|
||||
can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
|
||||
:type use_independent_chat_permissions: :obj:`bool`
|
||||
|
||||
:param permissions: Pass ChatPermissions object to set all permissions at once. Use this param instead of
|
||||
passing all boolean parameters.
|
||||
:type permissions: :class:`telebot.types.ChatPermissions`
|
||||
|
||||
:return: True on success
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
if permissions is None:
|
||||
permissions = types.ChatPermissions(
|
||||
can_send_messages=can_send_messages,
|
||||
can_send_media_messages=can_send_media_messages,
|
||||
can_send_polls=can_send_polls,
|
||||
can_send_other_messages=can_send_other_messages,
|
||||
can_add_web_page_previews=can_add_web_page_previews,
|
||||
can_change_info=can_change_info,
|
||||
can_invite_users=can_invite_users,
|
||||
can_pin_messages=can_pin_messages
|
||||
)
|
||||
logger.warning('The parameters "can_..." are deprecated, use "permissions" instead.')
|
||||
return apihelper.restrict_chat_member(
|
||||
self.token, chat_id, user_id, until_date,
|
||||
can_send_messages, can_send_media_messages,
|
||||
can_send_polls, can_send_other_messages,
|
||||
can_add_web_page_previews, can_change_info,
|
||||
can_invite_users, can_pin_messages)
|
||||
self.token, chat_id, user_id, permissions, until_date, use_independent_chat_permissions)
|
||||
|
||||
def promote_chat_member(
|
||||
self, chat_id: Union[int, str], user_id: int,
|
||||
|
@ -3054,7 +3123,7 @@ class TeleBot:
|
|||
:rtype: :obj:`bool`
|
||||
"""
|
||||
if can_manage_voice_chats is not None:
|
||||
logger.warning("promote_chat_member: can_manage_voice_chats parameter is deprecated. Use can_manage_video_chats instead.")
|
||||
logger.warning('The parameter "can_manage_voice_chats" is deprecated. Use "can_manage_video_chats" instead.')
|
||||
if can_manage_video_chats is None:
|
||||
can_manage_video_chats = can_manage_voice_chats
|
||||
|
||||
|
@ -3131,7 +3200,8 @@ class TeleBot:
|
|||
return apihelper.unban_chat_sender_chat(self.token, chat_id, sender_chat_id)
|
||||
|
||||
def set_chat_permissions(
|
||||
self, chat_id: Union[int, str], permissions: types.ChatPermissions) -> bool:
|
||||
self, chat_id: Union[int, str], permissions: types.ChatPermissions,
|
||||
use_independent_chat_permissions: Optional[bool]=None) -> bool:
|
||||
"""
|
||||
Use this method to set default chat permissions for all members.
|
||||
The bot must be an administrator in the group or a supergroup for this to work
|
||||
|
@ -3146,10 +3216,16 @@ class TeleBot:
|
|||
:param permissions: New default chat permissions
|
||||
:type permissions: :class:`telebot.types..ChatPermissions`
|
||||
|
||||
:param use_independent_chat_permissions: Pass True if chat permissions are set independently. Otherwise,
|
||||
the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages,
|
||||
can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and
|
||||
can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
|
||||
:type use_independent_chat_permissions: :obj:`bool`
|
||||
|
||||
:return: True on success
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.set_chat_permissions(self.token, chat_id, permissions)
|
||||
return apihelper.set_chat_permissions(self.token, chat_id, permissions, use_independent_chat_permissions)
|
||||
|
||||
def create_chat_invite_link(
|
||||
self, chat_id: Union[int, str],
|
||||
|
@ -3224,7 +3300,7 @@ class TeleBot:
|
|||
:rtype: :class:`telebot.types.ChatInviteLink`
|
||||
"""
|
||||
return types.ChatInviteLink.de_json(
|
||||
apihelper.edit_chat_invite_link(self.token, chat_id, name, invite_link, expire_date, member_limit, creates_join_request)
|
||||
apihelper.edit_chat_invite_link(self.token, chat_id, invite_link, name, expire_date, member_limit, creates_join_request)
|
||||
)
|
||||
|
||||
def revoke_chat_invite_link(
|
||||
|
@ -3368,6 +3444,110 @@ class TeleBot:
|
|||
result = apihelper.get_my_commands(self.token, scope, language_code)
|
||||
return [types.BotCommand.de_json(cmd) for cmd in result]
|
||||
|
||||
def set_my_name(self, name: Optional[str]=None, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to change the bot's name. Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#setmyname
|
||||
|
||||
:param name: Optional. New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language.
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param language_code: Optional. A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose
|
||||
language there is no dedicated name.
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: True on success.
|
||||
"""
|
||||
|
||||
return apihelper.set_my_name(self.token, name, language_code)
|
||||
|
||||
def get_my_name(self, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to get the current bot name for the given user language.
|
||||
Returns BotName on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#getmyname
|
||||
|
||||
:param language_code: Optional. A two-letter ISO 639-1 language code or an empty string
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: :class:`telebot.types.BotName`
|
||||
"""
|
||||
|
||||
result = apihelper.get_my_name(self.token, language_code)
|
||||
return types.BotName.de_json(result)
|
||||
|
||||
def set_my_description(self, description: Optional[str]=None, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to change the bot's description, which is shown in
|
||||
the chat with the bot if the chat is empty.
|
||||
Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#setmydescription
|
||||
|
||||
:param description: New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
|
||||
:type description: :obj:`str`
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for
|
||||
whose language there is no dedicated description.
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: True on success.
|
||||
"""
|
||||
|
||||
return apihelper.set_my_description(self.token, description, language_code)
|
||||
|
||||
def get_my_description(self, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to get the current bot description for the given user language.
|
||||
Returns BotDescription on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#getmydescription
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code or an empty string
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: :class:`telebot.types.BotDescription`
|
||||
"""
|
||||
|
||||
return types.BotDescription.de_json(apihelper.get_my_description(self.token, language_code))
|
||||
|
||||
def set_my_short_description(self, short_description:Optional[str]=None, language_code:Optional[str]=None):
|
||||
"""
|
||||
Use this method to change the bot's short description, which is shown on the bot's profile page and
|
||||
is sent together with the link when users share the bot.
|
||||
Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#setmyshortdescription
|
||||
|
||||
:param short_description: New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language.
|
||||
:type short_description: :obj:`str`
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code.
|
||||
If empty, the short description will be applied to all users for whose language there is no dedicated short description.
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: True on success.
|
||||
"""
|
||||
|
||||
return apihelper.set_my_short_description(self.token, short_description, language_code)
|
||||
|
||||
def get_my_short_description(self, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to get the current bot short description for the given user language.
|
||||
Returns BotShortDescription on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#getmyshortdescription
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code or an empty string
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: :class:`telebot.types.BotShortDescription`
|
||||
"""
|
||||
|
||||
return types.BotShortDescription.de_json(apihelper.get_my_short_description(self.token, language_code))
|
||||
|
||||
def set_chat_menu_button(self, chat_id: Union[int, str]=None,
|
||||
menu_button: types.MenuButton=None) -> bool:
|
||||
"""
|
||||
|
@ -4197,7 +4377,7 @@ class TeleBot:
|
|||
|
||||
def stop_poll(
|
||||
self, chat_id: Union[int, str], message_id: int,
|
||||
reply_markup: Optional[REPLY_MARKUP_TYPES]=None) -> types.Poll:
|
||||
reply_markup: Optional[types.InlineKeyboardMarkup]=None) -> types.Poll:
|
||||
"""
|
||||
Use this method to stop a poll which was sent by the bot. On success, the stopped Poll is returned.
|
||||
|
||||
|
@ -4210,7 +4390,7 @@ class TeleBot:
|
|||
:type message_id: :obj:`int`
|
||||
|
||||
:param reply_markup: A JSON-serialized object for a new message markup.
|
||||
:type reply_markup: :obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`
|
||||
:type reply_markup: :obj:`InlineKeyboardMarkup`
|
||||
|
||||
:return: On success, the stopped Poll is returned.
|
||||
:rtype: :obj:`types.Poll`
|
||||
|
@ -4341,7 +4521,8 @@ class TeleBot:
|
|||
is_personal: Optional[bool]=None,
|
||||
next_offset: Optional[str]=None,
|
||||
switch_pm_text: Optional[str]=None,
|
||||
switch_pm_parameter: Optional[str]=None) -> bool:
|
||||
switch_pm_parameter: Optional[str]=None,
|
||||
button: Optional[types.InlineQueryResultsButton]=None) -> bool:
|
||||
"""
|
||||
Use this method to send answers to an inline query. On success, True is returned.
|
||||
No more than 50 results per query are allowed.
|
||||
|
@ -4377,11 +4558,18 @@ class TeleBot:
|
|||
:param switch_pm_text: Parameter for the start message sent to the bot when user presses the switch button
|
||||
:type switch_pm_text: :obj:`str`
|
||||
|
||||
:param button: A JSON-serialized object describing a button to be shown above inline query results
|
||||
:type button: :obj:`types.InlineQueryResultsButton`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
if not button and (switch_pm_text or switch_pm_parameter):
|
||||
logger.warning("switch_pm_text and switch_pm_parameter are deprecated for answer_inline_query. Use button instead.")
|
||||
button = types.InlineQueryResultsButton(text=switch_pm_text, start_parameter=switch_pm_parameter)
|
||||
|
||||
return apihelper.answer_inline_query(self.token, inline_query_id, results, cache_time, is_personal, next_offset,
|
||||
switch_pm_text, switch_pm_parameter)
|
||||
button)
|
||||
|
||||
def answer_callback_query(
|
||||
self, callback_query_id: int,
|
||||
|
@ -4414,8 +4602,30 @@ class TeleBot:
|
|||
"""
|
||||
return apihelper.answer_callback_query(self.token, callback_query_id, text, show_alert, url, cache_time)
|
||||
|
||||
def set_sticker_set_thumb(
|
||||
self, name: str, user_id: int, thumb: Union[Any, str]=None):
|
||||
def set_sticker_set_thumbnail(self, name: str, user_id: int, thumbnail: Union[Any, str]=None):
|
||||
"""
|
||||
Use this method to set the thumbnail of a sticker set.
|
||||
Animated thumbnails can be set for animated sticker sets only. Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#setstickersetthumb
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param user_id: User identifier
|
||||
:type user_id: :obj:`int`
|
||||
|
||||
:param thumbnail: A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files ». Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail.
|
||||
:type thumbnail: :obj:`filelike object`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
return apihelper.set_sticker_set_thumbnail(self.token, name, user_id, thumbnail)
|
||||
|
||||
@util.deprecated(deprecation_text="Use set_sticker_set_thumbnail instead")
|
||||
def set_sticker_set_thumb(self, name: str, user_id: int, thumb: Union[Any, str]=None):
|
||||
"""
|
||||
Use this method to set the thumbnail of a sticker set.
|
||||
Animated thumbnails can be set for animated sticker sets only. Returns True on success.
|
||||
|
@ -4434,7 +4644,8 @@ class TeleBot:
|
|||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.set_sticker_set_thumb(self.token, name, user_id, thumb)
|
||||
# deprecated
|
||||
return self.set_sticker_set_thumbnail(name, user_id, thumb)
|
||||
|
||||
def get_sticker_set(self, name: str) -> types.StickerSet:
|
||||
"""
|
||||
|
@ -4464,8 +4675,107 @@ class TeleBot:
|
|||
"""
|
||||
result = apihelper.get_custom_emoji_stickers(self.token, custom_emoji_ids)
|
||||
return [types.Sticker.de_json(sticker) for sticker in result]
|
||||
|
||||
def set_sticker_keywords(self, sticker: str, keywords: List[str]=None) -> bool:
|
||||
"""
|
||||
Use this method to change search keywords assigned to a regular or custom emoji sticker.
|
||||
The sticker must belong to a sticker set created by the bot.
|
||||
Returns True on success.
|
||||
|
||||
def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]) -> types.File:
|
||||
:param sticker: File identifier of the sticker.
|
||||
:type sticker: :obj:`str`
|
||||
|
||||
:param keywords: A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters
|
||||
:type keywords: :obj:`list` of :obj:`str`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.set_sticker_keywords(self.token, sticker, keywords)
|
||||
|
||||
def set_sticker_mask_position(self, sticker: str, mask_position: types.MaskPosition=None) -> bool:
|
||||
"""
|
||||
Use this method to change the mask position of a mask sticker.
|
||||
The sticker must belong to a sticker set that was created by the bot.
|
||||
Returns True on success.
|
||||
|
||||
:param sticker: File identifier of the sticker.
|
||||
:type sticker: :obj:`str`
|
||||
|
||||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces.
|
||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.set_sticker_mask_position(self.token, sticker, mask_position)
|
||||
|
||||
|
||||
def set_custom_emoji_sticker_set_thumbnail(self, name: str, custom_emoji_id: Optional[str]=None) -> bool:
|
||||
"""
|
||||
Use this method to set the thumbnail of a custom emoji sticker set.
|
||||
Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param custom_emoji_id: Custom emoji identifier of a sticker from the sticker set; pass an empty string to drop the thumbnail and use the first sticker as the thumbnail.
|
||||
:type custom_emoji_id: :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return apihelper.set_custom_emoji_sticker_set_thumbnail(self.token, name, custom_emoji_id)
|
||||
|
||||
def set_sticker_set_title(self, name: str, title: str) -> bool:
|
||||
"""
|
||||
Use this method to set the title of a created sticker set.
|
||||
Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param title: New sticker set title
|
||||
:type title: :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
return apihelper.set_sticker_set_title(self.token, name, title)
|
||||
|
||||
def delete_sticker_set(self, name:str) -> bool:
|
||||
"""
|
||||
Use this method to delete a sticker set. Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
return apihelper.delete_sticker_set(self.token, name)
|
||||
|
||||
def set_sticker_emoji_list(self, sticker: str, emoji_list: List[str]) -> bool:
|
||||
"""
|
||||
Use this method to set the emoji list of a custom emoji sticker set.
|
||||
Returns True on success.
|
||||
|
||||
:param sticker: Sticker identifier
|
||||
:type sticker: :obj:`str`
|
||||
|
||||
:param emoji_list: List of emoji
|
||||
:type emoji_list: :obj:`list` of :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
return apihelper.set_sticker_emoji_list(self.token, sticker, emoji_list)
|
||||
|
||||
|
||||
def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]=None, sticker: Optional[types.InputFile]=None, sticker_format: Optional[str]=None) -> types.File:
|
||||
"""
|
||||
Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet
|
||||
methods (can be used multiple times). Returns the uploaded File on success.
|
||||
|
@ -4475,25 +4785,40 @@ class TeleBot:
|
|||
:param user_id: User identifier of sticker set owner
|
||||
:type user_id: :obj:`int`
|
||||
|
||||
:param png_sticker: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
|
||||
:param png_sticker: DEPRECATED: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
|
||||
and either width or height must be exactly 512px.
|
||||
:type png_sticker: :obj:`filelike object`
|
||||
|
||||
:param sticker: A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format.
|
||||
See https://core.telegram.org/stickers for technical requirements. More information on Sending Files »
|
||||
:type sticker: :class:`telebot.types.InputFile`
|
||||
|
||||
:param sticker_format: One of "static", "animated", "video".
|
||||
:type sticker_format: :obj:`str`
|
||||
|
||||
:return: On success, the sent file is returned.
|
||||
:rtype: :class:`telebot.types.File`
|
||||
"""
|
||||
result = apihelper.upload_sticker_file(self.token, user_id, png_sticker)
|
||||
if png_sticker:
|
||||
logger.warning('The parameter "png_sticker" is deprecated. Use "sticker" instead.')
|
||||
sticker = png_sticker
|
||||
sticker_format = "static"
|
||||
|
||||
result = apihelper.upload_sticker_file(self.token, user_id, sticker, sticker_format)
|
||||
return types.File.de_json(result)
|
||||
|
||||
def create_new_sticker_set(
|
||||
self, user_id: int, name: str, title: str,
|
||||
emojis: str,
|
||||
emojis: Optional[List[str]]=None,
|
||||
png_sticker: Union[Any, str]=None,
|
||||
tgs_sticker: Union[Any, str]=None,
|
||||
webm_sticker: Union[Any, str]=None,
|
||||
contains_masks: Optional[bool]=None,
|
||||
sticker_type: Optional[str]=None,
|
||||
mask_position: Optional[types.MaskPosition]=None) -> bool:
|
||||
mask_position: Optional[types.MaskPosition]=None,
|
||||
needs_repainting: Optional[bool]=None,
|
||||
stickers: List[types.InputSticker]=None,
|
||||
sticker_format: Optional[str]=None) -> bool:
|
||||
"""
|
||||
Use this method to create new sticker set owned by a user.
|
||||
The bot will be able to edit the created sticker set.
|
||||
|
@ -4501,6 +4826,9 @@ class TeleBot:
|
|||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#createnewstickerset
|
||||
|
||||
.. note::
|
||||
Fields *_sticker are deprecated, pass a list of stickers to stickers parameter instead.
|
||||
|
||||
:param user_id: User identifier of created sticker set owner
|
||||
:type user_id: :obj:`int`
|
||||
|
||||
|
@ -4530,38 +4858,69 @@ class TeleBot:
|
|||
use sticker_type instead.
|
||||
:type contains_masks: :obj:`bool`
|
||||
|
||||
:param sticker_type: Optional, Type of stickers in the set, pass “regular” or “mask”. Custom emoji sticker sets can't be created
|
||||
via the Bot API at the moment. By default, a regular sticker set is created.
|
||||
:param sticker_type: Type of stickers in the set, pass “regular”, “mask”, or “custom_emoji”. By default, a regular sticker set is created.
|
||||
:type sticker_type: :obj:`str`
|
||||
|
||||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces
|
||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||
|
||||
:param needs_repainting: Pass True if stickers in the sticker set must be repainted to the color of text when used in messages,
|
||||
the accent color if used as emoji status, white on chat photos, or another appropriate color based on context;
|
||||
for custom emoji sticker sets only
|
||||
:type needs_repainting: :obj:`bool`
|
||||
|
||||
:param stickers: List of stickers to be added to the set
|
||||
:type stickers: :obj:`list` of :class:`telebot.types.InputSticker`
|
||||
|
||||
:param sticker_format: Format of stickers in the set, must be one of “static”, “animated”, “video”
|
||||
:type sticker_format: :obj:`str`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
if tgs_sticker:
|
||||
sticker_format = 'animated'
|
||||
elif webm_sticker:
|
||||
sticker_format = 'video'
|
||||
elif png_sticker:
|
||||
sticker_format = 'static'
|
||||
|
||||
if contains_masks is not None:
|
||||
logger.warning('The parameter "contains_masks" is deprecated, use "sticker_type" instead')
|
||||
if sticker_type is None:
|
||||
sticker_type = 'mask' if contains_masks else 'regular'
|
||||
|
||||
if stickers is None:
|
||||
stickers = png_sticker or tgs_sticker or webm_sticker
|
||||
if stickers is None:
|
||||
raise ValueError('You must pass at least one sticker')
|
||||
stickers = [types.InputSticker(sticker=stickers, emoji_list=emojis, mask_position=mask_position)]
|
||||
|
||||
|
||||
|
||||
return apihelper.create_new_sticker_set(
|
||||
self.token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
||||
mask_position, webm_sticker, sticker_type)
|
||||
self.token, user_id, name, title, stickers, sticker_format, sticker_type, needs_repainting)
|
||||
|
||||
|
||||
def add_sticker_to_set(
|
||||
self, user_id: int, name: str, emojis: str,
|
||||
self, user_id: int, name: str, emojis: Union[List[str], str],
|
||||
png_sticker: Optional[Union[Any, str]]=None,
|
||||
tgs_sticker: Optional[Union[Any, str]]=None,
|
||||
webm_sticker: Optional[Union[Any, str]]=None,
|
||||
mask_position: Optional[types.MaskPosition]=None) -> bool:
|
||||
mask_position: Optional[types.MaskPosition]=None,
|
||||
sticker: Optional[List[types.InputSticker]]=None) -> bool:
|
||||
"""
|
||||
Use this method to add a new sticker to a set created by the bot.
|
||||
It's required to pass `png_sticker` or `tgs_sticker`.
|
||||
Use this method to add a new sticker to a set created by the bot.
|
||||
The format of the added sticker must match the format of the other stickers in the set.
|
||||
Emoji sticker sets can have up to 200 stickers. Animated and video sticker sets can have up to 50 stickers.
|
||||
Static sticker sets can have up to 120 stickers.
|
||||
Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#addstickertoset
|
||||
|
||||
.. note::
|
||||
**_sticker, mask_position, emojis parameters are deprecated, use stickers instead
|
||||
|
||||
:param user_id: User identifier of created sticker set owner
|
||||
:type user_id: :obj:`int`
|
||||
|
||||
|
@ -4585,11 +4944,27 @@ class TeleBot:
|
|||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces
|
||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||
|
||||
:param sticker: A JSON-serialized list of 1-50 initial stickers to be added to the sticker set
|
||||
:type sticker: :obj:`list` of :class:`telebot.types.InputSticker`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
# split emojis if string
|
||||
if isinstance(emojis, str):
|
||||
emojis = list(emojis)
|
||||
# Replaced the parameters png_sticker, tgs_sticker, webm_sticker, emojis and mask_position
|
||||
if sticker is None:
|
||||
old_sticker = png_sticker or tgs_sticker or webm_sticker
|
||||
if old_sticker is not None:
|
||||
logger.warning('The parameters "..._sticker", "emojis" and "mask_position" are deprecated, use "sticker" instead')
|
||||
if not old_sticker:
|
||||
raise ValueError('You must pass at least one sticker.')
|
||||
sticker = types.InputSticker(old_sticker, emojis, mask_position)
|
||||
|
||||
return apihelper.add_sticker_to_set(
|
||||
self.token, user_id, name, emojis, png_sticker, tgs_sticker, mask_position, webm_sticker)
|
||||
self.token, user_id, name, sticker)
|
||||
|
||||
def set_sticker_position_in_set(self, sticker: str, position: int) -> bool:
|
||||
"""
|
||||
|
@ -6223,7 +6598,7 @@ class TeleBot:
|
|||
Registers chat member handler.
|
||||
|
||||
:param callback: function to be called
|
||||
:type callback: :obj:`function``
|
||||
:type callback: :obj:`function`
|
||||
|
||||
:param func: Function executed as a filter
|
||||
:type func: :obj:`function`
|
||||
|
@ -6426,7 +6801,6 @@ class TeleBot:
|
|||
if not process_handler: continue
|
||||
for i in inspect.signature(handler['function']).parameters:
|
||||
params.append(i)
|
||||
result = None
|
||||
if len(params) == 1:
|
||||
result = handler['function'](message)
|
||||
elif "data" in params:
|
||||
|
|
|
@ -355,15 +355,15 @@ def get_chat_member_count(token, chat_id):
|
|||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
|
||||
def set_sticker_set_thumb(token, name, user_id, thumb):
|
||||
method_url = r'setStickerSetThumb'
|
||||
def set_sticker_set_thumbnail(token, name, user_id, thumbnail):
|
||||
method_url = r'setStickerSetThumbnail'
|
||||
payload = {'name': name, 'user_id': user_id}
|
||||
files = {}
|
||||
if thumb:
|
||||
if not isinstance(thumb, str):
|
||||
files['thumb'] = thumb
|
||||
if thumbnail:
|
||||
if not isinstance(thumbnail, str):
|
||||
files['thumbnail'] = thumbnail
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumbnail
|
||||
return _make_request(token, method_url, params=payload, files=files or None)
|
||||
|
||||
|
||||
|
@ -668,8 +668,8 @@ def send_chat_action(token, chat_id, action, timeout=None, message_thread_id=Non
|
|||
|
||||
|
||||
def send_video(token, chat_id, data, duration=None, caption=None, reply_to_message_id=None, reply_markup=None,
|
||||
parse_mode=None, supports_streaming=None, disable_notification=None, timeout=None,
|
||||
thumb=None, width=None, height=None, caption_entities=None, allow_sending_without_reply=None, protect_content=None,
|
||||
parse_mode=None, supports_streaming=None, disable_notification=None, timeout=None,
|
||||
thumbnail=None, width=None, height=None, caption_entities=None, allow_sending_without_reply=None, protect_content=None,
|
||||
message_thread_id=None, has_spoiler=None):
|
||||
method_url = r'sendVideo'
|
||||
payload = {'chat_id': chat_id}
|
||||
|
@ -694,14 +694,14 @@ def send_video(token, chat_id, data, duration=None, caption=None, reply_to_messa
|
|||
payload['disable_notification'] = disable_notification
|
||||
if timeout:
|
||||
payload['timeout'] = timeout
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if thumbnail:
|
||||
if not util.is_string(thumbnail):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumbnail
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumbnail}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumbnail
|
||||
if width:
|
||||
payload['width'] = width
|
||||
if height:
|
||||
|
@ -721,7 +721,7 @@ def send_video(token, chat_id, data, duration=None, caption=None, reply_to_messa
|
|||
|
||||
def send_animation(
|
||||
token, chat_id, data, duration=None, caption=None, reply_to_message_id=None, reply_markup=None,
|
||||
parse_mode=None, disable_notification=None, timeout=None, thumb=None, caption_entities=None,
|
||||
parse_mode=None, disable_notification=None, timeout=None, thumbnail=None, caption_entities=None,
|
||||
allow_sending_without_reply=None, protect_content=None, width=None, height=None, message_thread_id=None,
|
||||
has_spoiler=None):
|
||||
method_url = r'sendAnimation'
|
||||
|
@ -745,14 +745,14 @@ def send_animation(
|
|||
payload['disable_notification'] = disable_notification
|
||||
if timeout:
|
||||
payload['timeout'] = timeout
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if thumbnail:
|
||||
if not util.is_string(thumbnail):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumbnail
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumbnail}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumbnail
|
||||
if caption_entities:
|
||||
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
|
||||
if allow_sending_without_reply is not None:
|
||||
|
@ -806,7 +806,7 @@ def send_voice(token, chat_id, voice, caption=None, duration=None, reply_to_mess
|
|||
|
||||
|
||||
def send_video_note(token, chat_id, data, duration=None, length=None, reply_to_message_id=None, reply_markup=None,
|
||||
disable_notification=None, timeout=None, thumb=None, allow_sending_without_reply=None, protect_content=None,
|
||||
disable_notification=None, timeout=None, thumbnail=None, allow_sending_without_reply=None, protect_content=None,
|
||||
message_thread_id=None):
|
||||
method_url = r'sendVideoNote'
|
||||
payload = {'chat_id': chat_id}
|
||||
|
@ -829,14 +829,14 @@ def send_video_note(token, chat_id, data, duration=None, length=None, reply_to_m
|
|||
payload['disable_notification'] = disable_notification
|
||||
if timeout:
|
||||
payload['timeout'] = timeout
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if thumbnail:
|
||||
if not util.is_string(thumbnail):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumbnail
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumbnail}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumbnail
|
||||
if allow_sending_without_reply is not None:
|
||||
payload['allow_sending_without_reply'] = allow_sending_without_reply
|
||||
if protect_content is not None:
|
||||
|
@ -847,7 +847,7 @@ def send_video_note(token, chat_id, data, duration=None, length=None, reply_to_m
|
|||
|
||||
|
||||
def send_audio(token, chat_id, audio, caption=None, duration=None, performer=None, title=None, reply_to_message_id=None,
|
||||
reply_markup=None, parse_mode=None, disable_notification=None, timeout=None, thumb=None,
|
||||
reply_markup=None, parse_mode=None, disable_notification=None, timeout=None, thumbnail=None,
|
||||
caption_entities=None, allow_sending_without_reply=None, protect_content=None, message_thread_id=None):
|
||||
method_url = r'sendAudio'
|
||||
payload = {'chat_id': chat_id}
|
||||
|
@ -874,14 +874,14 @@ def send_audio(token, chat_id, audio, caption=None, duration=None, performer=Non
|
|||
payload['disable_notification'] = disable_notification
|
||||
if timeout:
|
||||
payload['timeout'] = timeout
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if thumbnail:
|
||||
if not util.is_string(thumbnail):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumbnail
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumbnail}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumbnail
|
||||
if caption_entities:
|
||||
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
|
||||
if allow_sending_without_reply is not None:
|
||||
|
@ -894,9 +894,9 @@ def send_audio(token, chat_id, audio, caption=None, duration=None, performer=Non
|
|||
|
||||
|
||||
def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None, parse_mode=None,
|
||||
disable_notification=None, timeout=None, caption=None, thumb=None, caption_entities=None,
|
||||
disable_notification=None, timeout=None, caption=None, thumbnail=None, caption_entities=None,
|
||||
allow_sending_without_reply=None, disable_content_type_detection=None, visible_file_name=None,
|
||||
protect_content = None, message_thread_id=None):
|
||||
protect_content = None, message_thread_id=None, emoji=None):
|
||||
method_url = get_method_by_type(data_type)
|
||||
payload = {'chat_id': chat_id}
|
||||
files = None
|
||||
|
@ -919,14 +919,14 @@ def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_m
|
|||
payload['timeout'] = timeout
|
||||
if caption:
|
||||
payload['caption'] = caption
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if thumbnail:
|
||||
if not util.is_string(thumbnail):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumbnail
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumbnail}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumbnail
|
||||
if caption_entities:
|
||||
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
|
||||
if allow_sending_without_reply is not None:
|
||||
|
@ -937,6 +937,8 @@ def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_m
|
|||
payload['disable_content_type_detection'] = disable_content_type_detection
|
||||
if message_thread_id:
|
||||
payload['message_thread_id'] = message_thread_id
|
||||
if emoji:
|
||||
payload['emoji'] = emoji
|
||||
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
|
@ -968,36 +970,19 @@ def unban_chat_member(token, chat_id, user_id, only_if_banned):
|
|||
|
||||
|
||||
def restrict_chat_member(
|
||||
token, chat_id, user_id, until_date=None,
|
||||
can_send_messages=None, can_send_media_messages=None,
|
||||
can_send_polls=None, can_send_other_messages=None,
|
||||
can_add_web_page_previews=None, can_change_info=None,
|
||||
can_invite_users=None, can_pin_messages=None):
|
||||
token, chat_id, user_id, permissions, until_date=None,
|
||||
use_independent_chat_permissions=None):
|
||||
method_url = 'restrictChatMember'
|
||||
permissions = {}
|
||||
if can_send_messages is not None:
|
||||
permissions['can_send_messages'] = can_send_messages
|
||||
if can_send_media_messages is not None:
|
||||
permissions['can_send_media_messages'] = can_send_media_messages
|
||||
if can_send_polls is not None:
|
||||
permissions['can_send_polls'] = can_send_polls
|
||||
if can_send_other_messages is not None:
|
||||
permissions['can_send_other_messages'] = can_send_other_messages
|
||||
if can_add_web_page_previews is not None:
|
||||
permissions['can_add_web_page_previews'] = can_add_web_page_previews
|
||||
if can_change_info is not None:
|
||||
permissions['can_change_info'] = can_change_info
|
||||
if can_invite_users is not None:
|
||||
permissions['can_invite_users'] = can_invite_users
|
||||
if can_pin_messages is not None:
|
||||
permissions['can_pin_messages'] = can_pin_messages
|
||||
permissions_json = json.dumps(permissions)
|
||||
payload = {'chat_id': chat_id, 'user_id': user_id, 'permissions': permissions_json}
|
||||
payload = {'chat_id': chat_id, 'user_id': user_id, 'permissions': permissions.to_json()}
|
||||
|
||||
if use_independent_chat_permissions is not None:
|
||||
payload['use_independent_chat_permissions'] = use_independent_chat_permissions
|
||||
if until_date is not None:
|
||||
if isinstance(until_date, datetime):
|
||||
payload['until_date'] = until_date.timestamp()
|
||||
else:
|
||||
payload['until_date'] = until_date
|
||||
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
|
@ -1056,12 +1041,14 @@ def unban_chat_sender_chat(token, chat_id, sender_chat_id):
|
|||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
def set_chat_permissions(token, chat_id, permissions):
|
||||
def set_chat_permissions(token, chat_id, permissions, use_independent_chat_permissions=None):
|
||||
method_url = 'setChatPermissions'
|
||||
payload = {
|
||||
'chat_id': chat_id,
|
||||
'permissions': permissions.to_json()
|
||||
}
|
||||
if use_independent_chat_permissions is not None:
|
||||
payload['use_independent_chat_permissions'] = use_independent_chat_permissions
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
|
@ -1167,6 +1154,39 @@ def set_chat_title(token, chat_id, title):
|
|||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
def set_my_description(token, description=None, language_code=None):
|
||||
method_url = r'setMyDescription'
|
||||
payload = {}
|
||||
if description is not None:
|
||||
payload['description'] = description
|
||||
if language_code is not None:
|
||||
payload['language_code'] = language_code
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
def get_my_description(token, language_code=None):
|
||||
method_url = r'getMyDescription'
|
||||
payload = {}
|
||||
if language_code:
|
||||
payload['language_code'] = language_code
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
def set_my_short_description(token, short_description=None, language_code=None):
|
||||
method_url = r'setMyShortDescription'
|
||||
payload = {}
|
||||
if short_description is not None:
|
||||
payload['short_description'] = short_description
|
||||
if language_code is not None:
|
||||
payload['language_code'] = language_code
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
def get_my_short_description(token, language_code=None):
|
||||
method_url = r'getMyShortDescription'
|
||||
payload = {}
|
||||
if language_code:
|
||||
payload['language_code'] = language_code
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
def get_my_commands(token, scope=None, language_code=None):
|
||||
method_url = r'getMyCommands'
|
||||
payload = {}
|
||||
|
@ -1176,6 +1196,22 @@ def get_my_commands(token, scope=None, language_code=None):
|
|||
payload['language_code'] = language_code
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
def set_my_name(token, name=None, language_code=None):
|
||||
method_url = r'setMyName'
|
||||
payload = {}
|
||||
if name is not None:
|
||||
payload['name'] = name
|
||||
if language_code is not None:
|
||||
payload['language_code'] = language_code
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
def get_my_name(token, language_code=None):
|
||||
method_url = r'getMyName'
|
||||
payload = {}
|
||||
if language_code is not None:
|
||||
payload['language_code'] = language_code
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
def set_chat_menu_button(token, chat_id=None, menu_button=None):
|
||||
method_url = r'setChatMenuButton'
|
||||
payload = {}
|
||||
|
@ -1459,7 +1495,8 @@ def send_invoice(
|
|||
:param max_tip_amount: The maximum accepted amount for tips in the smallest units of the currency
|
||||
:param suggested_tip_amounts: A JSON-serialized array of suggested amounts of tips in the smallest units of the currency.
|
||||
At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
|
||||
:param protect_content:
|
||||
:param protect_content: Protects the contents of the sent message from forwarding and saving
|
||||
:param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
|
||||
:return:
|
||||
"""
|
||||
method_url = r'sendInvoice'
|
||||
|
@ -1577,7 +1614,7 @@ def answer_callback_query(token, callback_query_id, text=None, show_alert=None,
|
|||
|
||||
|
||||
def answer_inline_query(token, inline_query_id, results, cache_time=None, is_personal=None, next_offset=None,
|
||||
switch_pm_text=None, switch_pm_parameter=None):
|
||||
button=None):
|
||||
method_url = 'answerInlineQuery'
|
||||
payload = {'inline_query_id': inline_query_id, 'results': _convert_list_json_serializable(results)}
|
||||
if cache_time is not None:
|
||||
|
@ -1586,10 +1623,8 @@ def answer_inline_query(token, inline_query_id, results, cache_time=None, is_per
|
|||
payload['is_personal'] = is_personal
|
||||
if next_offset is not None:
|
||||
payload['next_offset'] = next_offset
|
||||
if switch_pm_text:
|
||||
payload['switch_pm_text'] = switch_pm_text
|
||||
if switch_pm_parameter:
|
||||
payload['switch_pm_parameter'] = switch_pm_parameter
|
||||
if button is not None:
|
||||
payload["button"] = button.to_json()
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
|
@ -1599,58 +1634,86 @@ def get_sticker_set(token, name):
|
|||
|
||||
def get_custom_emoji_stickers(token, custom_emoji_ids):
|
||||
method_url = r'getCustomEmojiStickers'
|
||||
return _make_request(token, method_url, params={'custom_emoji_ids': custom_emoji_ids})
|
||||
return _make_request(token, method_url, params={'custom_emoji_ids': json.dumps(custom_emoji_ids)})
|
||||
|
||||
def set_sticker_keywords(token, sticker, keywords=None):
|
||||
method_url = 'setStickerKeywords'
|
||||
payload = {'sticker': sticker}
|
||||
if keywords:
|
||||
payload['keywords'] = json.dumps(keywords)
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
def set_sticker_mask_position(token, sticker, mask_position=None):
|
||||
method_url = 'setStickerMaskPosition'
|
||||
payload = {'sticker': sticker}
|
||||
if mask_position:
|
||||
payload['mask_position'] = mask_position.to_json()
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
def upload_sticker_file(token, user_id, png_sticker):
|
||||
def upload_sticker_file(token, user_id, sticker, sticker_format):
|
||||
method_url = 'uploadStickerFile'
|
||||
payload = {'user_id': user_id}
|
||||
files = {'png_sticker': png_sticker}
|
||||
payload = {'user_id': user_id, 'sticker_format': sticker_format}
|
||||
files = {'sticker': sticker}
|
||||
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
def set_custom_emoji_sticker_set_thumbnail(token, name, custom_emoji_id=None):
|
||||
method_url = 'setCustomEmojiStickerSetThumbnail'
|
||||
payload = {'name': name}
|
||||
if custom_emoji_id is not None:
|
||||
payload['custom_emoji_id'] = custom_emoji_id
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
def set_sticker_set_title(token, name, title):
|
||||
method_url = 'setStickerSetTitle'
|
||||
payload = {'name': name, 'title': title}
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
def delete_sticker_set(token, name):
|
||||
method_url = 'deleteStickerSet'
|
||||
payload = {'name': name}
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
def set_sticker_emoji_list(token, sticker, emoji_list):
|
||||
method_url = 'setStickerEmojiList'
|
||||
payload = {'sticker': sticker, 'emoji_list': json.dumps(emoji_list)}
|
||||
return _make_request(token, method_url, params=payload, method='post')
|
||||
|
||||
def create_new_sticker_set(
|
||||
token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
||||
mask_position=None, webm_sticker=None, sticker_type=None):
|
||||
token, user_id, name, title, stickers, sticker_format, sticker_type=None, needs_repainting=None):
|
||||
method_url = 'createNewStickerSet'
|
||||
payload = {'user_id': user_id, 'name': name, 'title': title, 'emojis': emojis}
|
||||
if png_sticker:
|
||||
stype = 'png_sticker'
|
||||
elif webm_sticker:
|
||||
stype = 'webm_sticker'
|
||||
else:
|
||||
stype = 'tgs_sticker'
|
||||
sticker = png_sticker or tgs_sticker or webm_sticker
|
||||
files = None
|
||||
if not util.is_string(sticker):
|
||||
files = {stype: sticker}
|
||||
else:
|
||||
payload[stype] = sticker
|
||||
if mask_position:
|
||||
payload['mask_position'] = mask_position.to_json()
|
||||
if webm_sticker:
|
||||
payload['webm_sticker'] = webm_sticker
|
||||
payload = {'user_id': user_id, 'name': name, 'title': title, 'sticker_format': sticker_format}
|
||||
if sticker_type:
|
||||
payload['sticker_type'] = sticker_type
|
||||
if needs_repainting:
|
||||
payload['needs_repainting'] = needs_repainting
|
||||
|
||||
files = {}
|
||||
lst = []
|
||||
|
||||
for sticker in stickers:
|
||||
json_dict, file = sticker.convert_input_sticker()
|
||||
json_dict = sticker.to_dict()
|
||||
|
||||
if file:
|
||||
list_keys = list(file.keys())
|
||||
files[list_keys[0]] = file[list_keys[0]]
|
||||
lst.append(json_dict)
|
||||
|
||||
payload['stickers'] = json.dumps(lst)
|
||||
|
||||
|
||||
|
||||
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
def add_sticker_to_set(token, user_id, name, emojis, png_sticker, tgs_sticker, mask_position, webm_sticker):
|
||||
def add_sticker_to_set(token, user_id, name, sticker):
|
||||
method_url = 'addStickerToSet'
|
||||
payload = {'user_id': user_id, 'name': name, 'emojis': emojis}
|
||||
if png_sticker:
|
||||
stype = 'png_sticker'
|
||||
elif webm_sticker:
|
||||
stype = 'webm_sticker'
|
||||
else:
|
||||
stype = 'tgs_sticker'
|
||||
sticker = png_sticker or tgs_sticker or webm_sticker
|
||||
files = None
|
||||
if not util.is_string(sticker):
|
||||
files = {stype: sticker}
|
||||
else:
|
||||
payload[stype] = sticker
|
||||
if mask_position:
|
||||
payload['mask_position'] = mask_position.to_json()
|
||||
json_dict, files = sticker.convert_input_sticker()
|
||||
payload = {'user_id': user_id, 'name': name, 'sticker': json_dict}
|
||||
|
||||
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import telebot.types
|
|||
from telebot.asyncio_storage import StateMemoryStorage, StatePickleStorage, StateStorageBase
|
||||
from telebot.asyncio_handler_backends import BaseMiddleware, CancelUpdate, SkipHandler, State, ContinueHandling
|
||||
|
||||
from inspect import signature
|
||||
from inspect import signature, iscoroutinefunction
|
||||
|
||||
from telebot import util, types, asyncio_helper
|
||||
import asyncio
|
||||
|
@ -139,7 +139,7 @@ class AsyncTeleBot:
|
|||
coloredlogs.install(logger=logger, level=logger.level)
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
'Install colorredlogs module to use colorful_logs option.'
|
||||
'Install coloredlogs module to use colorful_logs option.'
|
||||
)
|
||||
|
||||
# properties
|
||||
|
@ -209,8 +209,8 @@ class AsyncTeleBot:
|
|||
:param allowed_updates: Array of string. List the types of updates you want your bot to receive.
|
||||
:type allowed_updates: :obj:`list`, optional
|
||||
|
||||
:param long_polling_timeout: Timeout in seconds for long polling.
|
||||
:type long_polling_timeout: :obj:`int`, optional
|
||||
:param request_timeout: Timeout in seconds for request.
|
||||
:type request_timeout: :obj:`int`, optional
|
||||
|
||||
:return: An Array of Update objects is returned.
|
||||
:rtype: :obj:`list` of :class:`telebot.types.Update`
|
||||
|
@ -294,7 +294,7 @@ class AsyncTeleBot:
|
|||
:return:
|
||||
"""
|
||||
if none_stop is not None:
|
||||
logger.warning("polling: none_stop parameter is deprecated. Use non_stop instead.")
|
||||
logger.warning('The parameter "none_stop" is deprecated. Use "non_stop" instead.')
|
||||
non_stop = none_stop
|
||||
|
||||
if skip_pending:
|
||||
|
@ -511,7 +511,6 @@ class AsyncTeleBot:
|
|||
if not process_update: continue
|
||||
for i in signature(handler['function']).parameters:
|
||||
params.append(i)
|
||||
result = None
|
||||
if len(params) == 1:
|
||||
result = await handler['function'](message)
|
||||
elif "data" in params:
|
||||
|
@ -537,6 +536,7 @@ class AsyncTeleBot:
|
|||
if not isinstance(result, ContinueHandling):
|
||||
break
|
||||
except Exception as e:
|
||||
handler_error = e
|
||||
if self.exception_handler:
|
||||
self.exception_handler.handle(e)
|
||||
else:
|
||||
|
@ -837,6 +837,8 @@ class AsyncTeleBot:
|
|||
elif message_filter == 'chat_types':
|
||||
return message.chat.type in filter_value
|
||||
elif message_filter == 'func':
|
||||
if iscoroutinefunction(filter_value):
|
||||
return await filter_value(message)
|
||||
return filter_value(message)
|
||||
elif self.custom_filters and message_filter in self.custom_filters:
|
||||
return await self._check_filter(message_filter,filter_value,message)
|
||||
|
@ -2059,8 +2061,7 @@ class AsyncTeleBot:
|
|||
"""
|
||||
This class sets webhooks and listens to a given url and port.
|
||||
|
||||
:param listen: IP address to listen to. Defaults to
|
||||
0.0.0.0
|
||||
:param listen: IP address to listen to. Defaults to 0.0.0.0
|
||||
:param port: A port which will be used to listen to webhooks.
|
||||
:param url_path: Path to the webhook. Defaults to /token
|
||||
:param certificate: Path to the certificate file.
|
||||
|
@ -2072,6 +2073,8 @@ class AsyncTeleBot:
|
|||
:param drop_pending_updates: Pass True to drop all pending updates
|
||||
:param timeout: Integer. Request connection timeout
|
||||
:param secret_token: Secret token to be used to verify the webhook request.
|
||||
:param secret_token_length: Length of a secret token, defaults to 20
|
||||
:param debug: Debug mode, defaults to False
|
||||
:return:
|
||||
"""
|
||||
|
||||
|
@ -2079,12 +2082,9 @@ class AsyncTeleBot:
|
|||
if not secret_token:
|
||||
secret_token = ''.join(random.choices(string.ascii_uppercase + string.digits, k=secret_token_length))
|
||||
|
||||
|
||||
if not url_path:
|
||||
url_path = self.token + '/'
|
||||
if url_path[-1] != '/': url_path += '/'
|
||||
|
||||
|
||||
|
||||
protocol = "https" if certificate else "http"
|
||||
if not webhook_url:
|
||||
|
@ -2093,8 +2093,6 @@ class AsyncTeleBot:
|
|||
if certificate and certificate_key:
|
||||
ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
|
||||
ssl_ctx.load_cert_chain(certificate, certificate_key)
|
||||
else:
|
||||
ssl_ctx = None
|
||||
|
||||
# open certificate if it exists
|
||||
cert_file = open(certificate, 'rb') if certificate else None
|
||||
|
@ -2700,11 +2698,12 @@ class AsyncTeleBot:
|
|||
parse_mode: Optional[str]=None,
|
||||
disable_notification: Optional[bool]=None,
|
||||
timeout: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
protect_content: Optional[bool]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None) -> types.Message:
|
||||
"""
|
||||
Use this method to send audio files, if you want Telegram clients to display them in the music player.
|
||||
Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size,
|
||||
|
@ -2750,11 +2749,11 @@ class AsyncTeleBot:
|
|||
:param timeout: Timeout in seconds for the request.
|
||||
:type timeout: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
:param thumbnail: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320.
|
||||
Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file,
|
||||
so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>
|
||||
:type thumb: :obj:`str`
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
|
||||
:type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
|
||||
|
@ -2768,6 +2767,9 @@ class AsyncTeleBot:
|
|||
:param message_thread_id: Identifier of a message thread, in which the message will be sent
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:param thumb: Deprecated. Use thumbnail instead
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
|
@ -2776,10 +2778,14 @@ class AsyncTeleBot:
|
|||
protect_content = self.protect_content if (protect_content is None) else protect_content
|
||||
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('The parameter "thumb" is deprecated, use "thumbnail" instead')
|
||||
|
||||
return types.Message.de_json(
|
||||
await asyncio_helper.send_audio(
|
||||
self.token, chat_id, audio, caption, duration, performer, title, reply_to_message_id,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumb,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumbnail,
|
||||
caption_entities, allow_sending_without_reply, protect_content, message_thread_id))
|
||||
|
||||
async def send_voice(
|
||||
|
@ -2864,14 +2870,15 @@ class AsyncTeleBot:
|
|||
parse_mode: Optional[str]=None,
|
||||
disable_notification: Optional[bool]=None,
|
||||
timeout: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
visible_file_name: Optional[str]=None,
|
||||
disable_content_type_detection: Optional[bool]=None,
|
||||
data: Optional[Union[Any, str]]=None,
|
||||
protect_content: Optional[bool]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None) -> types.Message:
|
||||
"""
|
||||
Use this method to send general files.
|
||||
|
||||
|
@ -2904,8 +2911,8 @@ class AsyncTeleBot:
|
|||
:param timeout: Timeout in seconds for the request.
|
||||
:type timeout: :obj:`int`
|
||||
|
||||
:param thumb: InputFile or String : Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:param thumbnail: InputFile or String : Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode
|
||||
:type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity`
|
||||
|
@ -2928,6 +2935,9 @@ class AsyncTeleBot:
|
|||
:param message_thread_id: Identifier of a message thread, in which the message will be sent
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:param thumb: Deprecated. Use thumbnail instead
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
|
@ -2938,13 +2948,18 @@ class AsyncTeleBot:
|
|||
|
||||
if data and not(document):
|
||||
# function typo miss compatibility
|
||||
logger.warning('The parameter "data" is deprecated. Use "document" instead.')
|
||||
document = data
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')
|
||||
|
||||
return types.Message.de_json(
|
||||
await asyncio_helper.send_data(
|
||||
self.token, chat_id, document, 'document',
|
||||
reply_to_message_id = reply_to_message_id, reply_markup = reply_markup, parse_mode = parse_mode,
|
||||
disable_notification = disable_notification, timeout = timeout, caption = caption, thumb = thumb,
|
||||
disable_notification = disable_notification, timeout = timeout, caption = caption, thumbnail= thumbnail,
|
||||
caption_entities = caption_entities, allow_sending_without_reply = allow_sending_without_reply,
|
||||
disable_content_type_detection = disable_content_type_detection, visible_file_name = visible_file_name, protect_content = protect_content,
|
||||
message_thread_id = message_thread_id))
|
||||
|
@ -2958,7 +2973,8 @@ class AsyncTeleBot:
|
|||
allow_sending_without_reply: Optional[bool]=None,
|
||||
protect_content: Optional[bool]=None,
|
||||
data: Union[Any, str]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
emoji: Optional[str]=None) -> types.Message:
|
||||
"""
|
||||
Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers.
|
||||
On success, the sent Message is returned.
|
||||
|
@ -2998,6 +3014,9 @@ class AsyncTeleBot:
|
|||
:param message_thread_id: Identifier of a message thread, in which the message will be sent
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:param emoji: Emoji associated with the sticker; only for just uploaded stickers
|
||||
:type emoji: :obj:`str`
|
||||
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
|
@ -3007,7 +3026,7 @@ class AsyncTeleBot:
|
|||
|
||||
if data and not(sticker):
|
||||
# function typo miss compatibility
|
||||
logger.warning("send_sticker: data parameter is deprecated. Use sticker instead.")
|
||||
logger.warning('The parameter "data" is deprecated. Use "sticker" instead.')
|
||||
sticker = data
|
||||
|
||||
return types.Message.de_json(
|
||||
|
@ -3016,14 +3035,14 @@ class AsyncTeleBot:
|
|||
reply_to_message_id=reply_to_message_id, reply_markup=reply_markup,
|
||||
disable_notification=disable_notification, timeout=timeout,
|
||||
allow_sending_without_reply=allow_sending_without_reply, protect_content=protect_content,
|
||||
message_thread_id=message_thread_id))
|
||||
message_thread_id=message_thread_id, emoji=emoji))
|
||||
|
||||
async def send_video(
|
||||
self, chat_id: Union[int, str], video: Union[Any, str],
|
||||
duration: Optional[int]=None,
|
||||
width: Optional[int]=None,
|
||||
height: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption: Optional[str]=None,
|
||||
parse_mode: Optional[str]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
|
@ -3036,7 +3055,8 @@ class AsyncTeleBot:
|
|||
timeout: Optional[int]=None,
|
||||
data: Optional[Union[Any, str]]=None,
|
||||
message_thread_id: Optional[int]=None,
|
||||
has_spoiler: Optional[bool]=None) -> types.Message:
|
||||
has_spoiler: Optional[bool]=None,
|
||||
thumb: Optional[Union[Any, str]]=None) -> types.Message:
|
||||
"""
|
||||
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
|
||||
|
||||
|
@ -3057,8 +3077,8 @@ class AsyncTeleBot:
|
|||
:param height: Video height
|
||||
:type height: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:param thumbnail: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption: Video caption (may also be used when resending videos by file_id), 0-1024 characters after entities parsing
|
||||
:type caption: :obj:`str`
|
||||
|
@ -3101,6 +3121,9 @@ class AsyncTeleBot:
|
|||
:param has_spoiler: Pass True, if the video should be sent as a spoiler
|
||||
:type has_spoiler: :obj:`bool`
|
||||
|
||||
:param thumb: Deprecated. Use thumbnail instead
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
|
@ -3111,13 +3134,17 @@ class AsyncTeleBot:
|
|||
|
||||
if data and not(video):
|
||||
# function typo miss compatibility
|
||||
logger.warning("send_sticker: data parameter is deprecated. Use video instead.")
|
||||
logger.warning('The parameter "data" is deprecated. Use "video" instead.')
|
||||
video = data
|
||||
|
||||
if thumb and not(thumbnail):
|
||||
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')
|
||||
thumbnail = thumb
|
||||
|
||||
return types.Message.de_json(
|
||||
await asyncio_helper.send_video(
|
||||
self.token, chat_id, video, duration, caption, reply_to_message_id, reply_markup,
|
||||
parse_mode, supports_streaming, disable_notification, timeout, thumb, width, height,
|
||||
parse_mode, supports_streaming, disable_notification, timeout, thumbnail, width, height,
|
||||
caption_entities, allow_sending_without_reply, protect_content, message_thread_id, has_spoiler))
|
||||
|
||||
async def send_animation(
|
||||
|
@ -3125,7 +3152,7 @@ class AsyncTeleBot:
|
|||
duration: Optional[int]=None,
|
||||
width: Optional[int]=None,
|
||||
height: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
caption: Optional[str]=None,
|
||||
parse_mode: Optional[str]=None,
|
||||
caption_entities: Optional[List[types.MessageEntity]]=None,
|
||||
|
@ -3136,7 +3163,8 @@ class AsyncTeleBot:
|
|||
reply_markup: Optional[REPLY_MARKUP_TYPES]=None,
|
||||
timeout: Optional[int]=None,
|
||||
message_thread_id: Optional[int]=None,
|
||||
has_spoiler: Optional[bool]=None) -> types.Message:
|
||||
has_spoiler: Optional[bool]=None,
|
||||
thumb: Optional[Union[Any, str]]=None) -> types.Message:
|
||||
"""
|
||||
Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).
|
||||
On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.
|
||||
|
@ -3159,11 +3187,11 @@ class AsyncTeleBot:
|
|||
:param height: Animation height
|
||||
:type height: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
:param thumbnail: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320.
|
||||
Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file,
|
||||
so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param caption: Animation caption (may also be used when resending animation by file_id), 0-1024 characters after entities parsing
|
||||
:type caption: :obj:`str`
|
||||
|
@ -3200,6 +3228,9 @@ class AsyncTeleBot:
|
|||
:param has_spoiler: Pass True, if the animation should be sent as a spoiler
|
||||
:type has_spoiler: :obj:`bool`
|
||||
|
||||
:param thumb: Deprecated. Use thumbnail instead
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
|
@ -3208,10 +3239,14 @@ class AsyncTeleBot:
|
|||
protect_content = self.protect_content if (protect_content is None) else protect_content
|
||||
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')
|
||||
|
||||
return types.Message.de_json(
|
||||
await asyncio_helper.send_animation(
|
||||
self.token, chat_id, animation, duration, caption, reply_to_message_id,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumb,
|
||||
reply_markup, parse_mode, disable_notification, timeout, thumbnail,
|
||||
caption_entities, allow_sending_without_reply, width, height, protect_content, message_thread_id, has_spoiler))
|
||||
|
||||
async def send_video_note(
|
||||
|
@ -3222,10 +3257,11 @@ class AsyncTeleBot:
|
|||
reply_markup: Optional[REPLY_MARKUP_TYPES]=None,
|
||||
disable_notification: Optional[bool]=None,
|
||||
timeout: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None,
|
||||
thumbnail: Optional[Union[Any, str]]=None,
|
||||
allow_sending_without_reply: Optional[bool]=None,
|
||||
protect_content: Optional[bool]=None,
|
||||
message_thread_id: Optional[int]=None) -> types.Message:
|
||||
message_thread_id: Optional[int]=None,
|
||||
thumb: Optional[Union[Any, str]]=None) -> types.Message:
|
||||
"""
|
||||
As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long.
|
||||
Use this method to send video messages. On success, the sent Message is returned.
|
||||
|
@ -3259,11 +3295,11 @@ class AsyncTeleBot:
|
|||
:param timeout: Timeout in seconds for the request.
|
||||
:type timeout: :obj:`int`
|
||||
|
||||
:param thumb: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
:param thumbnail: Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side.
|
||||
The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320.
|
||||
Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file,
|
||||
so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:param allow_sending_without_reply: Pass True, if the message should be sent even if the specified replied-to message is not found
|
||||
:type allow_sending_without_reply: :obj:`bool`
|
||||
|
@ -3274,6 +3310,9 @@ class AsyncTeleBot:
|
|||
:param message_thread_id: Identifier of a message thread, in which the video note will be sent
|
||||
:type message_thread_id: :obj:`int`
|
||||
|
||||
:param thumb: Deprecated. Use thumbnail instead
|
||||
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`
|
||||
|
||||
:return: On success, the sent Message is returned.
|
||||
:rtype: :class:`telebot.types.Message`
|
||||
"""
|
||||
|
@ -3281,10 +3320,14 @@ class AsyncTeleBot:
|
|||
protect_content = self.protect_content if (protect_content is None) else protect_content
|
||||
allow_sending_without_reply = self.allow_sending_without_reply if (allow_sending_without_reply is None) else allow_sending_without_reply
|
||||
|
||||
if thumb is not None and thumbnail is None:
|
||||
thumbnail = thumb
|
||||
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')
|
||||
|
||||
return types.Message.de_json(
|
||||
await asyncio_helper.send_video_note(
|
||||
self.token, chat_id, data, duration, length, reply_to_message_id, reply_markup,
|
||||
disable_notification, timeout, thumb, allow_sending_without_reply, protect_content, message_thread_id))
|
||||
disable_notification, timeout, thumbnail, allow_sending_without_reply, protect_content, message_thread_id))
|
||||
|
||||
async def send_media_group(
|
||||
self, chat_id: Union[int, str],
|
||||
|
@ -3775,7 +3818,9 @@ class AsyncTeleBot:
|
|||
can_add_web_page_previews: Optional[bool]=None,
|
||||
can_change_info: Optional[bool]=None,
|
||||
can_invite_users: Optional[bool]=None,
|
||||
can_pin_messages: Optional[bool]=None) -> bool:
|
||||
can_pin_messages: Optional[bool]=None,
|
||||
permissions: Optional[types.ChatPermissions]=None,
|
||||
use_independent_chat_permissions: Optional[bool]=None) -> bool:
|
||||
"""
|
||||
Use this method to restrict a user in a supergroup.
|
||||
The bot must be an administrator in the supergroup for this to work and must have
|
||||
|
@ -3783,6 +3828,9 @@ class AsyncTeleBot:
|
|||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#restrictchatmember
|
||||
|
||||
.. warning::
|
||||
Individual parameters are deprecated and will be removed, use 'permissions' instead
|
||||
|
||||
:param chat_id: Unique identifier for the target group or username of the target supergroup
|
||||
or channel (in the format @channelusername)
|
||||
:type chat_id: :obj:`int` or :obj:`str`
|
||||
|
@ -3823,15 +3871,33 @@ class AsyncTeleBot:
|
|||
:param can_pin_messages: Pass True, if the user is allowed to pin messages. Ignored in public supergroups
|
||||
:type can_pin_messages: :obj:`bool`
|
||||
|
||||
:param use_independent_chat_permissions: Pass True if chat permissions are set independently. Otherwise,
|
||||
the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages,
|
||||
can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and
|
||||
can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
|
||||
:type use_independent_chat_permissions: :obj:`bool`
|
||||
|
||||
:param permissions: Pass ChatPermissions object to set all permissions at once. Use this parameter instead of
|
||||
passing all boolean parameters to avoid backward compatibility problems in future.
|
||||
:type permissions: :obj:`types.ChatPermissions`
|
||||
|
||||
:return: True on success
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
if permissions is None:
|
||||
permissions = types.ChatPermissions(
|
||||
can_send_messages=can_send_messages,
|
||||
can_send_media_messages=can_send_media_messages,
|
||||
can_send_polls=can_send_polls,
|
||||
can_send_other_messages=can_send_other_messages,
|
||||
can_add_web_page_previews=can_add_web_page_previews,
|
||||
can_change_info=can_change_info,
|
||||
can_invite_users=can_invite_users,
|
||||
can_pin_messages=can_pin_messages
|
||||
)
|
||||
logger.warning('The parameters "can_..." are deprecated, use "permissions" instead.')
|
||||
return await asyncio_helper.restrict_chat_member(
|
||||
self.token, chat_id, user_id, until_date,
|
||||
can_send_messages, can_send_media_messages,
|
||||
can_send_polls, can_send_other_messages,
|
||||
can_add_web_page_previews, can_change_info,
|
||||
can_invite_users, can_pin_messages)
|
||||
self.token, chat_id, user_id, permissions, until_date, use_independent_chat_permissions)
|
||||
|
||||
async def promote_chat_member(
|
||||
self, chat_id: Union[int, str], user_id: int,
|
||||
|
@ -3913,7 +3979,7 @@ class AsyncTeleBot:
|
|||
"""
|
||||
|
||||
if can_manage_voice_chats is not None:
|
||||
logger.warning("promote_chat_member: can_manage_voice_chats parameter is deprecated. Use can_manage_video_chats instead.")
|
||||
logger.warning('The parameter "can_manage_voice_chats" is deprecated. Use "can_manage_video_chats" instead.')
|
||||
if can_manage_video_chats is None:
|
||||
can_manage_video_chats = can_manage_voice_chats
|
||||
|
||||
|
@ -3991,7 +4057,8 @@ class AsyncTeleBot:
|
|||
return await asyncio_helper.unban_chat_sender_chat(self.token, chat_id, sender_chat_id)
|
||||
|
||||
async def set_chat_permissions(
|
||||
self, chat_id: Union[int, str], permissions: types.ChatPermissions) -> bool:
|
||||
self, chat_id: Union[int, str], permissions: types.ChatPermissions,
|
||||
use_independent_chat_permissions: Optional[bool]=None) -> bool:
|
||||
"""
|
||||
Use this method to set default chat permissions for all members.
|
||||
The bot must be an administrator in the group or a supergroup for this to work
|
||||
|
@ -4006,10 +4073,16 @@ class AsyncTeleBot:
|
|||
:param permissions: New default chat permissions
|
||||
:type permissions: :class:`telebot.types..ChatPermissions`
|
||||
|
||||
:param use_independent_chat_permissions: Pass True if chat permissions are set independently. Otherwise,
|
||||
the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages,
|
||||
can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and
|
||||
can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
|
||||
:type use_independent_chat_permissions: :obj:`bool`
|
||||
|
||||
:return: True on success
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.set_chat_permissions(self.token, chat_id, permissions)
|
||||
return await asyncio_helper.set_chat_permissions(self.token, chat_id, permissions, use_independent_chat_permissions)
|
||||
|
||||
async def create_chat_invite_link(
|
||||
self, chat_id: Union[int, str],
|
||||
|
@ -4084,7 +4157,7 @@ class AsyncTeleBot:
|
|||
:rtype: :class:`telebot.types.ChatInviteLink`
|
||||
"""
|
||||
return types.ChatInviteLink.de_json(
|
||||
await asyncio_helper.edit_chat_invite_link(self.token, chat_id, name, invite_link, expire_date, member_limit, creates_join_request)
|
||||
await asyncio_helper.edit_chat_invite_link(self.token, chat_id, invite_link, name, expire_date, member_limit, creates_join_request)
|
||||
)
|
||||
|
||||
async def revoke_chat_invite_link(
|
||||
|
@ -4206,6 +4279,68 @@ class AsyncTeleBot:
|
|||
"""
|
||||
return await asyncio_helper.delete_chat_photo(self.token, chat_id)
|
||||
|
||||
async def set_my_description(self, description: Optional[str]=None, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to change the bot's description, which is shown in
|
||||
the chat with the bot if the chat is empty.
|
||||
Returns True on success.
|
||||
|
||||
:param description: New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.
|
||||
:type description: :obj:`str`
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for
|
||||
whose language there is no dedicated description.
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: True on success.
|
||||
"""
|
||||
|
||||
return await asyncio_helper.set_my_description(self.token, description, language_code)
|
||||
|
||||
async def get_my_description(self, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to get the current bot description for the given user language.
|
||||
Returns BotDescription on success.
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code or an empty string
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: :class:`telebot.types.BotDescription`
|
||||
"""
|
||||
result = await asyncio_helper.get_my_description(self.token, language_code)
|
||||
return types.BotDescription.de_json(result)
|
||||
|
||||
async def set_my_short_description(self, short_description:Optional[str]=None, language_code:Optional[str]=None):
|
||||
"""
|
||||
Use this method to change the bot's short description, which is shown on the bot's profile page and
|
||||
is sent together with the link when users share the bot.
|
||||
Returns True on success.
|
||||
|
||||
:param short_description: New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language.
|
||||
:type short_description: :obj:`str`
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code.
|
||||
If empty, the short description will be applied to all users for whose language there is no dedicated short description.
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: True on success.
|
||||
"""
|
||||
|
||||
return await asyncio_helper.set_my_short_description(self.token, short_description, language_code)
|
||||
|
||||
async def get_my_short_description(self, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to get the current bot short description for the given user language.
|
||||
Returns BotShortDescription on success.
|
||||
|
||||
:param language_code: A two-letter ISO 639-1 language code or an empty string
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: :class:`telebot.types.BotShortDescription`
|
||||
"""
|
||||
result = await asyncio_helper.get_my_short_description(self.token, language_code)
|
||||
return types.BotShortDescription.de_json(result)
|
||||
|
||||
async def get_my_commands(self, scope: Optional[types.BotCommandScope],
|
||||
language_code: Optional[str]) -> List[types.BotCommand]:
|
||||
"""
|
||||
|
@ -4229,6 +4364,40 @@ class AsyncTeleBot:
|
|||
result = await asyncio_helper.get_my_commands(self.token, scope, language_code)
|
||||
return [types.BotCommand.de_json(cmd) for cmd in result]
|
||||
|
||||
async def set_my_name(self, name: Optional[str]=None, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to change the bot's name. Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#setmyname
|
||||
|
||||
:param name: Optional. New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language.
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param language_code: Optional. A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose
|
||||
language there is no dedicated name.
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: True on success.
|
||||
"""
|
||||
|
||||
return await asyncio_helper.set_my_name(self.token, name, language_code)
|
||||
|
||||
async def get_my_name(self, language_code: Optional[str]=None):
|
||||
"""
|
||||
Use this method to get the current bot name for the given user language.
|
||||
Returns BotName on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#getmyname
|
||||
|
||||
:param language_code: Optional. A two-letter ISO 639-1 language code or an empty string
|
||||
:type language_code: :obj:`str`
|
||||
|
||||
:return: :class:`telebot.types.BotName`
|
||||
"""
|
||||
|
||||
result = await asyncio_helper.get_my_name(self.token, language_code)
|
||||
return types.BotName.de_json(result)
|
||||
|
||||
async def set_chat_menu_button(self, chat_id: Union[int, str]=None,
|
||||
menu_button: types.MenuButton=None) -> bool:
|
||||
"""
|
||||
|
@ -5061,7 +5230,7 @@ class AsyncTeleBot:
|
|||
|
||||
async def stop_poll(
|
||||
self, chat_id: Union[int, str], message_id: int,
|
||||
reply_markup: Optional[REPLY_MARKUP_TYPES]=None) -> types.Poll:
|
||||
reply_markup: Optional[types.InlineKeyboardMarkup]=None) -> types.Poll:
|
||||
"""
|
||||
Use this method to stop a poll which was sent by the bot. On success, the stopped Poll is returned.
|
||||
|
||||
|
@ -5074,7 +5243,7 @@ class AsyncTeleBot:
|
|||
:type message_id: :obj:`int`
|
||||
|
||||
:param reply_markup: A JSON-serialized object for a new message markup.
|
||||
:type reply_markup: :obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`
|
||||
:type reply_markup: :obj:`InlineKeyboardMarkup`
|
||||
|
||||
:return: On success, the stopped Poll is returned.
|
||||
:rtype: :obj:`types.Poll`
|
||||
|
@ -5205,7 +5374,8 @@ class AsyncTeleBot:
|
|||
is_personal: Optional[bool]=None,
|
||||
next_offset: Optional[str]=None,
|
||||
switch_pm_text: Optional[str]=None,
|
||||
switch_pm_parameter: Optional[str]=None) -> bool:
|
||||
switch_pm_parameter: Optional[str]=None,
|
||||
button: Optional[types.InlineQueryResultsButton]=None) -> bool:
|
||||
"""
|
||||
Use this method to send answers to an inline query. On success, True is returned.
|
||||
No more than 50 results per query are allowed.
|
||||
|
@ -5241,11 +5411,18 @@ class AsyncTeleBot:
|
|||
:param switch_pm_text: Parameter for the start message sent to the bot when user presses the switch button
|
||||
:type switch_pm_text: :obj:`str`
|
||||
|
||||
:param button: A JSON-serialized object describing a button to be shown above inline query results
|
||||
:type button: :obj:`types.InlineQueryResultsButton`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
if not button and (switch_pm_text or switch_pm_parameter):
|
||||
logger.warning("switch_pm_text and switch_pm_parameter are deprecated for answer_inline_query. Use button instead.")
|
||||
button = types.InlineQueryResultsButton(text=switch_pm_text, start_parameter=switch_pm_parameter)
|
||||
return await asyncio_helper.answer_inline_query(self.token, inline_query_id, results, cache_time, is_personal, next_offset,
|
||||
switch_pm_text, switch_pm_parameter)
|
||||
button)
|
||||
|
||||
async def answer_callback_query(
|
||||
self, callback_query_id: int,
|
||||
|
@ -5278,8 +5455,29 @@ class AsyncTeleBot:
|
|||
"""
|
||||
return await asyncio_helper.answer_callback_query(self.token, callback_query_id, text, show_alert, url, cache_time)
|
||||
|
||||
async def set_sticker_set_thumb(
|
||||
self, name: str, user_id: int, thumb: Union[Any, str]=None):
|
||||
async def set_sticker_set_thumbnail(self, name: str, user_id: int, thumbnail: Union[Any, str]=None):
|
||||
"""
|
||||
Use this method to set the thumbnail of a sticker set.
|
||||
Animated thumbnails can be set for animated sticker sets only. Returns True on success.
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#setstickersetthumb
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param user_id: User identifier
|
||||
:type user_id: :obj:`int`
|
||||
|
||||
:param thumbnail: A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files ». Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail.
|
||||
:type thumbnail: :obj:`filelike object`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.set_sticker_set_thumbnail(self.token, name, user_id, thumbnail)
|
||||
|
||||
@util.deprecated(deprecation_text="Use set_sticker_set_thumbnail instead")
|
||||
async def set_sticker_set_thumb(self, name: str, user_id: int, thumb: Union[Any, str]=None):
|
||||
"""
|
||||
Use this method to set the thumbnail of a sticker set.
|
||||
Animated thumbnails can be set for animated sticker sets only. Returns True on success.
|
||||
|
@ -5298,7 +5496,8 @@ class AsyncTeleBot:
|
|||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.set_sticker_set_thumb(self.token, name, user_id, thumb)
|
||||
# deprecated
|
||||
return await self.set_sticker_set_thumbnail(name, user_id, thumb)
|
||||
|
||||
async def get_sticker_set(self, name: str) -> types.StickerSet:
|
||||
"""
|
||||
|
@ -5314,6 +5513,40 @@ class AsyncTeleBot:
|
|||
"""
|
||||
result = await asyncio_helper.get_sticker_set(self.token, name)
|
||||
return types.StickerSet.de_json(result)
|
||||
|
||||
async def set_sticker_keywords(self, sticker: str, keywords: List[str]=None) -> bool:
|
||||
"""
|
||||
Use this method to change search keywords assigned to a regular or custom emoji sticker.
|
||||
The sticker must belong to a sticker set created by the bot.
|
||||
Returns True on success.
|
||||
|
||||
:param sticker: File identifier of the sticker.
|
||||
:type sticker: :obj:`str`
|
||||
|
||||
:param keywords: A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters
|
||||
:type keywords: :obj:`list` of :obj:`str`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.set_sticker_keywords(self.token, sticker, keywords)
|
||||
|
||||
async def set_sticker_mask_position(self, sticker: str, mask_position: types.MaskPosition=None) -> bool:
|
||||
"""
|
||||
Use this method to change the mask position of a mask sticker.
|
||||
The sticker must belong to a sticker set that was created by the bot.
|
||||
Returns True on success.
|
||||
|
||||
:param sticker: File identifier of the sticker.
|
||||
:type sticker: :obj:`str`
|
||||
|
||||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces.
|
||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.set_sticker_mask_position(self.token, sticker, mask_position)
|
||||
|
||||
async def get_custom_emoji_stickers(self, custom_emoji_ids: List[str]) -> List[types.Sticker]:
|
||||
"""
|
||||
|
@ -5329,7 +5562,7 @@ class AsyncTeleBot:
|
|||
result = await asyncio_helper.get_custom_emoji_stickers(self.token, custom_emoji_ids)
|
||||
return [types.Sticker.de_json(sticker) for sticker in result]
|
||||
|
||||
async def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]) -> types.File:
|
||||
async def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]=None, sticker: Optional[types.InputFile]=None, sticker_format: Optional[str]=None) -> types.File:
|
||||
"""
|
||||
Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet
|
||||
methods (can be used multiple times). Returns the uploaded File on success.
|
||||
|
@ -5339,25 +5572,105 @@ class AsyncTeleBot:
|
|||
:param user_id: User identifier of sticker set owner
|
||||
:type user_id: :obj:`int`
|
||||
|
||||
:param png_sticker: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
|
||||
:param png_sticker: DEPRECATED: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
|
||||
and either width or height must be exactly 512px.
|
||||
:type png_sticker: :obj:`filelike object`
|
||||
|
||||
:param sticker: A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format.
|
||||
See https://core.telegram.org/stickers for technical requirements. More information on Sending Files »
|
||||
:type sticker: :class:`telebot.types.InputFile`
|
||||
|
||||
:param sticker_format: One of "static", "animated", "video".
|
||||
:type sticker_format: :obj:`str`
|
||||
|
||||
:return: On success, the sent file is returned.
|
||||
:rtype: :class:`telebot.types.File`
|
||||
"""
|
||||
result = await asyncio_helper.upload_sticker_file(self.token, user_id, png_sticker)
|
||||
if png_sticker:
|
||||
logger.warning('The parameter "png_sticker" is deprecated. Use "sticker" instead.')
|
||||
sticker = png_sticker
|
||||
sticker_format = "static"
|
||||
|
||||
result = await asyncio_helper.upload_sticker_file(self.token, user_id, sticker, sticker_format)
|
||||
return types.File.de_json(result)
|
||||
|
||||
async def set_custom_emoji_sticker_set_thumbnail(self, name: str, custom_emoji_id: Optional[str]=None) -> bool:
|
||||
"""
|
||||
Use this method to set the thumbnail of a custom emoji sticker set.
|
||||
Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param custom_emoji_id: Custom emoji identifier of a sticker from the sticker set; pass an empty string to drop the thumbnail and use the first sticker as the thumbnail.
|
||||
:type custom_emoji_id: :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return await asyncio_helper.set_custom_emoji_sticker_set_thumbnail(self.token, name, custom_emoji_id)
|
||||
|
||||
async def set_sticker_set_title(self, name: str, title: str) -> bool:
|
||||
"""
|
||||
Use this method to set the title of a created sticker set.
|
||||
Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param title: New sticker set title
|
||||
:type title: :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
return await asyncio_helper.set_sticker_set_title(self.token, name, title)
|
||||
|
||||
async def delete_sticker_set(self, name:str) -> bool:
|
||||
"""
|
||||
Use this method to delete a sticker set. Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
return await asyncio_helper.delete_sticker_set(self.token, name)
|
||||
|
||||
|
||||
async def set_sticker_emoji_list(self, name: str, emoji_list: List[str]) -> bool:
|
||||
"""
|
||||
Use this method to set the emoji list of a sticker set.
|
||||
Returns True on success.
|
||||
|
||||
:param name: Sticker set name
|
||||
:type name: :obj:`str`
|
||||
|
||||
:param emoji_list: List of emojis
|
||||
:type emoji_list: :obj:`list` of :obj:`str`
|
||||
|
||||
:return: Returns True on success.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
|
||||
return await asyncio_helper.set_sticker_emoji_list(self.token, name, emoji_list)
|
||||
|
||||
|
||||
async def create_new_sticker_set(
|
||||
self, user_id: int, name: str, title: str,
|
||||
emojis: str,
|
||||
emojis: Optional[List[str]]=None,
|
||||
png_sticker: Union[Any, str]=None,
|
||||
tgs_sticker: Union[Any, str]=None,
|
||||
webm_sticker: Union[Any, str]=None,
|
||||
contains_masks: Optional[bool]=None,
|
||||
sticker_type: Optional[str]=None,
|
||||
mask_position: Optional[types.MaskPosition]=None) -> bool:
|
||||
mask_position: Optional[types.MaskPosition]=None,
|
||||
needs_repainting: Optional[bool]=None,
|
||||
stickers: List[types.InputSticker]=None,
|
||||
sticker_format: Optional[str]=None) -> bool:
|
||||
"""
|
||||
Use this method to create new sticker set owned by a user.
|
||||
The bot will be able to edit the created sticker set.
|
||||
|
@ -5365,6 +5678,9 @@ class AsyncTeleBot:
|
|||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#createnewstickerset
|
||||
|
||||
.. note::
|
||||
Fields *_sticker are deprecated, pass a list of stickers to stickers parameter instead.
|
||||
|
||||
:param user_id: User identifier of created sticker set owner
|
||||
:type user_id: :obj:`int`
|
||||
|
||||
|
@ -5394,37 +5710,67 @@ class AsyncTeleBot:
|
|||
use sticker_type instead.
|
||||
:type contains_masks: :obj:`bool`
|
||||
|
||||
:param sticker_type: Optional, Type of stickers in the set, pass “regular” or “mask”. Custom emoji sticker sets can't be created
|
||||
via the Bot API at the moment. By default, a regular sticker set is created.
|
||||
:param sticker_type: Type of stickers in the set, pass “regular”, “mask”, or “custom_emoji”. By default, a regular sticker set is created.
|
||||
:type sticker_type: :obj:`str`
|
||||
|
||||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces
|
||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||
|
||||
:param needs_repainting: Pass True if stickers in the sticker set must be repainted to the color of text when used in messages,
|
||||
the accent color if used as emoji status, white on chat photos, or another appropriate color based on context;
|
||||
for custom emoji sticker sets only
|
||||
:type needs_repainting: :obj:`bool`
|
||||
|
||||
:param stickers: List of stickers to be added to the set
|
||||
:type stickers: :obj:`list` of :class:`telebot.types.InputSticker`
|
||||
|
||||
:param sticker_format: Format of stickers in the set, must be one of “static”, “animated”, “video”
|
||||
:type sticker_format: :obj:`str`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
if tgs_sticker:
|
||||
sticker_format = 'animated'
|
||||
elif webm_sticker:
|
||||
sticker_format = 'video'
|
||||
elif png_sticker:
|
||||
sticker_format = 'static'
|
||||
|
||||
if contains_masks is not None:
|
||||
logger.warning('The parameter "contains_masks" is deprecated, use "sticker_type" instead')
|
||||
if sticker_type is None:
|
||||
sticker_type = 'mask' if contains_masks else 'regular'
|
||||
|
||||
if stickers is None:
|
||||
stickers = png_sticker or tgs_sticker or webm_sticker
|
||||
if stickers is None:
|
||||
raise ValueError('You must pass at least one sticker')
|
||||
stickers = [types.InputSticker(sticker=stickers, emoji_list=emojis, mask_position=mask_position)]
|
||||
|
||||
|
||||
|
||||
return await asyncio_helper.create_new_sticker_set(
|
||||
self.token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
||||
mask_position, webm_sticker, sticker_type)
|
||||
self.token, user_id, name, title, stickers, sticker_format, sticker_type, needs_repainting)
|
||||
|
||||
|
||||
async def add_sticker_to_set(
|
||||
self, user_id: int, name: str, emojis: str,
|
||||
self, user_id: int, name: str, emojis: Union[List[str], str]=None,
|
||||
png_sticker: Optional[Union[Any, str]]=None,
|
||||
tgs_sticker: Optional[Union[Any, str]]=None,
|
||||
webm_sticker: Optional[Union[Any, str]]=None,
|
||||
mask_position: Optional[types.MaskPosition]=None) -> bool:
|
||||
mask_position: Optional[types.MaskPosition]=None,
|
||||
sticker: Optional[List[types.InputSticker]]=None) -> bool:
|
||||
"""
|
||||
Use this method to add a new sticker to a set created by the bot.
|
||||
It's required to pass `png_sticker` or `tgs_sticker`.
|
||||
Use this method to add a new sticker to a set created by the bot.
|
||||
The format of the added sticker must match the format of the other stickers in the set.
|
||||
Emoji sticker sets can have up to 200 stickers. Animated and video sticker sets can have up to 50 stickers.
|
||||
Static sticker sets can have up to 120 stickers.
|
||||
Returns True on success.
|
||||
|
||||
.. note::
|
||||
**_sticker, mask_position, emojis parameters are deprecated, use stickers instead
|
||||
|
||||
Telegram documentation: https://core.telegram.org/bots/api#addstickertoset
|
||||
|
||||
:param user_id: User identifier of created sticker set owner
|
||||
|
@ -5450,11 +5796,26 @@ class AsyncTeleBot:
|
|||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces
|
||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||
|
||||
:param sticker: A JSON-serialized list of 1-50 initial stickers to be added to the sticker set
|
||||
:type sticker: :obj:`list` of :class:`telebot.types.InputSticker`
|
||||
|
||||
:return: On success, True is returned.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
# split emojis if string
|
||||
if isinstance(emojis, str):
|
||||
emojis = list(emojis)
|
||||
# Replaced the parameters png_sticker, tgs_sticker, webm_sticker, emojis and mask_position
|
||||
if sticker is None:
|
||||
old_sticker = png_sticker or tgs_sticker or webm_sticker
|
||||
if old_sticker is not None:
|
||||
logger.warning('The parameters "..._sticker", "emojis" and "mask_position" are deprecated, use "sticker" instead')
|
||||
if not old_sticker:
|
||||
raise ValueError('You must pass at least one sticker.')
|
||||
sticker = types.InputSticker(old_sticker, emojis, mask_position)
|
||||
|
||||
return await asyncio_helper.add_sticker_to_set(
|
||||
self.token, user_id, name, emojis, png_sticker, tgs_sticker, mask_position, webm_sticker)
|
||||
self.token, user_id, name, sticker)
|
||||
|
||||
|
||||
async def set_sticker_position_in_set(self, sticker: str, position: int) -> bool:
|
||||
|
|
|
@ -74,12 +74,18 @@ class StatesGroup:
|
|||
my_state = State() # returns my_state:State string.
|
||||
"""
|
||||
def __init_subclass__(cls) -> None:
|
||||
|
||||
state_list = []
|
||||
for name, value in cls.__dict__.items():
|
||||
if not name.startswith('__') and not callable(value) and isinstance(value, State):
|
||||
# change value of that variable
|
||||
value.name = ':'.join((cls.__name__, name))
|
||||
value.group = cls
|
||||
state_list.append(value)
|
||||
cls._state_list = state_list
|
||||
|
||||
@property
|
||||
def state_list(self):
|
||||
return self._state_list
|
||||
|
||||
|
||||
class SkipHandler:
|
||||
|
|
|
@ -180,11 +180,13 @@ async def get_file_url(token, file_id):
|
|||
async def download_file(token, file_path):
|
||||
if FILE_URL is None:
|
||||
url = "https://api.telegram.org/file/bot{0}/{1}".format(token, file_path)
|
||||
else: url = FILE_URL.format(token, file_path)
|
||||
else:
|
||||
# noinspection PyUnresolvedReferences
|
||||
url = FILE_URL.format(token, file_path)
|
||||
session = await session_manager.get_session()
|
||||
async with session.get(url, proxy=proxy) as response:
|
||||
if response.status != 200:
|
||||
raise ApiHTTPException('Download file', result)
|
||||
raise ApiHTTPException('Download file', response)
|
||||
result = await response.read()
|
||||
|
||||
return result
|
||||
|
@ -243,11 +245,11 @@ async def get_updates(token, offset=None, limit=None,
|
|||
params['limit'] = limit
|
||||
if timeout:
|
||||
params['timeout'] = timeout
|
||||
if allowed_updates:
|
||||
params['allowed_updates'] = allowed_updates
|
||||
if allowed_updates is not None: # Empty lists should pass
|
||||
params['allowed_updates'] = json.dumps(allowed_updates)
|
||||
return await _process_request(token, method_name, params=params, request_timeout=request_timeout)
|
||||
|
||||
async def _check_result(method_name, result):
|
||||
async def _check_result(method_name, result: aiohttp.ClientResponse):
|
||||
"""
|
||||
Checks whether `result` is a valid API response.
|
||||
A result is considered invalid if:
|
||||
|
@ -263,7 +265,7 @@ async def _check_result(method_name, result):
|
|||
try:
|
||||
result_json = await result.json(encoding="utf-8")
|
||||
except:
|
||||
if result.status_code != 200:
|
||||
if result.status != 200:
|
||||
raise ApiHTTPException(method_name, result)
|
||||
else:
|
||||
raise ApiInvalidJSONException(method_name, result)
|
||||
|
@ -341,15 +343,15 @@ async def get_chat_member_count(token, chat_id):
|
|||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
|
||||
async def set_sticker_set_thumb(token, name, user_id, thumb):
|
||||
method_url = r'setStickerSetThumb'
|
||||
async def set_sticker_set_thumbnail(token, name, user_id, thumbnail):
|
||||
method_url = r'setStickerSetThumbnail'
|
||||
payload = {'name': name, 'user_id': user_id}
|
||||
files = {}
|
||||
if thumb:
|
||||
if not isinstance(thumb, str):
|
||||
files['thumb'] = thumb
|
||||
if thumbnail:
|
||||
if not isinstance(thumbnail, str):
|
||||
files['thumbnail'] = thumbnail
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumbnail
|
||||
return await _process_request(token, method_url, params=payload, files=files or None)
|
||||
|
||||
|
||||
|
@ -660,9 +662,9 @@ async def send_chat_action(token, chat_id, action, timeout=None, message_thread_
|
|||
|
||||
|
||||
async def send_video(token, chat_id, data, duration=None, caption=None, reply_to_message_id=None, reply_markup=None,
|
||||
parse_mode=None, supports_streaming=None, disable_notification=None, timeout=None,
|
||||
thumb=None, width=None, height=None, caption_entities=None, allow_sending_without_reply=None,
|
||||
protect_content=None, message_thread_id=None, has_spoiler=None):
|
||||
parse_mode=None, supports_streaming=None, disable_notification=None, timeout=None,
|
||||
thumbnail=None, width=None, height=None, caption_entities=None, allow_sending_without_reply=None,
|
||||
protect_content=None, message_thread_id=None, has_spoiler=None):
|
||||
method_url = r'sendVideo'
|
||||
payload = {'chat_id': chat_id}
|
||||
files = None
|
||||
|
@ -686,14 +688,14 @@ async def send_video(token, chat_id, data, duration=None, caption=None, reply_to
|
|||
payload['disable_notification'] = disable_notification
|
||||
if timeout:
|
||||
payload['timeout'] = timeout
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if thumbnail:
|
||||
if not util.is_string(thumbnail):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumbnail
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumbnail}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumbnail
|
||||
if width:
|
||||
payload['width'] = width
|
||||
if height:
|
||||
|
@ -713,7 +715,7 @@ async def send_video(token, chat_id, data, duration=None, caption=None, reply_to
|
|||
|
||||
async def send_animation(
|
||||
token, chat_id, data, duration=None, caption=None, reply_to_message_id=None, reply_markup=None,
|
||||
parse_mode=None, disable_notification=None, timeout=None, thumb=None, caption_entities=None,
|
||||
parse_mode=None, disable_notification=None, timeout=None, thumbnail=None, caption_entities=None,
|
||||
allow_sending_without_reply=None, width=None, height=None, protect_content=None, message_thread_id=None,
|
||||
has_spoiler=None):
|
||||
method_url = r'sendAnimation'
|
||||
|
@ -737,14 +739,14 @@ async def send_animation(
|
|||
payload['disable_notification'] = disable_notification
|
||||
if timeout:
|
||||
payload['timeout'] = timeout
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if thumbnail:
|
||||
if not util.is_string(thumbnail):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumbnail
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumbnail}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumbnail
|
||||
if caption_entities:
|
||||
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
|
||||
if allow_sending_without_reply is not None:
|
||||
|
@ -798,8 +800,8 @@ async def send_voice(token, chat_id, voice, caption=None, duration=None, reply_t
|
|||
|
||||
|
||||
async def send_video_note(token, chat_id, data, duration=None, length=None, reply_to_message_id=None, reply_markup=None,
|
||||
disable_notification=None, timeout=None, thumb=None, allow_sending_without_reply=None, protect_content=None,
|
||||
message_thread_id=None):
|
||||
disable_notification=None, timeout=None, thumbnail=None, allow_sending_without_reply=None, protect_content=None,
|
||||
message_thread_id=None):
|
||||
method_url = r'sendVideoNote'
|
||||
payload = {'chat_id': chat_id}
|
||||
files = None
|
||||
|
@ -821,14 +823,14 @@ async def send_video_note(token, chat_id, data, duration=None, length=None, repl
|
|||
payload['disable_notification'] = disable_notification
|
||||
if timeout:
|
||||
payload['timeout'] = timeout
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if thumbnail:
|
||||
if not util.is_string(thumbnail):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumbnail
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumbnail}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumbnail
|
||||
if allow_sending_without_reply is not None:
|
||||
payload['allow_sending_without_reply'] = allow_sending_without_reply
|
||||
if protect_content is not None:
|
||||
|
@ -839,8 +841,8 @@ async def send_video_note(token, chat_id, data, duration=None, length=None, repl
|
|||
|
||||
|
||||
async def send_audio(token, chat_id, audio, caption=None, duration=None, performer=None, title=None, reply_to_message_id=None,
|
||||
reply_markup=None, parse_mode=None, disable_notification=None, timeout=None, thumb=None,
|
||||
caption_entities=None, allow_sending_without_reply=None, protect_content=None, message_thread_id=None):
|
||||
reply_markup=None, parse_mode=None, disable_notification=None, timeout=None, thumbnail=None,
|
||||
caption_entities=None, allow_sending_without_reply=None, protect_content=None, message_thread_id=None):
|
||||
method_url = r'sendAudio'
|
||||
payload = {'chat_id': chat_id}
|
||||
files = None
|
||||
|
@ -866,14 +868,14 @@ async def send_audio(token, chat_id, audio, caption=None, duration=None, perform
|
|||
payload['disable_notification'] = disable_notification
|
||||
if timeout:
|
||||
payload['timeout'] = timeout
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if thumbnail:
|
||||
if not util.is_string(thumbnail):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumbnail
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumbnail}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumbnail
|
||||
if caption_entities:
|
||||
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
|
||||
if allow_sending_without_reply is not None:
|
||||
|
@ -886,9 +888,9 @@ async def send_audio(token, chat_id, audio, caption=None, duration=None, perform
|
|||
|
||||
|
||||
async def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None, parse_mode=None,
|
||||
disable_notification=None, timeout=None, caption=None, thumb=None, caption_entities=None,
|
||||
allow_sending_without_reply=None, disable_content_type_detection=None, visible_file_name=None, protect_content=None,
|
||||
message_thread_id=None):
|
||||
disable_notification=None, timeout=None, caption=None, thumbnail=None, caption_entities=None,
|
||||
allow_sending_without_reply=None, disable_content_type_detection=None, visible_file_name=None, protect_content=None,
|
||||
message_thread_id=None, emoji=None):
|
||||
method_url = await get_method_by_type(data_type)
|
||||
payload = {'chat_id': chat_id}
|
||||
files = None
|
||||
|
@ -911,14 +913,14 @@ async def send_data(token, chat_id, data, data_type, reply_to_message_id=None, r
|
|||
payload['timeout'] = timeout
|
||||
if caption:
|
||||
payload['caption'] = caption
|
||||
if thumb:
|
||||
if not util.is_string(thumb):
|
||||
if thumbnail:
|
||||
if not util.is_string(thumbnail):
|
||||
if files:
|
||||
files['thumb'] = thumb
|
||||
files['thumbnail'] = thumbnail
|
||||
else:
|
||||
files = {'thumb': thumb}
|
||||
files = {'thumbnail': thumbnail}
|
||||
else:
|
||||
payload['thumb'] = thumb
|
||||
payload['thumbnail'] = thumbnail
|
||||
if caption_entities:
|
||||
payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities))
|
||||
if allow_sending_without_reply is not None:
|
||||
|
@ -929,6 +931,8 @@ async def send_data(token, chat_id, data, data_type, reply_to_message_id=None, r
|
|||
payload['disable_content_type_detection'] = disable_content_type_detection
|
||||
if message_thread_id:
|
||||
payload['message_thread_id'] = message_thread_id
|
||||
if emoji:
|
||||
payload['emoji'] = emoji
|
||||
return await _process_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
|
@ -960,31 +964,13 @@ async def unban_chat_member(token, chat_id, user_id, only_if_banned):
|
|||
|
||||
|
||||
async def restrict_chat_member(
|
||||
token, chat_id, user_id, until_date=None,
|
||||
can_send_messages=None, can_send_media_messages=None,
|
||||
can_send_polls=None, can_send_other_messages=None,
|
||||
can_add_web_page_previews=None, can_change_info=None,
|
||||
can_invite_users=None, can_pin_messages=None):
|
||||
token, chat_id, user_id, permissions, until_date=None,
|
||||
use_independent_chat_permissions=None):
|
||||
method_url = 'restrictChatMember'
|
||||
permissions = {}
|
||||
if can_send_messages is not None:
|
||||
permissions['can_send_messages'] = can_send_messages
|
||||
if can_send_media_messages is not None:
|
||||
permissions['can_send_media_messages'] = can_send_media_messages
|
||||
if can_send_polls is not None:
|
||||
permissions['can_send_polls'] = can_send_polls
|
||||
if can_send_other_messages is not None:
|
||||
permissions['can_send_other_messages'] = can_send_other_messages
|
||||
if can_add_web_page_previews is not None:
|
||||
permissions['can_add_web_page_previews'] = can_add_web_page_previews
|
||||
if can_change_info is not None:
|
||||
permissions['can_change_info'] = can_change_info
|
||||
if can_invite_users is not None:
|
||||
permissions['can_invite_users'] = can_invite_users
|
||||
if can_pin_messages is not None:
|
||||
permissions['can_pin_messages'] = can_pin_messages
|
||||
permissions_json = json.dumps(permissions)
|
||||
payload = {'chat_id': chat_id, 'user_id': user_id, 'permissions': permissions_json}
|
||||
payload = {'chat_id': chat_id, 'user_id': user_id, 'permissions': permissions.to_json()}
|
||||
|
||||
if use_independent_chat_permissions is not None:
|
||||
payload['use_independent_chat_permissions'] = use_independent_chat_permissions
|
||||
if until_date is not None:
|
||||
if isinstance(until_date, datetime):
|
||||
payload['until_date'] = until_date.timestamp()
|
||||
|
@ -1046,12 +1032,14 @@ async def unban_chat_sender_chat(token, chat_id, sender_chat_id):
|
|||
payload = {'chat_id': chat_id, 'sender_chat_id': sender_chat_id}
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def set_chat_permissions(token, chat_id, permissions):
|
||||
async def set_chat_permissions(token, chat_id, permissions, use_independent_chat_permissions=None):
|
||||
method_url = 'setChatPermissions'
|
||||
payload = {
|
||||
'chat_id': chat_id,
|
||||
'permissions': permissions.to_json()
|
||||
}
|
||||
if use_independent_chat_permissions is not None:
|
||||
payload['use_independent_chat_permissions'] = use_independent_chat_permissions
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
|
@ -1154,6 +1142,37 @@ async def set_chat_title(token, chat_id, title):
|
|||
payload = {'chat_id': chat_id, 'title': title}
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def set_my_description(token, description=None, language_code=None):
|
||||
method_url = r'setMyDescription'
|
||||
payload = {}
|
||||
if description is not None:
|
||||
payload['description'] = description
|
||||
if language_code is not None:
|
||||
payload['language_code'] = language_code
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def get_my_description(token, language_code=None):
|
||||
method_url = r'getMyDescription'
|
||||
payload = {}
|
||||
if language_code:
|
||||
payload['language_code'] = language_code
|
||||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
async def set_my_short_description(token, short_description=None, language_code=None):
|
||||
method_url = r'setMyShortDescription'
|
||||
payload = {}
|
||||
if short_description is not None:
|
||||
payload['short_description'] = short_description
|
||||
if language_code is not None:
|
||||
payload['language_code'] = language_code
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def get_my_short_description(token, language_code=None):
|
||||
method_url = r'getMyShortDescription'
|
||||
payload = {}
|
||||
if language_code:
|
||||
payload['language_code'] = language_code
|
||||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
async def get_my_commands(token, scope=None, language_code=None):
|
||||
method_url = r'getMyCommands'
|
||||
|
@ -1164,6 +1183,23 @@ async def get_my_commands(token, scope=None, language_code=None):
|
|||
payload['language_code'] = language_code
|
||||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
|
||||
async def set_my_name(token, name=None, language_code=None):
|
||||
method_url = r'setMyName'
|
||||
payload = {}
|
||||
if name is not None:
|
||||
payload['name'] = name
|
||||
if language_code is not None:
|
||||
payload['language_code'] = language_code
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def get_my_name(token, language_code=None):
|
||||
method_url = r'getMyName'
|
||||
payload = {}
|
||||
if language_code is not None:
|
||||
payload['language_code'] = language_code
|
||||
return await _process_request(token, method_url, params=payload)
|
||||
|
||||
async def set_chat_menu_button(token, chat_id=None, menu_button=None):
|
||||
method_url = r'setChatMenuButton'
|
||||
payload = {}
|
||||
|
@ -1416,8 +1452,8 @@ async def send_invoice(
|
|||
need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None,
|
||||
send_phone_number_to_provider = None, send_email_to_provider = None, is_flexible=None,
|
||||
disable_notification=None, reply_to_message_id=None, reply_markup=None, provider_data=None,
|
||||
timeout=None, allow_sending_without_reply=None, max_tip_amount=None, suggested_tip_amounts=None, protect_content=None,
|
||||
message_thread_id=None):
|
||||
timeout=None, allow_sending_without_reply=None, max_tip_amount=None, suggested_tip_amounts=None,
|
||||
protect_content=None, message_thread_id=None):
|
||||
"""
|
||||
Use this method to send invoices. On success, the sent Message is returned.
|
||||
:param token: Bot's token (you don't need to fill this)
|
||||
|
@ -1449,7 +1485,8 @@ async def send_invoice(
|
|||
:param max_tip_amount: The maximum accepted amount for tips in the smallest units of the currency
|
||||
:param suggested_tip_amounts: A JSON-serialized array of suggested amounts of tips in the smallest units of the currency.
|
||||
At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
|
||||
:param protect_content:
|
||||
:param protect_content: Protects the contents of the sent message from forwarding and saving
|
||||
:param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
|
||||
:return:
|
||||
"""
|
||||
method_url = r'sendInvoice'
|
||||
|
@ -1567,7 +1604,7 @@ async def answer_callback_query(token, callback_query_id, text=None, show_alert=
|
|||
|
||||
|
||||
async def answer_inline_query(token, inline_query_id, results, cache_time=None, is_personal=None, next_offset=None,
|
||||
switch_pm_text=None, switch_pm_parameter=None):
|
||||
button=None):
|
||||
method_url = 'answerInlineQuery'
|
||||
payload = {'inline_query_id': inline_query_id, 'results': await _convert_list_json_serializable(results)}
|
||||
if cache_time is not None:
|
||||
|
@ -1576,10 +1613,10 @@ async def answer_inline_query(token, inline_query_id, results, cache_time=None,
|
|||
payload['is_personal'] = is_personal
|
||||
if next_offset is not None:
|
||||
payload['next_offset'] = next_offset
|
||||
if switch_pm_text:
|
||||
payload['switch_pm_text'] = switch_pm_text
|
||||
if switch_pm_parameter:
|
||||
payload['switch_pm_parameter'] = switch_pm_parameter
|
||||
if button is not None:
|
||||
payload["button"] = button.to_json()
|
||||
|
||||
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
|
@ -1589,62 +1626,85 @@ async def get_sticker_set(token, name):
|
|||
|
||||
async def get_custom_emoji_stickers(token, custom_emoji_ids):
|
||||
method_url = r'getCustomEmojiStickers'
|
||||
return await _process_request(token, method_url, params={'custom_emoji_ids': custom_emoji_ids})
|
||||
return await _process_request(token, method_url, params={'custom_emoji_ids': json.dumps(custom_emoji_ids)})
|
||||
|
||||
async def upload_sticker_file(token, user_id, png_sticker):
|
||||
async def set_sticker_keywords(token, sticker, keywords=None):
|
||||
method_url = 'setStickerKeywords'
|
||||
payload = {'sticker': sticker}
|
||||
if keywords:
|
||||
payload['keywords'] = json.dumps(keywords)
|
||||
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def set_sticker_mask_position(token, sticker, mask_position=None):
|
||||
method_url = 'setStickerMaskPosition'
|
||||
payload = {'sticker': sticker}
|
||||
if mask_position:
|
||||
payload['mask_position'] = mask_position.to_json()
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def upload_sticker_file(token, user_id, sticker, sticker_format):
|
||||
method_url = 'uploadStickerFile'
|
||||
payload = {'user_id': user_id}
|
||||
files = {'png_sticker': png_sticker}
|
||||
payload = {'user_id': user_id, 'sticker_format': sticker_format}
|
||||
files = {'sticker': sticker}
|
||||
return await _process_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
async def set_sticker_emoji_list(token, sticker, emoji_list):
|
||||
method_url = 'setStickerEmojiList'
|
||||
payload = {'sticker': sticker, 'emoji_list': json.dumps(emoji_list)}
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def delete_sticker_set(token, name):
|
||||
method_url = 'deleteStickerSet'
|
||||
payload = {'name': name}
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def set_custom_emoji_sticker_set_thumbnail(token, name, custom_emoji_id=None):
|
||||
method_url = 'setCustomEmojiStickerSetThumbnail'
|
||||
payload = {'name': name}
|
||||
if custom_emoji_id is not None:
|
||||
payload['custom_emoji_id'] = custom_emoji_id
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
|
||||
async def set_sticker_set_title(token, name, title):
|
||||
method_url = 'setStickerSetTitle'
|
||||
payload = {'name': name, 'title': title}
|
||||
return await _process_request(token, method_url, params=payload, method='post')
|
||||
|
||||
async def create_new_sticker_set(
|
||||
token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
||||
mask_position=None, webm_sticker=None, sticker_type=None):
|
||||
token, user_id, name, title, stickers, sticker_format, sticker_type=None, needs_repainting=None):
|
||||
method_url = 'createNewStickerSet'
|
||||
payload = {'user_id': user_id, 'name': name, 'title': title, 'emojis': emojis}
|
||||
if png_sticker:
|
||||
stype = 'png_sticker'
|
||||
elif webm_sticker:
|
||||
stype = 'webm_sticker'
|
||||
else:
|
||||
stype = 'tgs_sticker'
|
||||
sticker = png_sticker or tgs_sticker or webm_sticker
|
||||
files = None
|
||||
if not util.is_string(sticker):
|
||||
files = {stype: sticker}
|
||||
else:
|
||||
payload[stype] = sticker
|
||||
if mask_position:
|
||||
payload['mask_position'] = mask_position.to_json()
|
||||
if webm_sticker:
|
||||
payload['webm_sticker'] = webm_sticker
|
||||
payload = {'user_id': user_id, 'name': name, 'title': title, 'sticker_format': sticker_format}
|
||||
if sticker_type:
|
||||
payload['sticker_type'] = sticker_type
|
||||
if needs_repainting:
|
||||
payload['needs_repainting'] = needs_repainting
|
||||
|
||||
files = {}
|
||||
lst = []
|
||||
|
||||
for sticker in stickers:
|
||||
json_dict, file = sticker.convert_input_sticker()
|
||||
json_dict = sticker.to_dict()
|
||||
|
||||
if file:
|
||||
list_keys = list(file.keys())
|
||||
files[list_keys[0]] = file[list_keys[0]]
|
||||
lst.append(json_dict)
|
||||
|
||||
payload['stickers'] = json.dumps(lst)
|
||||
|
||||
|
||||
return await _process_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
async def add_sticker_to_set(token, user_id, name, emojis, png_sticker, tgs_sticker, mask_position, webm_sticker):
|
||||
async def add_sticker_to_set(token, user_id, name, sticker):
|
||||
method_url = 'addStickerToSet'
|
||||
payload = {'user_id': user_id, 'name': name, 'emojis': emojis}
|
||||
if png_sticker:
|
||||
stype = 'png_sticker'
|
||||
elif webm_sticker:
|
||||
stype = 'webm_sticker'
|
||||
else:
|
||||
stype = 'tgs_sticker'
|
||||
files = None
|
||||
sticker = png_sticker or tgs_sticker or webm_sticker
|
||||
json_dict, files = sticker.convert_input_sticker()
|
||||
payload = {'user_id': user_id, 'name': name, 'sticker': json_dict}
|
||||
|
||||
|
||||
if not util.is_string(sticker):
|
||||
files = {stype: sticker}
|
||||
else:
|
||||
payload[stype] = sticker
|
||||
if mask_position:
|
||||
payload['mask_position'] = mask_position.to_json()
|
||||
|
||||
if webm_sticker:
|
||||
payload['webm_sticker'] = webm_sticker
|
||||
return await _process_request(token, method_url, params=payload, files=files, method='post')
|
||||
|
||||
|
||||
|
@ -1914,10 +1974,10 @@ class ApiHTTPException(ApiException):
|
|||
This class represents an Exception thrown when a call to the
|
||||
Telegram API server returns HTTP code that is not 200.
|
||||
"""
|
||||
def __init__(self, function_name, result):
|
||||
def __init__(self, function_name, result: aiohttp.ClientResponse):
|
||||
super(ApiHTTPException, self).__init__(
|
||||
"The server returned HTTP {0} {1}. Response body:\n[{2}]" \
|
||||
.format(result.status_code, result.reason, result),
|
||||
.format(result.status, result.reason, result.request_info),
|
||||
function_name,
|
||||
result)
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class StatePickleStorage(StateStorageBase):
|
|||
"""
|
||||
Create directory .save-handlers.
|
||||
"""
|
||||
dirs = self.file_path.rsplit('/', maxsplit=1)[0]
|
||||
dirs, filename = os.path.split(self.file_path)
|
||||
os.makedirs(dirs, exist_ok=True)
|
||||
if not os.path.isfile(self.file_path):
|
||||
with open(self.file_path,'wb') as file:
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
from telebot.asyncio_storage.base_storage import StateStorageBase, StateContext
|
||||
import json
|
||||
|
||||
|
||||
redis_installed = True
|
||||
is_actual_aioredis = False
|
||||
try:
|
||||
import aioredis
|
||||
is_actual_aioredis = True
|
||||
except ImportError:
|
||||
try:
|
||||
from redis import asyncio as aioredis
|
||||
|
@ -23,10 +24,10 @@ class StateRedisStorage(StateStorageBase):
|
|||
if not redis_installed:
|
||||
raise ImportError('AioRedis is not installed. Install it via "pip install aioredis"')
|
||||
|
||||
|
||||
aioredis_version = tuple(map(int, aioredis.__version__.split(".")[0]))
|
||||
if aioredis_version < (2,):
|
||||
raise ImportError('Invalid aioredis version. Aioredis version should be >= 2.0.0')
|
||||
if is_actual_aioredis:
|
||||
aioredis_version = tuple(map(int, aioredis.__version__.split(".")[0]))
|
||||
if aioredis_version < (2,):
|
||||
raise ImportError('Invalid aioredis version. Aioredis version should be >= 2.0.0')
|
||||
self.redis = aioredis.Redis(host=host, port=port, db=db, password=password)
|
||||
|
||||
self.prefix = prefix
|
||||
|
@ -170,6 +171,6 @@ class StateRedisStorage(StateStorageBase):
|
|||
user_id = str(user_id)
|
||||
if response:
|
||||
if user_id in response:
|
||||
response[user_id]['data'] = dict(data, **response[user_id]['data'])
|
||||
response[user_id]['data'] = data
|
||||
await self.set_record(chat_id, response)
|
||||
return True
|
||||
|
|
|
@ -61,8 +61,8 @@ def escape_markdown(content: str) -> str:
|
|||
:rtype: :obj:`str`
|
||||
"""
|
||||
|
||||
parse = re.sub(r"([_*\[\]()~`>\#\+\-=|\.!\{\}])", r"\\\1", content)
|
||||
reparse = re.sub(r"\\\\([_*\[\]()~`>\#\+\-=|\.!\{\}])", r"\1", parse)
|
||||
parse = re.sub(r"([_*\[\]()~`>\#\+\-=|\.!\{\}\\])", r"\\\1", content)
|
||||
reparse = re.sub(r"\\\\([_*\[\]()~`>\#\+\-=|\.!\{\}\\])", r"\1", parse)
|
||||
return reparse
|
||||
|
||||
|
||||
|
|
|
@ -185,13 +185,20 @@ class StatesGroup:
|
|||
my_state = State() # returns my_state:State string.
|
||||
"""
|
||||
def __init_subclass__(cls) -> None:
|
||||
state_list = []
|
||||
for name, value in cls.__dict__.items():
|
||||
if not name.startswith('__') and not callable(value) and isinstance(value, State):
|
||||
# change value of that variable
|
||||
value.name = ':'.join((cls.__name__, name))
|
||||
value.group = cls
|
||||
state_list.append(value)
|
||||
cls._state_list = state_list
|
||||
|
||||
@property
|
||||
def state_list(self):
|
||||
return self._state_list
|
||||
|
||||
|
||||
|
||||
class BaseMiddleware:
|
||||
"""
|
||||
Base class for middleware.
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
import random
|
||||
import string
|
||||
from io import BytesIO
|
||||
|
||||
try:
|
||||
# noinspection PyPackageRequirements
|
||||
from PIL import Image
|
||||
pil_imported = True
|
||||
except ImportError:
|
||||
pil_imported = False
|
||||
|
||||
|
||||
def is_string(var) -> bool:
|
||||
"""
|
||||
Returns True if the given object is a string.
|
||||
"""
|
||||
return isinstance(var, str)
|
||||
|
||||
|
||||
def is_dict(var) -> bool:
|
||||
"""
|
||||
Returns True if the given object is a dictionary.
|
||||
|
||||
:param var: object to be checked
|
||||
:type var: :obj:`object`
|
||||
|
||||
:return: True if the given object is a dictionary.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return isinstance(var, dict)
|
||||
|
||||
|
||||
def is_bytes(var) -> bool:
|
||||
"""
|
||||
Returns True if the given object is a bytes object.
|
||||
|
||||
:param var: object to be checked
|
||||
:type var: :obj:`object`
|
||||
|
||||
:return: True if the given object is a bytes object.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return isinstance(var, bytes)
|
||||
|
||||
|
||||
def is_pil_image(var) -> bool:
|
||||
"""
|
||||
Returns True if the given object is a PIL.Image.Image object.
|
||||
|
||||
:param var: object to be checked
|
||||
:type var: :obj:`object`
|
||||
|
||||
:return: True if the given object is a PIL.Image.Image object.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return pil_imported and isinstance(var, Image.Image)
|
||||
|
||||
|
||||
def pil_image_to_file(image, extension='JPEG', quality='web_low'):
|
||||
if pil_imported:
|
||||
photoBuffer = BytesIO()
|
||||
image.convert('RGB').save(photoBuffer, extension, quality=quality)
|
||||
photoBuffer.seek(0)
|
||||
|
||||
return photoBuffer
|
||||
else:
|
||||
raise RuntimeError('PIL module is not imported')
|
||||
|
||||
|
||||
def chunks(lst, n):
|
||||
"""Yield successive n-sized chunks from lst."""
|
||||
# https://stackoverflow.com/a/312464/9935473
|
||||
for i in range(0, len(lst), n):
|
||||
yield lst[i:i + n]
|
||||
|
||||
|
||||
def generate_random_token() -> str:
|
||||
"""
|
||||
Generates a random token consisting of letters and digits, 16 characters long.
|
||||
|
||||
:return: a random token
|
||||
:rtype: :obj:`str`
|
||||
"""
|
||||
return ''.join(random.sample(string.ascii_letters, 16))
|
|
@ -34,7 +34,7 @@ class StatePickleStorage(StateStorageBase):
|
|||
"""
|
||||
Create directory .save-handlers.
|
||||
"""
|
||||
dirs = self.file_path.rsplit('/', maxsplit=1)[0]
|
||||
dirs, filename = os.path.split(self.file_path)
|
||||
os.makedirs(dirs, exist_ok=True)
|
||||
if not os.path.isfile(self.file_path):
|
||||
with open(self.file_path,'wb') as file:
|
||||
|
|
|
@ -174,7 +174,7 @@ class StateRedisStorage(StateStorageBase):
|
|||
user_id = str(user_id)
|
||||
if response:
|
||||
if user_id in response:
|
||||
response[user_id]['data'] = dict(data, **response[user_id]['data'])
|
||||
response[user_id]['data'] = data
|
||||
self.set_record(chat_id, response)
|
||||
return True
|
||||
|
||||
|
|
1225
telebot/types.py
1225
telebot/types.py
File diff suppressed because it is too large
Load Diff
209
telebot/util.py
209
telebot/util.py
|
@ -1,7 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
import threading
|
||||
import traceback
|
||||
from typing import Any, Callable, List, Dict, Optional, Union
|
||||
|
@ -14,21 +12,13 @@ import queue as Queue
|
|||
import logging
|
||||
|
||||
from telebot import types
|
||||
from telebot.service_utils import is_pil_image, is_dict, is_string, is_bytes, chunks, generate_random_token, pil_image_to_file
|
||||
|
||||
try:
|
||||
import ujson as json
|
||||
except ImportError:
|
||||
import json
|
||||
|
||||
try:
|
||||
# noinspection PyPackageRequirements
|
||||
from PIL import Image
|
||||
from io import BytesIO
|
||||
|
||||
pil_imported = True
|
||||
except:
|
||||
pil_imported = False
|
||||
|
||||
MAX_MESSAGE_LENGTH = 4096
|
||||
|
||||
logger = logging.getLogger('TeleBot')
|
||||
|
@ -44,11 +34,11 @@ content_type_media = [
|
|||
|
||||
#: Contains all service content types such as `User joined the group`.
|
||||
content_type_service = [
|
||||
'new_chat_members', 'left_chat_member', 'new_chat_title', 'new_chat_photo', 'delete_chat_photo', 'group_chat_created',
|
||||
'supergroup_chat_created', 'channel_chat_created', 'migrate_to_chat_id', 'migrate_from_chat_id', 'pinned_message',
|
||||
'proximity_alert_triggered', 'video_chat_scheduled', 'video_chat_started', 'video_chat_ended',
|
||||
'video_chat_participants_invited', 'message_auto_delete_timer_changed', 'forum_topic_created', 'forum_topic_closed',
|
||||
'forum_topic_reopened',
|
||||
'new_chat_members', 'left_chat_member', 'new_chat_title', 'new_chat_photo', 'delete_chat_photo',
|
||||
'group_chat_created', 'supergroup_chat_created', 'channel_chat_created', 'migrate_to_chat_id',
|
||||
'migrate_from_chat_id', 'pinned_message', 'proximity_alert_triggered', 'video_chat_scheduled', 'video_chat_started',
|
||||
'video_chat_ended', 'video_chat_participants_invited', 'message_auto_delete_timer_changed', 'forum_topic_created',
|
||||
'forum_topic_closed', 'forum_topic_reopened', 'user_shared', 'chat_shared',
|
||||
]
|
||||
|
||||
#: All update types, should be used for allowed_updates parameter in polling.
|
||||
|
@ -129,6 +119,7 @@ class ThreadPool:
|
|||
"""
|
||||
:meta private:
|
||||
"""
|
||||
|
||||
def __init__(self, telebot, num_threads=2):
|
||||
self.telebot = telebot
|
||||
self.tasks = Queue.Queue()
|
||||
|
@ -162,13 +153,15 @@ class ThreadPool:
|
|||
for worker in self.workers:
|
||||
worker.stop()
|
||||
for worker in self.workers:
|
||||
worker.join()
|
||||
if worker != threading.current_thread():
|
||||
worker.join()
|
||||
|
||||
|
||||
class AsyncTask:
|
||||
"""
|
||||
:meta private:
|
||||
"""
|
||||
|
||||
def __init__(self, target, *args, **kwargs):
|
||||
self.target = target
|
||||
self.args = args
|
||||
|
@ -198,7 +191,8 @@ class CustomRequestResponse():
|
|||
"""
|
||||
:meta private:
|
||||
"""
|
||||
def __init__(self, json_text, status_code = 200, reason = ""):
|
||||
|
||||
def __init__(self, json_text, status_code=200, reason=""):
|
||||
self.status_code = status_code
|
||||
self.text = json_text
|
||||
self.reason = reason
|
||||
|
@ -211,6 +205,7 @@ def async_dec():
|
|||
"""
|
||||
:meta private:
|
||||
"""
|
||||
|
||||
def decorator(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
return AsyncTask(fn, *args, **kwargs)
|
||||
|
@ -220,63 +215,6 @@ def async_dec():
|
|||
return decorator
|
||||
|
||||
|
||||
def is_string(var) -> bool:
|
||||
"""
|
||||
Returns True if the given object is a string.
|
||||
"""
|
||||
return isinstance(var, str)
|
||||
|
||||
|
||||
def is_dict(var) -> bool:
|
||||
"""
|
||||
Returns True if the given object is a dictionary.
|
||||
|
||||
:param var: object to be checked
|
||||
:type var: :obj:`object`
|
||||
|
||||
:return: True if the given object is a dictionary.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return isinstance(var, dict)
|
||||
|
||||
|
||||
def is_bytes(var) -> bool:
|
||||
"""
|
||||
Returns True if the given object is a bytes object.
|
||||
|
||||
:param var: object to be checked
|
||||
:type var: :obj:`object`
|
||||
|
||||
:return: True if the given object is a bytes object.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return isinstance(var, bytes)
|
||||
|
||||
|
||||
def is_pil_image(var) -> bool:
|
||||
"""
|
||||
Returns True if the given object is a PIL.Image.Image object.
|
||||
|
||||
:param var: object to be checked
|
||||
:type var: :obj:`object`
|
||||
|
||||
:return: True if the given object is a PIL.Image.Image object.
|
||||
:rtype: :obj:`bool`
|
||||
"""
|
||||
return pil_imported and isinstance(var, Image.Image)
|
||||
|
||||
|
||||
def pil_image_to_file(image, extension='JPEG', quality='web_low'):
|
||||
if pil_imported:
|
||||
photoBuffer = BytesIO()
|
||||
image.convert('RGB').save(photoBuffer, extension, quality=quality)
|
||||
photoBuffer.seek(0)
|
||||
|
||||
return photoBuffer
|
||||
else:
|
||||
raise RuntimeError('PIL module is not imported')
|
||||
|
||||
|
||||
def is_command(text: str) -> bool:
|
||||
r"""
|
||||
Checks if `text` is a command. Telegram chat commands start with the '/' character.
|
||||
|
@ -335,6 +273,39 @@ def extract_arguments(text: str) -> str or None:
|
|||
result = regexp.match(text)
|
||||
return result.group(2) if is_command(text) else None
|
||||
|
||||
def extract_entity(text: str, e: types.MessageEntity) -> str:
|
||||
"""
|
||||
Returns the content of the entity.
|
||||
|
||||
:param text: The text of the message the entity belongs to
|
||||
:type text: :obj:`str`
|
||||
|
||||
:param e: The entity to extract
|
||||
:type e: :obj:`MessageEntity`
|
||||
|
||||
:return: The content of the entity
|
||||
:rtype: :obj:`str`
|
||||
"""
|
||||
offset = 0
|
||||
start = 0
|
||||
encoded_text = text.encode()
|
||||
end = len(encoded_text)
|
||||
i = 0
|
||||
|
||||
for byte in encoded_text:
|
||||
if (byte & 0xc0) != 0x80:
|
||||
if offset == e.offset:
|
||||
start = i
|
||||
elif offset - e.offset == e.length:
|
||||
end = i
|
||||
break
|
||||
if byte >= 0xf0:
|
||||
offset += 2
|
||||
else:
|
||||
offset += 1
|
||||
i += 1
|
||||
|
||||
return encoded_text[start:end].decode()
|
||||
|
||||
def split_string(text: str, chars_per_string: int) -> List[str]:
|
||||
"""
|
||||
|
@ -353,7 +324,7 @@ def split_string(text: str, chars_per_string: int) -> List[str]:
|
|||
return [text[i:i + chars_per_string] for i in range(0, len(text), chars_per_string)]
|
||||
|
||||
|
||||
def smart_split(text: str, chars_per_string: int=MAX_MESSAGE_LENGTH) -> List[str]:
|
||||
def smart_split(text: str, chars_per_string: int = MAX_MESSAGE_LENGTH) -> List[str]:
|
||||
r"""
|
||||
Splits one string into multiple strings, with a maximum amount of `chars_per_string` characters per string.
|
||||
This is very useful for splitting one giant message into multiples.
|
||||
|
@ -383,9 +354,12 @@ def smart_split(text: str, chars_per_string: int=MAX_MESSAGE_LENGTH) -> List[str
|
|||
|
||||
part = text[:chars_per_string]
|
||||
|
||||
if "\n" in part: part = _text_before_last("\n")
|
||||
elif ". " in part: part = _text_before_last(". ")
|
||||
elif " " in part: part = _text_before_last(" ")
|
||||
if "\n" in part:
|
||||
part = _text_before_last("\n")
|
||||
elif ". " in part:
|
||||
part = _text_before_last(". ")
|
||||
elif " " in part:
|
||||
part = _text_before_last(" ")
|
||||
|
||||
parts.append(part)
|
||||
text = text[len(part):]
|
||||
|
@ -401,12 +375,12 @@ def escape(text: str) -> str:
|
|||
chars = {"&": "&", "<": "<", ">": ">"}
|
||||
if text is None:
|
||||
return None
|
||||
for old, new in chars.items():
|
||||
for old, new in chars.items():
|
||||
text = text.replace(old, new)
|
||||
return text
|
||||
|
||||
|
||||
def user_link(user: types.User, include_id: bool=False) -> str:
|
||||
def user_link(user: types.User, include_id: bool = False) -> str:
|
||||
"""
|
||||
Returns an HTML user link. This is useful for reports.
|
||||
Attention: Don't forget to set parse_mode to 'HTML'!
|
||||
|
@ -433,10 +407,10 @@ def user_link(user: types.User, include_id: bool=False) -> str:
|
|||
"""
|
||||
name = escape(user.first_name)
|
||||
return (f"<a href='tg://user?id={user.id}'>{name}</a>"
|
||||
+ (f" (<pre>{user.id}</pre>)" if include_id else ""))
|
||||
+ (f" (<pre>{user.id}</pre>)" if include_id else ""))
|
||||
|
||||
|
||||
def quick_markup(values: Dict[str, Dict[str, Any]], row_width: int=2) -> types.InlineKeyboardMarkup:
|
||||
def quick_markup(values: Dict[str, Dict[str, Any]], row_width: int = 2) -> types.InlineKeyboardMarkup:
|
||||
"""
|
||||
Returns a reply markup from a dict in this format: {'text': kwargs}
|
||||
This is useful to avoid always typing 'btn1 = InlineKeyboardButton(...)' 'btn2 = InlineKeyboardButton(...)'
|
||||
|
@ -446,11 +420,13 @@ def quick_markup(values: Dict[str, Dict[str, Any]], row_width: int=2) -> types.I
|
|||
.. code-block:: python3
|
||||
:caption: Using quick_markup:
|
||||
|
||||
quick_markup({
|
||||
from telebot.util import quick_markup
|
||||
|
||||
markup = quick_markup({
|
||||
'Twitter': {'url': 'https://twitter.com'},
|
||||
'Facebook': {'url': 'https://facebook.com'},
|
||||
'Back': {'callback_data': 'whatever'}
|
||||
}, row_width=2):
|
||||
}, row_width=2)
|
||||
# returns an InlineKeyboardMarkup with two buttons in a row, one leading to Twitter, the other to facebook
|
||||
# and a back button below
|
||||
|
||||
|
@ -469,7 +445,7 @@ def quick_markup(values: Dict[str, Dict[str, Any]], row_width: int=2) -> types.I
|
|||
:param values: a dict containing all buttons to create in this format: {text: kwargs} {str:}
|
||||
:type values: :obj:`dict`
|
||||
|
||||
:param row_width: int row width
|
||||
:param row_width: number of :class:`telebot.types.InlineKeyboardButton` objects on each row
|
||||
:type row_width: :obj:`int`
|
||||
|
||||
:return: InlineKeyboardMarkup
|
||||
|
@ -551,24 +527,7 @@ def per_thread(key, construct_value, reset=False):
|
|||
return getattr(thread_local, key)
|
||||
|
||||
|
||||
def chunks(lst, n):
|
||||
"""Yield successive n-sized chunks from lst."""
|
||||
# https://stackoverflow.com/a/312464/9935473
|
||||
for i in range(0, len(lst), n):
|
||||
yield lst[i:i + n]
|
||||
|
||||
|
||||
def generate_random_token() -> str:
|
||||
"""
|
||||
Generates a random token consisting of letters and digits, 16 characters long.
|
||||
|
||||
:return: a random token
|
||||
:rtype: :obj:`str`
|
||||
"""
|
||||
return ''.join(random.sample(string.ascii_letters, 16))
|
||||
|
||||
|
||||
def deprecated(warn: bool=True, alternative: Optional[Callable]=None, deprecation_text=None):
|
||||
def deprecated(warn: bool = True, alternative: Optional[Callable] = None, deprecation_text=None):
|
||||
"""
|
||||
Use this decorator to mark functions as deprecated.
|
||||
When the function is used, an info (or warning if `warn` is True) is logged.
|
||||
|
@ -586,6 +545,7 @@ def deprecated(warn: bool=True, alternative: Optional[Callable]=None, deprecatio
|
|||
|
||||
:return: The decorated function
|
||||
"""
|
||||
|
||||
def decorator(function):
|
||||
def wrapper(*args, **kwargs):
|
||||
info = f"`{function.__name__}` is deprecated."
|
||||
|
@ -598,7 +558,9 @@ def deprecated(warn: bool=True, alternative: Optional[Callable]=None, deprecatio
|
|||
else:
|
||||
logger.warning(info)
|
||||
return function(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
|
@ -628,7 +590,7 @@ def webhook_google_functions(bot, request):
|
|||
return 'Bot ON'
|
||||
|
||||
|
||||
def antiflood(function: Callable, *args, **kwargs):
|
||||
def antiflood(function: Callable, *args, number_retries=5, **kwargs):
|
||||
"""
|
||||
Use this function inside loops in order to avoid getting TooManyRequests error.
|
||||
Example:
|
||||
|
@ -642,6 +604,9 @@ def antiflood(function: Callable, *args, **kwargs):
|
|||
:param function: The function to call
|
||||
:type function: :obj:`Callable`
|
||||
|
||||
:param number_retries: Number of retries to send
|
||||
:type function: :obj:int
|
||||
|
||||
:param args: The arguments to pass to the function
|
||||
:type args: :obj:`tuple`
|
||||
|
||||
|
@ -653,16 +618,18 @@ def antiflood(function: Callable, *args, **kwargs):
|
|||
from telebot.apihelper import ApiTelegramException
|
||||
from time import sleep
|
||||
|
||||
try:
|
||||
return function(*args, **kwargs)
|
||||
except ApiTelegramException as ex:
|
||||
if ex.error_code == 429:
|
||||
sleep(ex.result_json['parameters']['retry_after'])
|
||||
for _ in range(number_retries - 1):
|
||||
try:
|
||||
return function(*args, **kwargs)
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
except ApiTelegramException as ex:
|
||||
if ex.error_code == 429:
|
||||
sleep(ex.result_json['parameters']['retry_after'])
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
return function(*args, **kwargs)
|
||||
|
||||
|
||||
def parse_web_app_data(token: str, raw_init_data: str):
|
||||
"""
|
||||
Parses web app data.
|
||||
|
@ -715,4 +682,16 @@ def validate_web_app_data(token: str, raw_init_data: str):
|
|||
|
||||
return hmac.new(secret_key.digest(), data_check_string.encode(), sha256).hexdigest() == init_data_hash
|
||||
|
||||
|
||||
|
||||
__all__ = (
|
||||
"content_type_media", "content_type_service", "update_types",
|
||||
"WorkerThread", "AsyncTask", "CustomRequestResponse",
|
||||
"async_dec", "deprecated",
|
||||
"is_bytes", "is_string", "is_dict", "is_pil_image",
|
||||
"chunks", "generate_random_token", "pil_image_to_file",
|
||||
"is_command", "extract_command", "extract_arguments",
|
||||
"split_string", "smart_split", "escape", "user_link", "quick_markup",
|
||||
"antiflood", "parse_web_app_data", "validate_web_app_data",
|
||||
"or_set", "or_clear", "orify", "OrEvent", "per_thread",
|
||||
"webhook_google_functions"
|
||||
)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
# Versions should comply with PEP440.
|
||||
# This line is parsed in setup.py:
|
||||
__version__ = '4.9.0'
|
||||
__version__ = '4.12.0'
|
||||
|
|
|
@ -470,6 +470,53 @@ class TestTeleBot:
|
|||
for i in range(0,200):
|
||||
util.antiflood(tb.send_message, CHAT_ID, text)
|
||||
assert i == 199
|
||||
|
||||
def test_extract_entity(self):
|
||||
entities_map = {"https://core.telegram.org/api/entities": "https://core.telegram.org/api/entities",
|
||||
"https://github.com/eternnoir/pyTelegramBotAPI": "https://github.com/eternnoir/pyTelegramBotAPI",
|
||||
"*粗 bold text体*": "粗 bold text体",
|
||||
"_斜体 italic text_": "斜体 italic text",
|
||||
"[谷歌](http://www.google.com/)": "谷歌",
|
||||
'`std::cout<<"test"<<std::endl;`': 'std::cout<<"test"<<std::endl;',
|
||||
'''```rust
|
||||
let number = loop {
|
||||
println!("Pick a pattern from 0-2:");
|
||||
stdin.read_line(&mut option).unwrap();
|
||||
match option.lines().next().unwrap().parse::<usize>() {
|
||||
Ok(number @ 0..=2) => break number,
|
||||
_ => {
|
||||
println!("invalid input!");
|
||||
option = String::new();
|
||||
continue;
|
||||
}
|
||||
};
|
||||
};```''': '''let number = loop {
|
||||
println!("Pick a pattern from 0-2:");
|
||||
stdin.read_line(&mut option).unwrap();
|
||||
match option.lines().next().unwrap().parse::<usize>() {
|
||||
Ok(number @ 0..=2) => break number,
|
||||
_ => {
|
||||
println!("invalid input!");
|
||||
option = String::new();
|
||||
continue;
|
||||
}
|
||||
};
|
||||
};''',
|
||||
"@username": "@username",
|
||||
"#hashtag索引标签": "#hashtag索引标签",
|
||||
"do-not-reply@telegram.org": "do-not-reply@telegram.org",
|
||||
"+12125550123": "+12125550123"}
|
||||
entites = list(entities_map.keys())
|
||||
contents = list(entities_map.values())
|
||||
contents.sort()
|
||||
text = '\n'.join(entites)
|
||||
|
||||
bot = telebot.TeleBot(TOKEN)
|
||||
message = bot.send_message(CHAT_ID, text, parse_mode="Markdown")
|
||||
extracted_contents = [util.extract_entity(
|
||||
message.text, e) for e in message.entities]
|
||||
extracted_contents.sort()
|
||||
assert contents == extracted_contents
|
||||
|
||||
@staticmethod
|
||||
def create_text_message(text):
|
||||
|
|
|
@ -67,9 +67,9 @@ def test_json_GroupChat():
|
|||
|
||||
|
||||
def test_json_Document():
|
||||
json_string = r'{"file_name":"Text File","thumb":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_unique_id": "AgADJQEAAqfhOEY","file_size":446}'
|
||||
json_string = r'{"file_name":"Text File","thumbnail":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_unique_id": "AgADJQEAAqfhOEY","file_size":446}'
|
||||
doc = types.Document.de_json(json_string)
|
||||
assert doc.thumb is None
|
||||
assert doc.thumbnail is None
|
||||
assert doc.file_name == 'Text File'
|
||||
|
||||
|
||||
|
@ -83,23 +83,23 @@ def test_json_Message_Audio():
|
|||
|
||||
|
||||
def test_json_Message_Sticker():
|
||||
json_string = r'{"message_id": 21552, "from": {"id": 590740002, "is_bot": false, "first_name": "⚜️ Ƥυrуα ⚜️", "username": "Purya", "language_code": "en"}, "chat": {"id": -1001309982000, "title": "123", "type": "supergroup"}, "date": 1594068909, "sticker": {"type": "regular", "width": 368, "height": 368, "emoji": "🤖", "set_name": "ipuryapack", "is_animated": false, "is_video": true, "thumb": {"file_id": "AAMCBAADHQJOFL7mAAJUMF8Dj62hpmDhpRAYvkc8CtIqipolAAJ8AAPA-8cF9yxjgjkLS97A0D4iXQARtQAHbQADHy4AAhoE", "file_unique_id": "AQADwNA-Il0AAx8uAAI", "file_size": 7776, "width": 60, "height": 60}, "file_id": "CAACAgQAAx0CThS-5gACVDBfA4-toaZg4aUQGL5HWerSKoqaJQACArADwPvHBfcsY4I5C3feGgQ", "file_unique_id": "AgADfAADsPvHWQ", "file_size": 14602}}'
|
||||
json_string = r'{"message_id": 21552, "from": {"id": 590740002, "is_bot": false, "first_name": "⚜️ Ƥυrуα ⚜️", "username": "Purya", "language_code": "en"}, "chat": {"id": -1001309982000, "title": "123", "type": "supergroup"}, "date": 1594068909, "sticker": {"type": "regular", "width": 368, "height": 368, "emoji": "🤖", "set_name": "ipuryapack", "is_animated": false, "is_video": true, "thumbnail": {"file_id": "AAMCBAADHQJOFL7mAAJUMF8Dj62hpmDhpRAYvkc8CtIqipolAAJ8AAPA-8cF9yxjgjkLS97A0D4iXQARtQAHbQADHy4AAhoE", "file_unique_id": "AQADwNA-Il0AAx8uAAI", "file_size": 7776, "width": 60, "height": 60}, "file_id": "CAACAgQAAx0CThS-5gACVDBfA4-toaZg4aUQGL5HWerSKoqaJQACArADwPvHBfcsY4I5C3feGgQ", "file_unique_id": "AgADfAADsPvHWQ", "file_size": 14602}}'
|
||||
msg = types.Message.de_json(json_string)
|
||||
assert msg.sticker.height == 368
|
||||
assert msg.sticker.thumb.height == 60
|
||||
assert msg.sticker.thumbnail.height == 60
|
||||
assert msg.content_type == 'sticker'
|
||||
|
||||
|
||||
def test_json_Message_Sticker_without_thumb():
|
||||
def test_json_Message_Sticker_without_thumbnail():
|
||||
json_string = r'{"message_id": 21552, "from": {"id": 590740002, "is_bot": false, "first_name": "⚜️ Ƥυrуα ⚜️", "username": "Purya", "language_code": "en"}, "chat": {"id": -1001309982000, "title": "123", "type": "supergroup"}, "date": 1594068909, "sticker": {"type": "regular", "width": 368, "height": 368, "emoji": "🤖", "set_name": "ipuryapack", "is_animated": false, "is_video": true, "file_id": "CAACAgQAAx0CThS-5gACVDBfA4-toaZg4aUQGL5HWerSKoqaJQACArADwPvHBfcsY4I5C3feGgQ", "file_unique_id": "AgADfAADsPvHWQ", "file_size": 14602}}'
|
||||
msg = types.Message.de_json(json_string)
|
||||
assert msg.sticker.height == 368
|
||||
assert msg.sticker.thumb is None
|
||||
assert msg.sticker.thumbnail is None
|
||||
assert msg.content_type == 'sticker'
|
||||
|
||||
|
||||
def test_json_Message_Document():
|
||||
json_string = r'{"message_id":97,"from":{"id":10734,"first_name":"Fd","last_name":"Wd","username":"dd","is_bot":true },"chat":{"id":10,"first_name":"Fd","type":"private","last_name":"Wd","username":"dd"},"date":1435478744,"document":{"file_name":"Text File","thumb":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":446}}'
|
||||
json_string = r'{"message_id":97,"from":{"id":10734,"first_name":"Fd","last_name":"Wd","username":"dd","is_bot":true },"chat":{"id":10,"first_name":"Fd","type":"private","last_name":"Wd","username":"dd"},"date":1435478744,"document":{"file_name":"Text File","thumbnail":{},"file_id":"BQADBQADMwIAAsYifgZ_CEh0u682xwI","file_unique_id": "AQAD_QIfa3QAAyA4BgAB","file_size":446}}'
|
||||
msg = types.Message.de_json(json_string)
|
||||
assert msg.document.file_name == 'Text File'
|
||||
assert msg.content_type == 'document'
|
||||
|
@ -113,11 +113,11 @@ def test_json_Message_Photo():
|
|||
|
||||
|
||||
def test_json_Message_Video():
|
||||
json_string = r'{"message_id":101,"from":{"id":109734,"first_name":"dd","last_name":"dd","username":"dd","is_bot":true },"chat":{"id":109734,"first_name":"dd","type":"private","last_name":"dd","username":"dd"},"date":1435481960,"video":{"duration":3,"caption":"","width":360,"height":640,"thumb":{"file_id":"AAQFABPiYnBjkDwMAAIC","file_unique_id": "AQADTeisa3QAAz1nAAI","file_size":1597,"width":50,"height":90},"file_id":"BAADBQADNifgb_TOPEKErGoQI","file_unique_id": "AgADbgEAAn8VSFY","file_size":260699}}'
|
||||
json_string = r'{"message_id":101,"from":{"id":109734,"first_name":"dd","last_name":"dd","username":"dd","is_bot":true },"chat":{"id":109734,"first_name":"dd","type":"private","last_name":"dd","username":"dd"},"date":1435481960,"video":{"duration":3,"caption":"","width":360,"height":640,"thumbnail":{"file_id":"AAQFABPiYnBjkDwMAAIC","file_unique_id": "AQADTeisa3QAAz1nAAI","file_size":1597,"width":50,"height":90},"file_id":"BAADBQADNifgb_TOPEKErGoQI","file_unique_id": "AgADbgEAAn8VSFY","file_size":260699}}'
|
||||
msg = types.Message.de_json(json_string)
|
||||
assert msg.video
|
||||
assert msg.video.duration == 3
|
||||
assert msg.video.thumb.width == 50
|
||||
assert msg.video.thumbnail.width == 50
|
||||
assert msg.content_type == 'video'
|
||||
|
||||
|
||||
|
@ -271,5 +271,33 @@ def test_sent_web_app_message():
|
|||
assert sent_web_app_message.inline_message_id == '29430'
|
||||
|
||||
|
||||
def test_message_entity():
|
||||
# TODO: Add support for nesting entities
|
||||
|
||||
|
||||
sample_string_1 = r'{"update_id":934522126,"message":{"message_id":1374510,"from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en","is_premium":true},"chat":{"id":927266710,"first_name":">_run","username":"coder2020","type":"private"},"date":1682177590,"text":"b b b","entities":[{"offset":0,"length":2,"type":"bold"},{"offset":0,"length":1,"type":"italic"},{"offset":2,"length":2,"type":"bold"},{"offset":2,"length":1,"type":"italic"},{"offset":4,"length":1,"type":"bold"},{"offset":4,"length":1,"type":"italic"}]}}'
|
||||
update = types.Update.de_json(sample_string_1)
|
||||
message: types.Message = update.message
|
||||
assert message.html_text == "<i><b>b </b></i><i><b>b </b></i><i><b>b</b></i>"
|
||||
|
||||
sample_string_2 = r'{"update_id":934522166,"message":{"message_id":1374526,"from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en","is_premium":true},"chat":{"id":927266710,"first_name":">_run","username":"coder2020","type":"private"},"date":1682179716,"text":"b b b","entities":[{"offset":0,"length":1,"type":"bold"},{"offset":2,"length":1,"type":"bold"},{"offset":4,"length":1,"type":"italic"}]}}'
|
||||
message_2 = types.Update.de_json(sample_string_2).message
|
||||
assert message_2.html_text == "<b>b</b> <b>b</b> <i>b</i>"
|
||||
|
||||
|
||||
|
||||
sample_string_3 = r'{"update_id":934522172,"message":{"message_id":1374530,"from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en","is_premium":true},"chat":{"id":927266710,"first_name":">_run","username":"coder2020","type":"private"},"date":1682179968,"text":"This is a bold text with a nested italic and bold text.","entities":[{"offset":10,"length":4,"type":"bold"},{"offset":27,"length":7,"type":"italic"},{"offset":34,"length":15,"type":"bold"},{"offset":34,"length":15,"type":"italic"}]}}'
|
||||
message_3 = types.Update.de_json(sample_string_3).message
|
||||
assert message_3.html_text == "This is a <b>bold</b> text with a <i>nested </i><i><b>italic and bold</b></i> text."
|
||||
|
||||
|
||||
sample_string_4 = r'{"update_id":934522437,"message":{"message_id":1374619,"from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en","is_premium":true},"chat":{"id":927266710,"first_name":">_run","username":"coder2020","type":"private"},"date":1682189507,"forward_from":{"id":927266710,"is_bot":false,"first_name":">_run","username":"coder2020","language_code":"en","is_premium":true},"forward_date":1682189124,"text":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa😋😋","entities":[{"offset":0,"length":76,"type":"bold"},{"offset":0,"length":76,"type":"italic"},{"offset":0,"length":76,"type":"underline"},{"offset":0,"length":76,"type":"strikethrough"},{"offset":76,"length":2,"type":"custom_emoji","custom_emoji_id":"5456188142006575553"},{"offset":78,"length":2,"type":"custom_emoji","custom_emoji_id":"5456188142006575553"}]}}'
|
||||
message_4 = types.Update.de_json(sample_string_4).message
|
||||
assert message_4.html_text == '<s><u><i><b>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</b></i></u></s><tg-emoji emoji-id="5456188142006575553">😋</tg-emoji><tg-emoji emoji-id="5456188142006575553">😋</tg-emoji>'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue