Compliance with bot API 9.0
Also, the repository is not hosted on GiTea
This commit is contained in:
parent
9c61b564b1
commit
6cf63716ff
@ -11,7 +11,7 @@ __author__ = "Davide Testa"
|
|||||||
__email__ = "davide@davte.it"
|
__email__ = "davide@davte.it"
|
||||||
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
|
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
|
||||||
__license__ = "GNU General Public License v3.0"
|
__license__ = "GNU General Public License v3.0"
|
||||||
__version__ = "2.10.9"
|
__version__ = "2.10.10"
|
||||||
__maintainer__ = "Davide Testa"
|
__maintainer__ = "Davide Testa"
|
||||||
__contact__ = "t.me/davte"
|
__contact__ = "t.me/davte"
|
||||||
|
|
||||||
|
@ -318,7 +318,8 @@ class InputSticker(dict):
|
|||||||
or pass “attach://<file_attach_name>” to upload a new one using
|
or pass “attach://<file_attach_name>” to upload a new one using
|
||||||
multipart/form-data under <file_attach_name> name.
|
multipart/form-data under <file_attach_name> name.
|
||||||
Animated and video stickers can't be uploaded via HTTP URL.
|
Animated and video stickers can't be uploaded via HTTP URL.
|
||||||
More information on Sending Files: https://core.telegram.org/bots/api#sending-files
|
More information on Sending Files:
|
||||||
|
https://core.telegram.org/bots/api#sending-files
|
||||||
@param format_: Format of the added sticker, must be one of “static”
|
@param format_: Format of the added sticker, must be one of “static”
|
||||||
for a .WEBP or .PNG image, “animated” for a .TGS animation,
|
for a .WEBP or .PNG image, “animated” for a .TGS animation,
|
||||||
“video” for a WEBM video
|
“video” for a WEBM video
|
||||||
@ -709,6 +710,58 @@ class InputStoryContentVideo(InputStoryContent):
|
|||||||
self[parameter] = value
|
self[parameter] = value
|
||||||
|
|
||||||
|
|
||||||
|
class InputProfilePhoto(DictToDump):
|
||||||
|
"""This object describes a profile photo to set.
|
||||||
|
|
||||||
|
Currently, it can be one of
|
||||||
|
- InputProfilePhotoStatic
|
||||||
|
- InputProfilePhotoAnimated
|
||||||
|
"""
|
||||||
|
def __init__(self, type_):
|
||||||
|
assert type_ in ('InputProfilePhotoStatic',
|
||||||
|
'InputProfilePhotoAnimated',), (
|
||||||
|
f"Invalid InputProfilePhoto type: {type_}"
|
||||||
|
)
|
||||||
|
self['type'] = type_
|
||||||
|
|
||||||
|
|
||||||
|
class InputProfilePhotoStatic(InputProfilePhoto):
|
||||||
|
"""A static profile photo in the .JPG format.
|
||||||
|
|
||||||
|
@param photo: the static profile photo. Profile photos can't be reused and
|
||||||
|
can only be uploaded as a new file, so you can pass
|
||||||
|
"attach://<file_attach_name>" if the photo was uploaded using
|
||||||
|
multipart/form-data under <file_attach_name>.
|
||||||
|
More information on Sending Files:
|
||||||
|
https://core.telegram.org/bots/api#sending-files
|
||||||
|
"""
|
||||||
|
def __init__(self, photo: str):
|
||||||
|
super().__init__(type_='static')
|
||||||
|
for parameter, value in locals().items():
|
||||||
|
if value:
|
||||||
|
self[parameter] = value
|
||||||
|
|
||||||
|
|
||||||
|
class InputProfilePhotoAnimated(InputProfilePhoto):
|
||||||
|
"""A static profile photo in the MPEG4 format.
|
||||||
|
|
||||||
|
@param animation: The animated profile photo. Profile photos can't be reused
|
||||||
|
and can only be uploaded as a new file, so you can pass
|
||||||
|
"attach://<file_attach_name>" if the photo was uploaded using
|
||||||
|
multipart/form-data under <file_attach_name>.
|
||||||
|
More information on Sending Files:
|
||||||
|
https://core.telegram.org/bots/api#sending-files
|
||||||
|
@param main_frame_timestamp: Optional. Timestamp in seconds of the frame
|
||||||
|
that will be used as the static profile photo. Defaults to 0.0.
|
||||||
|
"""
|
||||||
|
def __init__(self, animation: str,
|
||||||
|
main_frame_timestamp: float = None):
|
||||||
|
super().__init__(type_='animated')
|
||||||
|
for parameter, value in locals().items():
|
||||||
|
if value:
|
||||||
|
self[parameter] = value
|
||||||
|
|
||||||
|
|
||||||
def handle_deprecated_disable_web_page_preview(parameters: dict,
|
def handle_deprecated_disable_web_page_preview(parameters: dict,
|
||||||
kwargs: dict):
|
kwargs: dict):
|
||||||
if 'disable_web_page_preview' in kwargs:
|
if 'disable_web_page_preview' in kwargs:
|
||||||
@ -3625,6 +3678,166 @@ class TelegramBot:
|
|||||||
parameters=locals()
|
parameters=locals()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def giftPremiumSubscription(
|
||||||
|
self, user_id: int,
|
||||||
|
month_count: int, star_count: int,
|
||||||
|
text: str = None,
|
||||||
|
text_parse_mode: str = None,
|
||||||
|
text_entities: List['MessageEntity'] = None
|
||||||
|
):
|
||||||
|
"""Gifts a Telegram Premium subscription to the given user.
|
||||||
|
|
||||||
|
Returns True on success.
|
||||||
|
See https://core.telegram.org/bots/api#giftpremiumsubscription for details.
|
||||||
|
"""
|
||||||
|
if star_count not in (1000, 1500, 2500):
|
||||||
|
logging.warning("Star count should be 1000 for three months, 1500 "
|
||||||
|
"for 6 months or 2000 for 12 months")
|
||||||
|
return await self.api_request(
|
||||||
|
'giftPremiumSubscription',
|
||||||
|
parameters=locals()
|
||||||
|
)
|
||||||
|
|
||||||
|
async def readBusinessMessage(self,
|
||||||
|
business_connection_id: str,
|
||||||
|
chat_id: int,
|
||||||
|
message_id: int):
|
||||||
|
"""Marks incoming message as read on behalf of a business account.
|
||||||
|
|
||||||
|
Requires the can_read_messages business bot right.
|
||||||
|
Returns True on success.
|
||||||
|
See https://core.telegram.org/bots/api#readbusinessmessage for details.
|
||||||
|
"""
|
||||||
|
return await self.api_request(
|
||||||
|
'readBusinessMessage',
|
||||||
|
parameters=locals()
|
||||||
|
)
|
||||||
|
|
||||||
|
async def deleteBusinessMessages(self,
|
||||||
|
business_connection_id: str,
|
||||||
|
message_ids: List[int]):
|
||||||
|
"""Delete messages on behalf of a business account.
|
||||||
|
|
||||||
|
Requires the can_delete_outgoing_messages business bot right to delete
|
||||||
|
messages sent by the bot itself, or the can_delete_all_messages
|
||||||
|
business bot right to delete any message.
|
||||||
|
Returns True on success.
|
||||||
|
See https://core.telegram.org/bots/api#deletebusinessmessages for details.
|
||||||
|
"""
|
||||||
|
return await self.api_request(
|
||||||
|
'deleteBusinessMessages',
|
||||||
|
parameters=locals()
|
||||||
|
)
|
||||||
|
|
||||||
|
async def setBusinessAccountName(self,
|
||||||
|
business_connection_id: str,
|
||||||
|
first_name: str,
|
||||||
|
last_name: str = None):
|
||||||
|
"""Changes the first and last name of a managed business account.
|
||||||
|
|
||||||
|
Requires the can_change_name business bot right.
|
||||||
|
Returns True on success.
|
||||||
|
See https://core.telegram.org/bots/api#setbusinessaccountname for details.
|
||||||
|
"""
|
||||||
|
return await self.api_request(
|
||||||
|
'setBusinessAccountName',
|
||||||
|
parameters=locals()
|
||||||
|
)
|
||||||
|
|
||||||
|
async def setBusinessAccountUsername(self,
|
||||||
|
business_connection_id: str,
|
||||||
|
username: str = None):
|
||||||
|
"""Changes the username of a managed business account.
|
||||||
|
|
||||||
|
Requires the can_change_username business bot right.
|
||||||
|
Returns True on success.
|
||||||
|
See https://core.telegram.org/bots/api#setbusinessaccountusername for details.
|
||||||
|
"""
|
||||||
|
return await self.api_request(
|
||||||
|
'setBusinessAccountUsername',
|
||||||
|
parameters=locals()
|
||||||
|
)
|
||||||
|
|
||||||
|
async def setBusinessAccountBio(self,
|
||||||
|
business_connection_id: str,
|
||||||
|
bio: str = None):
|
||||||
|
"""Changes the bio of a managed business account.
|
||||||
|
|
||||||
|
Requires the can_change_bio business bot right.
|
||||||
|
Returns True on success.
|
||||||
|
See https://core.telegram.org/bots/api#setbusinessaccountbio for details.
|
||||||
|
"""
|
||||||
|
return await self.api_request(
|
||||||
|
'setBusinessAccountBio',
|
||||||
|
parameters=locals()
|
||||||
|
)
|
||||||
|
|
||||||
|
async def setBusinessAccountProfilePhoto(self,
|
||||||
|
business_connection_id: str,
|
||||||
|
photo: 'InputProfilePhoto',
|
||||||
|
is_public: bool = None):
|
||||||
|
"""Changes the profile photo of a managed business account.
|
||||||
|
|
||||||
|
Requires the can_edit_profile_photo business bot right.
|
||||||
|
Returns True on success.
|
||||||
|
See https://core.telegram.org/bots/api#setbusinessaccountprofilephoto for details.
|
||||||
|
"""
|
||||||
|
return await self.api_request(
|
||||||
|
'setBusinessAccountProfilePhoto',
|
||||||
|
parameters=locals()
|
||||||
|
)
|
||||||
|
|
||||||
|
async def removeBusinessAccountProfilePhoto(self, business_connection_id: str, is_public: bool):
|
||||||
|
"""Removes the current profile photo of a managed business account.
|
||||||
|
|
||||||
|
Requires the can_edit_profile_photo business bot right.
|
||||||
|
Returns True on success.
|
||||||
|
See https://core.telegram.org/bots/api#removebusinessaccountprofilephoto for details.
|
||||||
|
"""
|
||||||
|
return await self.api_request(
|
||||||
|
'removeBusinessAccountProfilePhoto',
|
||||||
|
parameters=locals()
|
||||||
|
)
|
||||||
|
|
||||||
|
async def setBusinessAccountGiftSettings(self, business_connection_id: str, show_gift_button: bool, accepted_gift_types: 'AcceptedGiftTypes'):
|
||||||
|
"""Changes the privacy settings pertaining to incoming gifts in a managed
|
||||||
|
business account.
|
||||||
|
|
||||||
|
Requires the can_change_gift_settings business bot right.
|
||||||
|
Returns True on success.
|
||||||
|
See https://core.telegram.org/bots/api#setbusinessaccountgiftsettings for details.
|
||||||
|
"""
|
||||||
|
return await self.api_request(
|
||||||
|
'setBusinessAccountGiftSettings',
|
||||||
|
parameters=locals()
|
||||||
|
)
|
||||||
|
|
||||||
|
async def getBusinessAccountStarBalance(self, business_connection_id: str):
|
||||||
|
"""Returns the amount of Telegram Stars owned by a managed business
|
||||||
|
account.
|
||||||
|
|
||||||
|
Requires the can_view_gifts_and_stars business bot right.
|
||||||
|
Returns StarAmount on success.
|
||||||
|
See https://core.telegram.org/bots/api#getbusinessaccountstarbalance for details.
|
||||||
|
"""
|
||||||
|
return await self.api_request(
|
||||||
|
'getBusinessAccountStarBalance',
|
||||||
|
parameters=locals()
|
||||||
|
)
|
||||||
|
|
||||||
|
async def transferBusinessAccountStars(self, business_connection_id: str, star_count: int):
|
||||||
|
"""Transfers Telegram Stars from the business account balance to the bot's
|
||||||
|
balance.
|
||||||
|
|
||||||
|
Requires the can_transfer_stars business bot right.
|
||||||
|
Returns True on success.
|
||||||
|
See https://core.telegram.org/bots/api#transferbusinessaccountstars for details.
|
||||||
|
"""
|
||||||
|
return await self.api_request(
|
||||||
|
'transferBusinessAccountStars',
|
||||||
|
parameters=locals()
|
||||||
|
)
|
||||||
|
|
||||||
async def getBusinessAccountGifts(self,
|
async def getBusinessAccountGifts(self,
|
||||||
business_connection_id: str,
|
business_connection_id: str,
|
||||||
exclude_unsaved: bool = None,
|
exclude_unsaved: bool = None,
|
||||||
|
@ -25,6 +25,7 @@ class TelegramApiMethod(object):
|
|||||||
'Boolean': "bool",
|
'Boolean': "bool",
|
||||||
'Integer': "int",
|
'Integer': "int",
|
||||||
'Integer or String': "Union[int, str]",
|
'Integer or String': "Union[int, str]",
|
||||||
|
'Array of Integer': "List[str]",
|
||||||
'String': "str",
|
'String': "str",
|
||||||
}
|
}
|
||||||
"""Telegram bot API method."""
|
"""Telegram bot API method."""
|
||||||
@ -55,14 +56,15 @@ class TelegramApiMethod(object):
|
|||||||
for n, paragraph in enumerate(self.description.replace('.', '.\n').split('\n')):
|
for n, paragraph in enumerate(self.description.replace('.', '.\n').split('\n')):
|
||||||
additional_indentation = 0
|
additional_indentation = 0
|
||||||
if n == 0 and paragraph.startswith(redundant_string):
|
if n == 0 and paragraph.startswith(redundant_string):
|
||||||
paragraph = paragraph[len(redundant_string)].upper() + paragraph[len(redundant_string)+1:]
|
paragraph = (paragraph[len(redundant_string)].upper()
|
||||||
|
+ paragraph[len(redundant_string)+1:])
|
||||||
for word in paragraph.split(' '):
|
for word in paragraph.split(' '):
|
||||||
if len(current_line) + len(word) > 80 - indentation - additional_indentation:
|
if len(current_line) + len(word) > 80 - indentation - additional_indentation:
|
||||||
additional_indentation = max(additional_indentation, 4)
|
additional_indentation = max(additional_indentation, 4)
|
||||||
result += f"{current_line.strip()}\n{' ' * additional_indentation}"
|
result += f"{current_line.strip()}\n{' ' * additional_indentation}"
|
||||||
current_line = ""
|
current_line = ""
|
||||||
current_line += f"{word} "
|
current_line += f"{word} "
|
||||||
if len(current_line):
|
if len(current_line) > 0:
|
||||||
result += f"{current_line.strip()}\n"
|
result += f"{current_line.strip()}\n"
|
||||||
current_line = ""
|
current_line = ""
|
||||||
if n == 0:
|
if n == 0:
|
||||||
@ -203,7 +205,7 @@ async def print_api_methods(filename=None,
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
if output_file:
|
if output_file:
|
||||||
with open(output_file, 'w') as file:
|
with open(output_file, 'w', encoding="utf-8") as file:
|
||||||
if new_methods:
|
if new_methods:
|
||||||
file.write(
|
file.write(
|
||||||
"from typing import List, Union\n"
|
"from typing import List, Union\n"
|
||||||
|
2
setup.py
2
setup.py
@ -51,7 +51,7 @@ setuptools.setup(
|
|||||||
license=find_information("license", "davtelepot", "__init__.py"),
|
license=find_information("license", "davtelepot", "__init__.py"),
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
url="https://gogs.davte.it/davte/davtelepot",
|
url="https://gitea.davte.it/davte/davtelepot",
|
||||||
packages=setuptools.find_packages(),
|
packages=setuptools.find_packages(),
|
||||||
platforms=['any'],
|
platforms=['any'],
|
||||||
install_requires=[
|
install_requires=[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user