Compare commits
127 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
53802728a1
|
|||
|
2cdb4e743f
|
|||
|
98fbbf0127
|
|||
|
856d53de1c
|
|||
|
5e8a2b65f5
|
|||
|
3b0bfb4880
|
|||
|
a49e727e31
|
|||
|
c78522d46b
|
|||
|
c4964105b4
|
|||
|
3396bc6f18
|
|||
|
c1f4abc541
|
|||
|
c4a822e45d
|
|||
|
6b4a95be36
|
|||
|
beaf3f8516
|
|||
|
fc1f087d4a
|
|||
|
aeac4aea52
|
|||
|
5ab22909cf
|
|||
|
9094955812
|
|||
|
173783e154
|
|||
|
92a986d090
|
|||
|
3e6e364336
|
|||
|
f0a4c914e4
|
|||
|
80a1440e75
|
|||
|
b978022658
|
|||
|
50f561e7f9
|
|||
|
a9b785f49d
|
|||
|
b7d08ab2ba
|
|||
|
d362ec496b
|
|||
|
0bfc1e157b
|
|||
|
bc40957b27
|
|||
|
45117610f9
|
|||
|
f91661927e
|
|||
|
12f3a2cc73
|
|||
|
25abb80343
|
|||
|
76ea65a660
|
|||
|
e254dbf42a
|
|||
|
b7b91a65ea
|
|||
|
abebff43d9
|
|||
|
a460f71b69
|
|||
|
6ad5ec2865
|
|||
|
cfae729270
|
|||
|
dc9c2a7b14
|
|||
|
a3cc676432
|
|||
|
15a7a58537
|
|||
|
ea30fd39cf
|
|||
|
a5cabdd102
|
|||
|
89fa73d1a5
|
|||
|
4b22658bf5
|
|||
|
bce8cff3cf
|
|||
|
ea07aa47cf
|
|||
|
d49bab54ca
|
|||
|
83d01e4da9
|
|||
|
59dde0d25e
|
|||
|
713f4ffd0e
|
|||
|
51bc95332f
|
|||
|
92758d923c
|
|||
|
946e2a881f
|
|||
|
|
0f4d31892f
|
||
|
|
c4eaa0b9db | ||
|
|
21214feb0a | ||
|
|
f7ee5b71a1 | ||
|
|
fb58c0239d | ||
|
|
c848bfc228 | ||
|
|
f823057cbe | ||
|
|
d7a1acd23b | ||
|
|
70053c9279 | ||
|
|
1c76c7d797 | ||
|
|
dfffbff7c6 | ||
|
|
a4b1ed09a2 | ||
|
|
a1bd681cbf | ||
|
|
9c57677320 | ||
|
|
956e982157 | ||
|
|
4bd10894a8 | ||
|
|
89a9863510 | ||
|
|
ed36e53a28 | ||
|
|
8977e0fbc3 | ||
|
|
cf7e0c740b | ||
|
|
12b18cff58 | ||
|
|
3160723aa7 | ||
|
|
8e2feb5ac2 | ||
|
|
cbc7424a97 | ||
|
|
1e7c384b6d | ||
|
|
7cc2e02f47 | ||
|
|
6315c0dcc2 | ||
|
|
f06c525f5b | ||
|
|
ea5c63c1f8 | ||
|
|
ea549b63c8 | ||
|
|
e63b0f9265 | ||
|
|
cb9310437f | ||
|
|
5bc58dd7d5 | ||
|
|
5d35579e10 | ||
|
|
b0132e0b30 | ||
|
|
49ecee63d0 | ||
|
|
273eda2b67 | ||
|
|
b12f653096 | ||
|
|
05878f3fbd | ||
|
|
c583c3c3b0 | ||
|
|
2d40903069 | ||
|
|
217a445a65 | ||
|
|
b68dbe7a07 | ||
|
|
258ca9f6ef | ||
|
|
3648a36636 | ||
|
|
ef99493c7f | ||
|
|
841f7f0c8d | ||
|
|
23882e5b3b | ||
|
|
6ba21f0115 | ||
|
|
ca6dca3cb7 | ||
|
|
9072c3abe5 | ||
|
|
e74e38c6ae | ||
|
|
7a23045479 | ||
|
|
5ef449a542 | ||
|
|
a2c83f8d9c | ||
|
|
dddaf20ea2 | ||
|
|
a828bb5d3c | ||
|
|
25f5514dff | ||
|
|
34f802732b | ||
|
|
f6466b0540 | ||
|
|
7565df17ba | ||
|
|
4be33370b9 | ||
|
|
cf3f7a88fb | ||
|
|
a4d464da58 | ||
|
|
83c0a91919 | ||
|
|
85a5ce3882 | ||
|
|
77405d2dd3 | ||
|
|
1e2316e748 | ||
|
|
16014c5a42 | ||
|
|
f0be5b5ff2 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -41,7 +41,6 @@ __pycache__/
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
.venv/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
|
||||
@@ -11,7 +11,7 @@ __author__ = "Davide Testa"
|
||||
__email__ = "davide@davte.it"
|
||||
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
|
||||
__license__ = "GNU General Public License v3.0"
|
||||
__version__ = "2.10.11"
|
||||
__version__ = "2.10.6"
|
||||
__maintainer__ = "Davide Testa"
|
||||
__contact__ = "t.me/davte"
|
||||
|
||||
|
||||
@@ -836,8 +836,7 @@ def get_maintenance_exception_criterion(bot, allowed_command):
|
||||
|
||||
|
||||
async def get_last_commit():
|
||||
"""Get last commit hash and message."""
|
||||
last_commit_message = None
|
||||
"""Get last commit hash and davtelepot version."""
|
||||
try:
|
||||
_subprocess = await asyncio.create_subprocess_exec(
|
||||
'git', 'rev-parse', 'HEAD',
|
||||
@@ -845,22 +844,12 @@ async def get_last_commit():
|
||||
stderr=asyncio.subprocess.STDOUT
|
||||
)
|
||||
stdout, _ = await _subprocess.communicate()
|
||||
last_commit_hash = stdout.decode().strip()
|
||||
last_commit = stdout.decode().strip()
|
||||
except Exception as e:
|
||||
last_commit_hash = f"{e}"
|
||||
try:
|
||||
_subprocess = await asyncio.create_subprocess_exec(
|
||||
'git', 'log', '--pretty=%B', "-n", "1", last_commit_hash,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.STDOUT
|
||||
)
|
||||
stdout, _ = await _subprocess.communicate()
|
||||
last_commit_message = stdout.decode().strip()
|
||||
except Exception:
|
||||
pass
|
||||
if last_commit_hash.startswith("fatal: not a git repository"):
|
||||
last_commit_hash = "-"
|
||||
return last_commit_hash, last_commit_message
|
||||
last_commit = f"{e}"
|
||||
if last_commit.startswith("fatal: not a git repository"):
|
||||
last_commit = "-"
|
||||
return last_commit
|
||||
|
||||
|
||||
async def get_new_versions(bot: Bot,
|
||||
@@ -910,15 +899,12 @@ async def get_new_versions(bot: Bot,
|
||||
|
||||
async def version_command(bot: Bot, update: dict,
|
||||
user_record: OrderedDict, language: str):
|
||||
last_commit_hash, last_commit_message = await get_last_commit()
|
||||
last_commit = await get_last_commit()
|
||||
text = bot.get_message(
|
||||
'admin', 'version_command', 'header',
|
||||
last_commit=last_commit_hash,
|
||||
last_commit=last_commit,
|
||||
update=update, user_record=user_record
|
||||
)
|
||||
if last_commit_message:
|
||||
text += "\n<i>" + last_commit_message + "</i>"
|
||||
text += "\n\n"
|
||||
) + '\n\n'
|
||||
text += f'<b>Python: </b> <code>{platform.python_version()}</code>\n'
|
||||
text += '\n'.join(
|
||||
f"<b>{package.__name__}</b>: "
|
||||
@@ -961,7 +947,7 @@ async def notify_new_version(bot: Bot):
|
||||
|
||||
Notify admins when last commit and/or davtelepot version change.
|
||||
"""
|
||||
last_commit_hash, last_commit_message = await get_last_commit()
|
||||
last_commit = await get_last_commit()
|
||||
old_record = bot.db['version_history'].find_one(
|
||||
order_by=['-id']
|
||||
)
|
||||
@@ -969,7 +955,7 @@ async def notify_new_version(bot: Bot):
|
||||
f"{package.__name__}_version": get_package_version(package)
|
||||
for package in bot.packages
|
||||
}
|
||||
current_versions['last_commit'] = last_commit_hash
|
||||
current_versions['last_commit'] = last_commit
|
||||
if old_record is None:
|
||||
old_record = dict(
|
||||
updated_at=datetime.datetime.min,
|
||||
@@ -992,16 +978,13 @@ async def notify_new_version(bot: Bot):
|
||||
'admin', 'new_version', 'title',
|
||||
user_record=admin
|
||||
) + '\n\n'
|
||||
if last_commit_hash != old_record['last_commit']:
|
||||
if last_commit != old_record['last_commit']:
|
||||
text += bot.get_message(
|
||||
'admin', 'new_version', 'last_commit',
|
||||
old_record=old_record,
|
||||
new_record=current_versions,
|
||||
user_record=admin
|
||||
)
|
||||
if last_commit_message:
|
||||
text += f"\n<i>{last_commit_message}</i>"
|
||||
text += "\n\n"
|
||||
) + '\n\n'
|
||||
text += '\n'.join(
|
||||
f"<b>{name[:-len('_version')]}</b>: "
|
||||
f"<code>{old_record[name]}</code> —> "
|
||||
@@ -1907,8 +1890,6 @@ async def create_promotion_command(bot: Bot):
|
||||
of the machine running the bot.
|
||||
"""
|
||||
await bot.get_me()
|
||||
if len(bot.administrators) > 0:
|
||||
return
|
||||
bot.administration_token = get_secure_key(length=10)
|
||||
print(f"To become administrator click "
|
||||
f"https://t.me/{bot.name}?start="
|
||||
@@ -2151,4 +2132,6 @@ def init(telegram_bot: Bot,
|
||||
update=update,
|
||||
user_record=user_record,
|
||||
language=language)
|
||||
asyncio.ensure_future(create_promotion_command(bot=telegram_bot))
|
||||
|
||||
if len(telegram_bot.administrators) == 0:
|
||||
asyncio.ensure_future(create_promotion_command(bot=telegram_bot))
|
||||
|
||||
@@ -318,8 +318,7 @@ class InputSticker(dict):
|
||||
or pass “attach://<file_attach_name>” to upload a new one using
|
||||
multipart/form-data under <file_attach_name> name.
|
||||
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”
|
||||
for a .WEBP or .PNG image, “animated” for a .TGS animation,
|
||||
“video” for a WEBM video
|
||||
@@ -404,9 +403,9 @@ class ReactionType(DictToDump):
|
||||
emoji: str = None,
|
||||
custom_emoji_id: str = None):
|
||||
super().__init__(self)
|
||||
if type_ not in ('emoji', 'custom_emoji', 'paid'):
|
||||
if type_ not in ('emoji', 'custom_emoji'):
|
||||
raise TypeError(
|
||||
f"ReactionType must be `emoji`, `custom_emoji` or `paid`.\n"
|
||||
f"ReactionType must be `emoji` or `custom_emoji`.\n"
|
||||
f"Unknown type {type_}"
|
||||
)
|
||||
self['type'] = type_
|
||||
@@ -419,7 +418,7 @@ class ReactionType(DictToDump):
|
||||
self['emoji'] = emoji
|
||||
elif custom_emoji_id:
|
||||
self['custom_emoji_id'] = custom_emoji_id
|
||||
elif type_ != 'paid':
|
||||
else:
|
||||
raise TypeError(
|
||||
"At least one of the two fields `emoji` or `custom_emoji` "
|
||||
"must be provided and not None."
|
||||
@@ -458,310 +457,6 @@ class InputPaidMediaVideo(InputPaidMedia):
|
||||
self['supports_streaming'] = supports_streaming
|
||||
|
||||
|
||||
class MessageEntity(DictToDump):
|
||||
def __init__(self,
|
||||
type_: str,
|
||||
offset: int,
|
||||
length: int,
|
||||
url: str,
|
||||
user: 'User',
|
||||
language: str,
|
||||
custom_emoji_id: str):
|
||||
super().__init__()
|
||||
self['type'] = type_
|
||||
self['offset'] = offset
|
||||
self['length'] = length
|
||||
self['url'] = url
|
||||
self['user'] = user
|
||||
self['language'] = language
|
||||
self['custom_emoji_id'] = custom_emoji_id
|
||||
|
||||
|
||||
class PreparedInlineMessage(DictToDump):
|
||||
"""Describes an inline message to be sent by a user of a Mini App.
|
||||
|
||||
Attributes:
|
||||
id (str): Unique identifier of the prepared message
|
||||
expiration_date (int): Expiration date of the prepared message,
|
||||
in Unix time. Expired prepared messages can no longer be used.
|
||||
"""
|
||||
def __init__(self,
|
||||
id: str,
|
||||
expiration_date: int):
|
||||
super().__init__()
|
||||
self['id'] = id
|
||||
self['expiration_date'] = expiration_date
|
||||
|
||||
|
||||
class StoryAreaPosition(DictToDump):
|
||||
"""Describes the position of a clickable area within a story.
|
||||
|
||||
@param x_percentage: The abscissa of the area's center, as a percentage of
|
||||
the media width
|
||||
@param y_percentage: The ordinate of the area's center, as a percentage of
|
||||
the media height
|
||||
@param width_percentage: The width of the area's rectangle, as a percentage
|
||||
of the media width
|
||||
@param height_percentage: The height of the area's rectangle, as a
|
||||
percentage of the media height
|
||||
@param rotation_angle: The clockwise rotation angle of the rectangle, in
|
||||
degrees; 0-360
|
||||
@param corner_radius_percentage: The radius of the rectangle corner
|
||||
rounding, as a percentage of the media width
|
||||
"""
|
||||
def __init__(self,x_percentage: float = None,
|
||||
y_percentage: float = None,
|
||||
width_percentage: float = None,
|
||||
height_percentage: float = None,
|
||||
rotation_angle: float = None,
|
||||
corner_radius_percentage: float = None):
|
||||
super().__init__()
|
||||
for parameter, value in locals().items():
|
||||
if value:
|
||||
self[parameter] = value
|
||||
|
||||
|
||||
class StoryAreaType(DictToDump):
|
||||
"""Describes the type of a clickable area on a story.
|
||||
|
||||
Currently, it can be one of:
|
||||
- StoryAreaTypeLocation
|
||||
- StoryAreaTypeSuggestedReaction
|
||||
- StoryAreaTypeLink
|
||||
- StoryAreaTypeWeather
|
||||
- StoryAreaTypeUniqueGift
|
||||
"""
|
||||
def __init__(self, type_):
|
||||
assert type_ in ('location',
|
||||
'suggested_reaction',
|
||||
'link',
|
||||
'weather',
|
||||
'unique_gift'), (
|
||||
f"Invalid StoryAreaType: {type_}"
|
||||
)
|
||||
self['type'] = type_
|
||||
|
||||
|
||||
class LocationAddress(DictToDump):
|
||||
"""Describes the physical address of a location.
|
||||
|
||||
@param country_code: the two-letter ISO 3166-1 alpha-2 country code of the
|
||||
country where the location is located
|
||||
@param state (optional): state of the location
|
||||
@param city (optional): city of the location
|
||||
@param street(optional): street address of the location
|
||||
"""
|
||||
def __init__(self, country_code: str,
|
||||
state: str = None,
|
||||
city: str = None, street: str = None):
|
||||
assert len(f"{country_code}") == 2, (
|
||||
f"Invalid country code: {country_code}"
|
||||
)
|
||||
super().__init__()
|
||||
for parameter, value in locals().items():
|
||||
if value:
|
||||
self[parameter] = value
|
||||
|
||||
|
||||
|
||||
class StoryAreaTypeLocation(StoryAreaType):
|
||||
"""Describes a story area pointing to a location.
|
||||
|
||||
Currently, a story can have up to 10 location areas.
|
||||
@param latitude: location latitude in degrees
|
||||
@param longitude: location longitude in degrees
|
||||
@param address: Optional. Address of the location
|
||||
"""
|
||||
def __init__(self, latitude: float, longitude: float,
|
||||
address: 'LocationAddress' = None):
|
||||
super().__init__(type_='location')
|
||||
for parameter, value in locals().items():
|
||||
if value:
|
||||
self[parameter] = value
|
||||
|
||||
|
||||
class StoryAreaTypeSuggestedReaction(StoryAreaType):
|
||||
"""Describes a story area pointing to a suggested reaction.
|
||||
|
||||
Currently, a story can have up to 5 suggested reaction areas.
|
||||
@param reaction_type: type of the reaction
|
||||
@param is_dark: pass True if the reaction area has a dark background
|
||||
@param is_flipped: pass True if reaction area corner is flipped
|
||||
"""
|
||||
def __init__(self, reaction_type: 'ReactionType',
|
||||
is_dark: bool = None,
|
||||
is_flipped: bool = None):
|
||||
super().__init__(type_='suggested_reaction')
|
||||
for parameter, value in locals().items():
|
||||
if value is not None:
|
||||
self[parameter] = value
|
||||
|
||||
|
||||
class StoryAreaTypeLink(StoryAreaType):
|
||||
"""Describes a story area pointing to an HTTP or tg:// link.
|
||||
|
||||
Currently, a story can have up to 3 link areas.
|
||||
@param url: HTTP or tg:// URL to be opened when the area is clicked
|
||||
"""
|
||||
def __init__(self, url: str):
|
||||
super().__init__(type_='link')
|
||||
self['url'] = url
|
||||
|
||||
|
||||
class StoryAreaTypeWeather(StoryAreaType):
|
||||
"""Describes a story area containing weather information.
|
||||
|
||||
Currently, a story can have up to 3 weather areas.
|
||||
Parameters:
|
||||
@param temperature: temperature, in degree Celsius
|
||||
@param emoji: emoji representing the weather
|
||||
@param background_color: a color of the area background in the ARGB format
|
||||
"""
|
||||
def __init__(self, temperature: float, emoji: str, background_color: int):
|
||||
super().__init__(type_='weather')
|
||||
for parameter, value in locals().items():
|
||||
if value:
|
||||
self[parameter] = value
|
||||
|
||||
|
||||
class StoryAreaTypeUniqueGift(StoryAreaType):
|
||||
"""Describes a story area pointing to a unique gift.
|
||||
|
||||
Currently, a story can have at most 1 unique gift area.
|
||||
@param name: unique name of the gift
|
||||
"""
|
||||
def __init__(self, name):
|
||||
super().__init__(type_='unique_gift')
|
||||
for parameter, value in locals().items():
|
||||
if value:
|
||||
self[parameter] = value
|
||||
|
||||
|
||||
class StoryArea(DictToDump):
|
||||
"""Describes a clickable area on a story media.
|
||||
|
||||
@param position: Position of the area
|
||||
@param type: Type of the area
|
||||
"""
|
||||
def __init__(self,
|
||||
position: 'StoryAreaPosition',
|
||||
type_: 'StoryAreaType'):
|
||||
super().__init__()
|
||||
self['position'] = position
|
||||
self['type'] = type_
|
||||
|
||||
|
||||
class InputStoryContent(DictToDump):
|
||||
"""This object describes the content of a story to post.
|
||||
|
||||
Currently, it can be one of
|
||||
- InputStoryContentPhoto
|
||||
- InputStoryContentVideo
|
||||
"""
|
||||
def __init__(self, type_):
|
||||
assert type_ in ('photo',
|
||||
'video',), (
|
||||
f"Invalid InputStoryContent type: {type_}"
|
||||
)
|
||||
self['type'] = type_
|
||||
|
||||
|
||||
class InputStoryContentPhoto(InputStoryContent):
|
||||
"""Describes a photo to post as a story.
|
||||
|
||||
@param photo: the photo to post as a story. The photo must be of the size
|
||||
1080x1920 and must not exceed 10 MB. The photo 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: https://core.telegram.org/bots/api#sending-files
|
||||
"""
|
||||
def __init__(self, photo: str):
|
||||
super().__init__(type_='photo')
|
||||
for parameter, value in locals().items():
|
||||
if value:
|
||||
self[parameter] = value
|
||||
|
||||
|
||||
class InputStoryContentVideo(InputStoryContent):
|
||||
"""Describes a video to post as a story.
|
||||
|
||||
@param video: The video to post as a story. The video must be of the size
|
||||
720x1280, streamable, encoded with H.265 codec, with key frames added
|
||||
each second in the MPEG4 format, and must not exceed 30 MB. The video
|
||||
can't be reused and can only be uploaded as a new file, so you can pass
|
||||
“attach://<file_attach_name>” if the video was uploaded using
|
||||
multipart/form-data under <file_attach_name>.
|
||||
More information: https://core.telegram.org/bots/api#sending-files
|
||||
@param duration: Optional. Precise duration of the video in seconds; 0-60
|
||||
@param cover_frame_timestamp: Optional. Timestamp in seconds of the frame
|
||||
that will be used as the static cover for the story. Defaults to 0.0.
|
||||
@param is_animation: Optional. Pass True if the video has no sound
|
||||
|
||||
More information: https://core.telegram.org/bots/api#sending-files
|
||||
"""
|
||||
def __init__(self, video: str, duration: float = None,
|
||||
cover_frame_timestamp: float = None,
|
||||
is_animation: bool = None):
|
||||
super().__init__(type_='photo')
|
||||
for parameter, value in locals().items():
|
||||
if value is not None:
|
||||
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,
|
||||
kwargs: dict):
|
||||
if 'disable_web_page_preview' in kwargs:
|
||||
@@ -1222,7 +917,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send a text message. On success, return it.
|
||||
|
||||
@@ -1246,8 +940,7 @@ class TelegramBot:
|
||||
message_id: int,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
disable_notification: bool = None,
|
||||
video_start_timestamp: int = None):
|
||||
disable_notification: bool = None):
|
||||
"""Forward a message.
|
||||
|
||||
See https://core.telegram.org/bots/api#forwardmessage for details.
|
||||
@@ -1270,7 +963,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send a photo from file_id, HTTP url or file.
|
||||
|
||||
@@ -1300,7 +992,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send an audio file from file_id, HTTP url or file.
|
||||
|
||||
@@ -1333,7 +1024,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send a document from file_id, HTTP url or file.
|
||||
|
||||
@@ -1371,9 +1061,6 @@ class TelegramBot:
|
||||
has_spoiler: bool = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
start_timestamp: int = None,
|
||||
cover=None,
|
||||
**kwargs):
|
||||
"""Send a video from file_id, HTTP url or file.
|
||||
|
||||
@@ -1410,7 +1097,6 @@ class TelegramBot:
|
||||
has_spoiler: bool = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send animation files (GIF or H.264/MPEG-4 AVC video without sound).
|
||||
|
||||
@@ -1442,7 +1128,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send an audio file to be displayed as playable voice message.
|
||||
|
||||
@@ -1469,7 +1154,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send a rounded square mp4 video message of up to 1 minute long.
|
||||
|
||||
@@ -1496,7 +1180,6 @@ class TelegramBot:
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send a group of photos or videos as an album.
|
||||
|
||||
@@ -1526,7 +1209,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send a point on the map. May be kept updated for a `live_period`.
|
||||
|
||||
@@ -1614,7 +1296,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send information about a venue.
|
||||
|
||||
@@ -1642,7 +1323,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send a phone contact.
|
||||
|
||||
@@ -1680,7 +1360,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send a native poll in a group, a supergroup or channel.
|
||||
|
||||
@@ -2202,7 +1881,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send `.webp` stickers.
|
||||
|
||||
@@ -2422,7 +2100,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send an invoice.
|
||||
|
||||
@@ -2503,7 +2180,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send a game.
|
||||
|
||||
@@ -2571,7 +2247,6 @@ class TelegramBot:
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
**kwargs):
|
||||
"""Send a dice.
|
||||
|
||||
@@ -2721,8 +2396,6 @@ class TelegramBot:
|
||||
disable_notification: bool = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
video_start_timestamp: int = None,
|
||||
**kwargs):
|
||||
"""Use this method to copy messages of any kind.
|
||||
|
||||
@@ -3085,27 +2758,11 @@ class TelegramBot:
|
||||
need_shipping_address: bool,
|
||||
send_phone_number_to_provider: bool,
|
||||
send_email_to_provider: bool,
|
||||
is_flexible: bool,
|
||||
business_connection_id: str = None,
|
||||
subscription_period: int = None
|
||||
):
|
||||
is_flexible: bool):
|
||||
"""Use this method to create a link for an invoice.
|
||||
|
||||
Returns the created invoice link as String on success. See
|
||||
https://core.telegram.org/bots/api#createinvoicelink for details.
|
||||
|
||||
Attributes:
|
||||
business_connection_id (Optional[str]): Unique identifier of the
|
||||
business connection on behalf of which the link will be created.
|
||||
For payments in Telegram Stars only.
|
||||
subscription_period (Optional[int]): The number of seconds the
|
||||
subscription will be active for before the next payment. The
|
||||
currency must be set to “XTR” (Telegram Stars) if the parameter
|
||||
is used. Currently, it must always be 2592000 (30 days) if
|
||||
specified. Any number of subscriptions can be active for a given
|
||||
bot at the same time, including multiple concurrent
|
||||
subscriptions from the same user.
|
||||
Subscription price must no exceed 2500 Telegram Stars.
|
||||
Returns the created invoice link as String on success.
|
||||
See https://core.telegram.org/bots/api#createinvoicelink for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'createInvoiceLink',
|
||||
@@ -3452,7 +3109,6 @@ class TelegramBot:
|
||||
|
||||
async def sendPaidMedia(self, chat_id: Union[int, str], star_count: int,
|
||||
media: List[InputPaidMedia],
|
||||
payload: str = None,
|
||||
business_connection_id: str = None,
|
||||
caption: str = None, parse_mode: str = None,
|
||||
caption_entities: List[dict] = None,
|
||||
@@ -3460,7 +3116,6 @@ class TelegramBot:
|
||||
disable_notification: bool = None,
|
||||
protect_content: bool = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
allow_paid_broadcast: bool = None,
|
||||
reply_markup = None):
|
||||
"""Send paid media to channel chats.
|
||||
|
||||
@@ -3533,425 +3188,3 @@ class TelegramBot:
|
||||
'editChatSubscriptionInviteLink',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def setUserEmojiStatus(self, user_id: int,
|
||||
emoji_status_custom_emoji_id: str = None,
|
||||
emoji_status_expiration_date: int = None):
|
||||
"""Changes the emoji status for a given user that previously allowed the
|
||||
bot to manage their emoji status via the Mini App method
|
||||
requestEmojiStatusAccess.
|
||||
|
||||
Returns True on success.
|
||||
See https://core.telegram.org/bots/api#setuseremojistatus for details.
|
||||
"""
|
||||
if emoji_status_custom_emoji_id is None:
|
||||
emoji_status_custom_emoji_id = ''
|
||||
return await self.api_request(
|
||||
'setUserEmojiStatus',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def getAvailableGifts(self):
|
||||
"""Returns the list of gifts that can be sent by the bot to users.
|
||||
|
||||
Requires no parameters.
|
||||
Returns a Gifts object.
|
||||
See https://core.telegram.org/bots/api#getavailablegifts for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'getAvailableGifts',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def sendGift(self, user_id: int, chat_id: Union[int, str],
|
||||
gift_id: str, pay_for_upgrade: bool,
|
||||
text: str, text_parse_mode: str,
|
||||
text_entities: List['MessageEntity']):
|
||||
"""Sends a gift to the given user.
|
||||
|
||||
The gift can't be converted to Telegram Stars by the user.
|
||||
Returns True on success.
|
||||
See https://core.telegram.org/bots/api#sendgift for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'sendGift',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def verifyUser(self, user_id: int,
|
||||
custom_description: str = None):
|
||||
"""Verifies a user on behalf of the organization which is represented by
|
||||
the bot.
|
||||
|
||||
Returns True on success.
|
||||
See https://core.telegram.org/bots/api#verifyuser for details.
|
||||
"""
|
||||
if len(custom_description) > 70:
|
||||
raise TypeError("Parameter `custom_description` is too long "
|
||||
"(0-70 characters).")
|
||||
return await self.api_request(
|
||||
'verifyUser',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def verifyChat(self, chat_id: Union[int, str],
|
||||
custom_description: str = None):
|
||||
"""Verifies a chat on behalf of the organization which is represented by
|
||||
the bot.
|
||||
|
||||
Returns True on success.
|
||||
See https://core.telegram.org/bots/api#verifychat for details.
|
||||
"""
|
||||
if isinstance(chat_id, str) and chat_id.isnumeric():
|
||||
chat_id = int(chat_id)
|
||||
if not (isinstance(chat_id, int) or
|
||||
(isinstance(chat_id, str) and chat_id.startswith('@'))):
|
||||
raise TypeError(f"Invalid chat_id: `{chat_id}`")
|
||||
if len(custom_description) > 70:
|
||||
raise TypeError("Parameter `custom_description` is too long "
|
||||
"(0-70 characters).")
|
||||
return await self.api_request(
|
||||
'verifyChat',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def removeUserVerification(self, user_id: int):
|
||||
"""Removes verification from a user who is currently verified on behalf
|
||||
of the organization represented by the bot.
|
||||
|
||||
Returns True on success.
|
||||
See https://core.telegram.org/bots/api#removeuserverification for
|
||||
details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'removeUserVerification',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def removeChatVerification(self, chat_id: Union[int, str]):
|
||||
"""Removes verification from a chat that is currently verified on behalf
|
||||
of the organization represented by the bot.
|
||||
|
||||
Returns True on success.
|
||||
See https://core.telegram.org/bots/api#removechatverification for
|
||||
details.
|
||||
"""
|
||||
if not (isinstance(chat_id, int) or
|
||||
(isinstance(chat_id, str) and chat_id.startswith('@'))):
|
||||
raise TypeError(f"Invalid chat_id: `{chat_id}`")
|
||||
return await self.api_request(
|
||||
'removeChatVerification',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def savePreparedInlineMessage(self,
|
||||
user_id: int,
|
||||
result: 'InlineQueryResult',
|
||||
allow_user_chats: bool = None,
|
||||
allow_bot_chats: bool = None,
|
||||
allow_group_chats: bool = None,
|
||||
allow_channel_chats: bool = None
|
||||
) -> 'PreparedInlineMessage':
|
||||
"""Stores a message that can be sent by a user of a Mini App.
|
||||
|
||||
Returns a PreparedInlineMessage object.
|
||||
See https://core.telegram.org/bots/api#savepreparedinlinemessage for
|
||||
details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'savePreparedInlineMessage',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def editUserStarSubscription(self, user_id: int,
|
||||
telegram_payment_charge_id: str,
|
||||
is_canceled: bool):
|
||||
"""Allows the bot to cancel or re-enable extension of a subscription
|
||||
paid in Telegram Stars.
|
||||
|
||||
Returns True on success.
|
||||
See https://core.telegram.org/bots/api#edituserstarsubscription for
|
||||
details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'editUserStarSubscription',
|
||||
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,
|
||||
business_connection_id: str,
|
||||
exclude_unsaved: bool = None,
|
||||
exclude_saved: bool = None,
|
||||
exclude_unlimited: bool = None,
|
||||
exclude_limited: bool = None,
|
||||
exclude_unique: bool = None,
|
||||
sort_by_price: bool = None,
|
||||
offset: str = None,
|
||||
limit: int = None):
|
||||
"""Returns the gifts received and owned by a managed business account.
|
||||
|
||||
Requires the can_view_gifts_and_stars business bot right.
|
||||
Returns OwnedGifts on success.
|
||||
See https://core.telegram.org/bots/api#getbusinessaccountgifts for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'getBusinessAccountGifts',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def convertGiftToStars(self, business_connection_id: str, owned_gift_id: str):
|
||||
"""Converts a given regular gift to Telegram Stars.
|
||||
|
||||
Requires the can_convert_gifts_to_stars business bot right.
|
||||
Returns True on success.
|
||||
See https://core.telegram.org/bots/api#convertgifttostars for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'convertGiftToStars',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def upgradeGift(self, business_connection_id: str,
|
||||
owned_gift_id: str,
|
||||
keep_original_details: bool = None,
|
||||
star_count: int = None):
|
||||
"""Upgrades a given regular gift to a unique gift.
|
||||
|
||||
Requires the can_transfer_and_upgrade_gifts business bot right.
|
||||
Additionally requires the can_transfer_stars business bot right if the
|
||||
upgrade is paid.
|
||||
Returns True on success.
|
||||
See https://core.telegram.org/bots/api#upgradegift for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'upgradeGift',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def transferGift(self, business_connection_id: str,
|
||||
owned_gift_id: str,
|
||||
new_owner_chat_id: int,
|
||||
star_count: int = None):
|
||||
"""Transfers an owned unique gift to another user.
|
||||
|
||||
Requires the can_transfer_and_upgrade_gifts business bot right.
|
||||
Requires can_transfer_stars business bot right if the transfer is paid.
|
||||
Returns True on success.
|
||||
See https://core.telegram.org/bots/api#transfergift for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'transferGift',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def postStory(self, business_connection_id: str,
|
||||
content: 'InputStoryContent',
|
||||
active_period: int,
|
||||
caption: str = None,
|
||||
parse_mode: str = None,
|
||||
caption_entities: List['MessageEntity'] = None,
|
||||
areas: List['StoryArea'] = None,
|
||||
post_to_chat_page: bool = None,
|
||||
protect_content: bool = None):
|
||||
"""Posts a story on behalf of a managed business account.
|
||||
|
||||
Requires the can_manage_stories business bot right.
|
||||
Returns Story on success.
|
||||
See https://core.telegram.org/bots/api#poststory for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'postStory',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def editStory(self, business_connection_id: str,
|
||||
story_id: int,
|
||||
content: 'InputStoryContent',
|
||||
caption: str = None,
|
||||
parse_mode: str = None,
|
||||
caption_entities: List[dict] = None,
|
||||
areas: List['StoryArea'] = None):
|
||||
"""Edits a story previously posted by the bot on behalf of a managed
|
||||
business account.
|
||||
|
||||
Requires the can_manage_stories business bot right.
|
||||
Returns Story on success.
|
||||
See https://core.telegram.org/bots/api#editstory for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'editStory',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def deleteStory(self, business_connection_id: str, story_id: int):
|
||||
"""Deletes a story previously posted by the bot on behalf of a managed
|
||||
business account.
|
||||
|
||||
Requires the can_manage_stories business bot right.
|
||||
Returns True on success.
|
||||
See https://core.telegram.org/bots/api#deletestory for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'deleteStory',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
@@ -25,7 +25,6 @@ class TelegramApiMethod(object):
|
||||
'Boolean': "bool",
|
||||
'Integer': "int",
|
||||
'Integer or String': "Union[int, str]",
|
||||
'Array of Integer': "List[str]",
|
||||
'String': "str",
|
||||
}
|
||||
"""Telegram bot API method."""
|
||||
@@ -56,15 +55,14 @@ class TelegramApiMethod(object):
|
||||
for n, paragraph in enumerate(self.description.replace('.', '.\n').split('\n')):
|
||||
additional_indentation = 0
|
||||
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(' '):
|
||||
if len(current_line) + len(word) > 80 - indentation - additional_indentation:
|
||||
additional_indentation = max(additional_indentation, 4)
|
||||
result += f"{current_line.strip()}\n{' ' * additional_indentation}"
|
||||
current_line = ""
|
||||
current_line += f"{word} "
|
||||
if len(current_line) > 0:
|
||||
if len(current_line):
|
||||
result += f"{current_line.strip()}\n"
|
||||
current_line = ""
|
||||
if n == 0:
|
||||
@@ -205,7 +203,7 @@ async def print_api_methods(filename=None,
|
||||
)
|
||||
)
|
||||
if output_file:
|
||||
with open(output_file, 'w', encoding="utf-8") as file:
|
||||
with open(output_file, 'w') as file:
|
||||
if new_methods:
|
||||
file.write(
|
||||
"from typing import List, Union\n"
|
||||
|
||||
@@ -122,47 +122,12 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
||||
'edited_message': self.edited_message_handler,
|
||||
'channel_post': self.channel_post_handler,
|
||||
'edited_channel_post': self.edited_channel_post_handler,
|
||||
'business_connection': self.get_update_handler(
|
||||
update_type='business_connection'
|
||||
),
|
||||
'business_message': self.get_update_handler(
|
||||
update_type='business_message'
|
||||
),
|
||||
'edited_business_message': self.get_update_handler(
|
||||
update_type='edited_business_message'
|
||||
),
|
||||
'deleted_business_messages': self.get_update_handler(
|
||||
update_type='deleted_business_messages'
|
||||
),
|
||||
'message_reaction': self.get_update_handler(
|
||||
update_type='message_reaction'
|
||||
),
|
||||
'message_reaction_count': self.get_update_handler(
|
||||
update_type='message_reaction_count'
|
||||
),
|
||||
'inline_query': self.inline_query_handler,
|
||||
'chosen_inline_result': self.chosen_inline_result_handler,
|
||||
'callback_query': self.callback_query_handler,
|
||||
'shipping_query': self.shipping_query_handler,
|
||||
'pre_checkout_query': self.pre_checkout_query_handler,
|
||||
'purchased_paid_media': self.get_update_handler(
|
||||
update_type='purchased_paid_media'
|
||||
),
|
||||
'poll': self.poll_handler,
|
||||
'poll_answer': self.get_update_handler(
|
||||
update_type='poll_answer'
|
||||
),
|
||||
'my_chat_member': self.get_update_handler(
|
||||
update_type='my_chat_member'
|
||||
),
|
||||
'chat_member': self.get_update_handler( update_type='chat_member' ),
|
||||
'chat_join_request': self.get_update_handler(
|
||||
update_type='chat_join_request'
|
||||
),
|
||||
'chat_boost': self.get_update_handler( update_type='chat_boost' ),
|
||||
'removed_chat_boost': self.get_update_handler(
|
||||
update_type='removed_chat_boost'
|
||||
),
|
||||
}
|
||||
# Different message update types need different handlers
|
||||
self.message_handlers = {
|
||||
@@ -256,8 +221,6 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
||||
self.Role = None
|
||||
self.packages = [sys.modules['davtelepot']]
|
||||
self._documents_max_dimension = None
|
||||
self._getting_me = False
|
||||
self._got_me = False
|
||||
# Add `users` table with its fields if missing
|
||||
if 'users' not in self.db.tables:
|
||||
table = self.db.create_table(
|
||||
@@ -717,18 +680,6 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
||||
)
|
||||
return
|
||||
|
||||
def get_update_handler(self, update_type: str):
|
||||
"""Get update handler for `update_type`."""
|
||||
bot = self
|
||||
async def handler(update, user_record, language=None):
|
||||
"""Handle update message of type `update_type`"""
|
||||
logging.info(
|
||||
"The following update was received: %s\n"
|
||||
"However, this `%s` handler does nothing yet.",
|
||||
update, update_type
|
||||
)
|
||||
return handler
|
||||
|
||||
async def edited_channel_post_handler(self, update, user_record, language=None):
|
||||
"""Handle Telegram `edited_channel_post` update."""
|
||||
logging.info(
|
||||
@@ -2853,7 +2804,9 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
||||
"""
|
||||
if not callable(condition):
|
||||
raise TypeError(
|
||||
f'Condition {condition.__name__} is not a callable'
|
||||
'Condition {c} is not a callable'.format(
|
||||
c=condition.__name__
|
||||
)
|
||||
)
|
||||
|
||||
def query_decorator(handler):
|
||||
@@ -3194,41 +3147,26 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
||||
|
||||
Restart bots if bot can't be got.
|
||||
"""
|
||||
for _ in range(60):
|
||||
if not self._getting_me:
|
||||
break
|
||||
await asyncio.sleep(0.5)
|
||||
else:
|
||||
raise TimeoutError("Getting bot information was in progress but "
|
||||
"did not make it in 30 seconds...")
|
||||
if self._got_me:
|
||||
return
|
||||
self._getting_me = True
|
||||
try:
|
||||
me = await self.getMe()
|
||||
if isinstance(me, Exception):
|
||||
raise me
|
||||
if me is None:
|
||||
raise TypeError('getMe returned None')
|
||||
elif me is None:
|
||||
raise Exception('getMe returned None')
|
||||
self._name = me["username"]
|
||||
self._telegram_id = me['id']
|
||||
except Exception as e:
|
||||
logging.error(
|
||||
"API getMe method failed, information about this bot could "
|
||||
"not be retrieved. Restarting in 5 minutes...\n\n"
|
||||
"Error information:\n%s", e
|
||||
f"API getMe method failed, information about this bot could "
|
||||
f"not be retrieved. Restarting in 5 minutes...\n\n"
|
||||
f"Error information:\n{e}"
|
||||
)
|
||||
self._getting_me = False
|
||||
await asyncio.sleep(5*60)
|
||||
if self._got_me:
|
||||
return
|
||||
self.__class__.stop(
|
||||
message="Information about this bot could not be retrieved.\n"
|
||||
"Restarting...",
|
||||
final_state=65
|
||||
)
|
||||
self._getting_me = False
|
||||
self._got_me = True
|
||||
|
||||
def setup(self):
|
||||
"""Make bot ask for updates and handle responses."""
|
||||
@@ -3243,11 +3181,9 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
||||
|
||||
async def close_sessions(self):
|
||||
"""Close open sessions."""
|
||||
for session_name in list(self.sessions.keys()):
|
||||
session = self.sessions[session_name]
|
||||
for session_name, session in self.sessions.items():
|
||||
if not session.closed:
|
||||
await session.close()
|
||||
del self.sessions[session_name]
|
||||
|
||||
async def send_one_message(self, *args, **kwargs):
|
||||
sent_message = await self.send_message(*args, **kwargs)
|
||||
|
||||
2
setup.py
2
setup.py
@@ -51,7 +51,7 @@ setuptools.setup(
|
||||
license=find_information("license", "davtelepot", "__init__.py"),
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
url="https://gitea.davte.it/davte/davtelepot",
|
||||
url="https://gogs.davte.it/davte/davtelepot",
|
||||
packages=setuptools.find_packages(),
|
||||
platforms=['any'],
|
||||
install_requires=[
|
||||
|
||||
Reference in New Issue
Block a user