Compare commits
54
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b489363de
|
||
|
|
a343e095e8
|
||
|
|
a3b28bc1d6
|
||
|
|
3969794075
|
||
|
|
748ba624a4
|
||
|
|
41507067be
|
||
|
|
ec747bef1d
|
||
|
|
199fe29cf1
|
||
|
|
41f38d0b23
|
||
|
|
cf492f0c8b
|
||
|
|
eab81b065d
|
||
|
|
51a77c695b
|
||
|
|
febe5cee3f
|
||
|
|
fb04211e81
|
||
|
|
3bd1a9b679
|
||
|
|
0c3ed2070d
|
||
|
|
5c30dafd4c
|
||
|
|
27f9d62cf9
|
||
|
|
fafa639328
|
||
|
|
55b47ed1f7
|
||
|
|
881d249256
|
||
|
|
fc486c60ce
|
||
|
|
e813d37c8f
|
||
|
|
21f91fb07c
|
||
|
|
50c2f92e8e
|
||
|
|
d77c416ea6
|
||
|
|
e487764aad
|
||
|
|
4bf00f0cc5
|
||
|
|
ed7e335d4e
|
||
|
|
d6a4a1d69a
|
||
|
|
668822fc21
|
||
|
|
135442dcd6
|
||
|
|
eb11160a02
|
||
|
|
fda4cac348
|
||
|
|
773fe1fdb1
|
||
|
|
ddf25f8dd1
|
||
|
|
17b26ec23e
|
||
|
|
68974c4c40
|
||
|
|
92e39e7ed7
|
||
|
|
48b7e1e4a2
|
||
|
|
b797f3fffe
|
||
|
|
3e19ba4c81
|
||
|
|
e29bb08b7b
|
||
|
|
7233f9e478
|
||
|
|
e481623a75
|
||
|
|
88835955ef | ||
|
|
8c37d00602 | ||
|
|
ada375b766 | ||
|
|
ed05d843bc | ||
|
|
bc51ed109a | ||
|
|
76204ccd69 | ||
|
|
293a831958 | ||
|
|
fafc3de090 | ||
|
|
5fe875e49c |
@@ -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.6"
|
||||
__version__ = "2.10.2"
|
||||
__maintainer__ = "Davide Testa"
|
||||
__contact__ = "t.me/davte"
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import re
|
||||
import types
|
||||
|
||||
from collections import OrderedDict
|
||||
from importlib.metadata import version as get_package_version_from_metadata
|
||||
from typing import Union, List, Tuple
|
||||
|
||||
# Third party modules
|
||||
@@ -29,8 +28,8 @@ from davtelepot.messages import default_admin_messages, default_talk_messages
|
||||
from davtelepot.bot import Bot
|
||||
from davtelepot.utilities import (
|
||||
async_wrapper, CachedPage, Confirmator, extract, get_cleaned_text,
|
||||
get_secure_key, get_user, clean_html_string, line_drawing_unordered_list,
|
||||
make_button, make_inline_keyboard, remove_html_tags, send_part_of_text_file,
|
||||
get_user, clean_html_string, line_drawing_unordered_list, make_button,
|
||||
make_inline_keyboard, remove_html_tags, send_part_of_text_file,
|
||||
send_csv_file, make_lines_of_buttons, join_path
|
||||
)
|
||||
|
||||
@@ -45,13 +44,6 @@ variable_regex = re.compile(r"(?P<name>[a-zA-Z]\w*)\s*=\s*"
|
||||
r"\"[^\"]*\")")
|
||||
|
||||
|
||||
def get_package_version(package: types.ModuleType):
|
||||
"""Get version of given package."""
|
||||
if hasattr(package, '__version__'):
|
||||
return package.__version__
|
||||
return get_package_version_from_metadata(package.__name__)
|
||||
|
||||
|
||||
async def _forward_to(update,
|
||||
bot: Bot,
|
||||
sender,
|
||||
@@ -873,12 +865,7 @@ async def get_new_versions(bot: Bot,
|
||||
"skipping...")
|
||||
continue
|
||||
new_version = web_page['info']['version']
|
||||
try:
|
||||
current_version = get_package_version(package)
|
||||
except TypeError:
|
||||
current_version = "NA"
|
||||
logging.error("Could not get current version of "
|
||||
"package %s", package.__name__)
|
||||
current_version = package.__version__
|
||||
notification_record = bot.db['updates_notifications'].find_one(
|
||||
package=package.__name__,
|
||||
order_by=['-id'],
|
||||
@@ -908,7 +895,7 @@ async def version_command(bot: Bot, update: dict,
|
||||
text += f'<b>Python: </b> <code>{platform.python_version()}</code>\n'
|
||||
text += '\n'.join(
|
||||
f"<b>{package.__name__}</b>: "
|
||||
f"<code>{get_package_version(package)}</code>"
|
||||
f"<code>{package.__version__}</code>"
|
||||
for package in bot.packages
|
||||
)
|
||||
temporary_message = await bot.send_message(
|
||||
@@ -952,7 +939,7 @@ async def notify_new_version(bot: Bot):
|
||||
order_by=['-id']
|
||||
)
|
||||
current_versions = {
|
||||
f"{package.__name__}_version": get_package_version(package)
|
||||
f"{package.__name__}_version": package.__version__
|
||||
for package in bot.packages
|
||||
}
|
||||
current_versions['last_commit'] = last_commit
|
||||
@@ -1859,50 +1846,6 @@ async def config_command(bot: Bot, update: dict,
|
||||
language=language)
|
||||
|
||||
|
||||
async def become_administrator(bot: Bot, update: dict,
|
||||
user_record: dict, language: str):
|
||||
"""When the bot has no administrator, become one providing a token.
|
||||
|
||||
The token will be printed to the stdout on the machine running the bot.
|
||||
"""
|
||||
if len(bot.administrators) > 0:
|
||||
return
|
||||
def _get_message(*args):
|
||||
return bot.get_message('admin', 'become_admin', *args,
|
||||
update=update, user_record=user_record,
|
||||
language=language)
|
||||
token = get_cleaned_text(update=update, bot=bot,
|
||||
replace=['become_administrator',
|
||||
'00become_administrator'],
|
||||
strip='/ @_')
|
||||
if token != bot.administration_token:
|
||||
return _get_message('wrong_token')
|
||||
with bot.db as db:
|
||||
db['users'].update({**user_record, 'privileges': 1},
|
||||
['id'])
|
||||
return _get_message('success')
|
||||
|
||||
|
||||
async def create_promotion_command(bot: Bot):
|
||||
"""If bot has no administrators, users can elevate themselves.
|
||||
|
||||
To do so, they need to provide a token, that will be printed to the stdout
|
||||
of the machine running the bot.
|
||||
"""
|
||||
await bot.get_me()
|
||||
bot.administration_token = get_secure_key(length=10)
|
||||
print(f"To become administrator click "
|
||||
f"https://t.me/{bot.name}?start="
|
||||
f"00become_administrator_{bot.administration_token}")
|
||||
@bot.command(command='become_administrator',
|
||||
authorization_level='everybody',
|
||||
aliases=['00become_administrator'])
|
||||
async def _become_administrator(bot, update, user_record, language):
|
||||
return await become_administrator(bot=bot, update=update,
|
||||
user_record=user_record,
|
||||
language=language)
|
||||
|
||||
|
||||
def init(telegram_bot: Bot,
|
||||
talk_messages: dict = None,
|
||||
admin_messages: dict = None,
|
||||
@@ -2132,6 +2075,3 @@ def init(telegram_bot: Bot,
|
||||
update=update,
|
||||
user_record=user_record,
|
||||
language=language)
|
||||
|
||||
if len(telegram_bot.administrators) == 0:
|
||||
asyncio.ensure_future(create_promotion_command(bot=telegram_bot))
|
||||
|
||||
+1
-151
@@ -425,38 +425,6 @@ class ReactionType(DictToDump):
|
||||
)
|
||||
|
||||
|
||||
class InputPaidMedia(DictToDump):
|
||||
def __init__(self,
|
||||
type_: str,
|
||||
media: str):
|
||||
assert type_ in ('photo', 'video'), f"Invalid paid media type `{type_}`"
|
||||
super().__init__()
|
||||
self['type'] = type_
|
||||
self['media'] = media
|
||||
|
||||
|
||||
class InputPaidMediaPhoto(InputPaidMedia):
|
||||
def __init__(self,
|
||||
media: str):
|
||||
super().__init__('photo', media)
|
||||
|
||||
|
||||
class InputPaidMediaVideo(InputPaidMedia):
|
||||
def __init__(self,
|
||||
media: str,
|
||||
thumbnail: str = None,
|
||||
width: int = None,
|
||||
height: int = None,
|
||||
duration: int = None,
|
||||
supports_streaming: bool = None):
|
||||
super().__init__('video', media)
|
||||
self['thumbnail'] = thumbnail
|
||||
self['width'] = width
|
||||
self['height'] = height
|
||||
self['duration'] = duration
|
||||
self['supports_streaming'] = supports_streaming
|
||||
|
||||
|
||||
def handle_deprecated_disable_web_page_preview(parameters: dict,
|
||||
kwargs: dict):
|
||||
if 'disable_web_page_preview' in kwargs:
|
||||
@@ -914,7 +882,6 @@ class TelegramBot:
|
||||
link_preview_options: LinkPreviewOptions = None,
|
||||
disable_notification: bool = None,
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -955,12 +922,10 @@ class TelegramBot:
|
||||
caption: str = None,
|
||||
parse_mode: str = None,
|
||||
caption_entities: List[dict] = None,
|
||||
show_caption_above_media: bool = None,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
disable_notification: bool = None,
|
||||
has_spoiler: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -989,7 +954,6 @@ class TelegramBot:
|
||||
disable_notification: bool = None,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -1021,7 +985,6 @@ class TelegramBot:
|
||||
disable_notification: bool = None,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -1052,12 +1015,10 @@ class TelegramBot:
|
||||
caption: str = None,
|
||||
parse_mode: str = None,
|
||||
caption_entities: List[dict] = None,
|
||||
show_caption_above_media: bool = None,
|
||||
supports_streaming: bool = None,
|
||||
disable_notification: bool = None,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
has_spoiler: bool = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
@@ -1089,11 +1050,9 @@ class TelegramBot:
|
||||
caption: str = None,
|
||||
parse_mode: str = None,
|
||||
caption_entities: List[dict] = None,
|
||||
show_caption_above_media: bool = None,
|
||||
disable_notification: bool = None,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
has_spoiler: bool = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
@@ -1125,7 +1084,6 @@ class TelegramBot:
|
||||
disable_notification: bool = None,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -1151,7 +1109,6 @@ class TelegramBot:
|
||||
disable_notification: bool = None,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -1178,7 +1135,6 @@ class TelegramBot:
|
||||
disable_notification: bool = None,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
**kwargs):
|
||||
"""Send a group of photos or videos as an album.
|
||||
@@ -1206,7 +1162,6 @@ class TelegramBot:
|
||||
disable_notification: bool = None,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -1232,9 +1187,7 @@ class TelegramBot:
|
||||
)
|
||||
|
||||
async def editMessageLiveLocation(self, latitude: float, longitude: float,
|
||||
live_period: int = None,
|
||||
chat_id: Union[int, str] = None,
|
||||
business_connection_id: str = None,
|
||||
message_id: int = None,
|
||||
inline_message_id: str = None,
|
||||
horizontal_accuracy: float = None,
|
||||
@@ -1265,7 +1218,6 @@ class TelegramBot:
|
||||
|
||||
async def stopMessageLiveLocation(self,
|
||||
chat_id: Union[int, str] = None,
|
||||
business_connection_id: str = None,
|
||||
message_id: int = None,
|
||||
inline_message_id: int = None,
|
||||
reply_markup=None):
|
||||
@@ -1293,7 +1245,6 @@ class TelegramBot:
|
||||
disable_notification: bool = None,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -1320,7 +1271,6 @@ class TelegramBot:
|
||||
disable_notification: bool = None,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -1341,8 +1291,6 @@ class TelegramBot:
|
||||
chat_id: Union[int, str],
|
||||
question: str,
|
||||
options: List[str],
|
||||
question_parse_mode: str = None,
|
||||
question_entities: list = None,
|
||||
business_connection_id: str = None,
|
||||
is_anonymous: bool = True,
|
||||
type_: str = 'regular',
|
||||
@@ -1357,7 +1305,6 @@ class TelegramBot:
|
||||
disable_notification: bool = None,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -1593,7 +1540,6 @@ class TelegramBot:
|
||||
)
|
||||
|
||||
async def pinChatMessage(self, chat_id: Union[int, str], message_id,
|
||||
business_connection_id: str = None,
|
||||
disable_notification: bool = None):
|
||||
"""Pin a message in a group, a supergroup, or a channel.
|
||||
|
||||
@@ -1609,7 +1555,6 @@ class TelegramBot:
|
||||
)
|
||||
|
||||
async def unpinChatMessage(self, chat_id: Union[int, str],
|
||||
business_connection_id: str = None,
|
||||
message_id: int = None):
|
||||
"""Unpin a message in a group, a supergroup, or a channel.
|
||||
|
||||
@@ -1734,7 +1679,6 @@ class TelegramBot:
|
||||
|
||||
async def editMessageText(self, text: str,
|
||||
chat_id: Union[int, str] = None,
|
||||
business_connection_id: str = None,
|
||||
message_id: int = None,
|
||||
inline_message_id: str = None,
|
||||
parse_mode: str = None,
|
||||
@@ -1759,13 +1703,11 @@ class TelegramBot:
|
||||
|
||||
async def editMessageCaption(self,
|
||||
chat_id: Union[int, str] = None,
|
||||
business_connection_id: str = None,
|
||||
message_id: int = None,
|
||||
inline_message_id: str = None,
|
||||
caption: str = None,
|
||||
parse_mode: str = None,
|
||||
caption_entities: List[dict] = None,
|
||||
show_caption_above_media: bool = None,
|
||||
reply_markup=None):
|
||||
"""Edit captions of messages.
|
||||
|
||||
@@ -1780,7 +1722,6 @@ class TelegramBot:
|
||||
|
||||
async def editMessageMedia(self,
|
||||
chat_id: Union[int, str] = None,
|
||||
business_connection_id: str = None,
|
||||
message_id: int = None,
|
||||
inline_message_id: str = None,
|
||||
media=None,
|
||||
@@ -1803,7 +1744,6 @@ class TelegramBot:
|
||||
|
||||
async def editMessageReplyMarkup(self,
|
||||
chat_id: Union[int, str] = None,
|
||||
business_connection_id: str = None,
|
||||
message_id: int = None,
|
||||
inline_message_id: str = None,
|
||||
reply_markup=None):
|
||||
@@ -1819,10 +1759,7 @@ class TelegramBot:
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def stopPoll(self,
|
||||
chat_id: Union[int, str],
|
||||
message_id,
|
||||
business_connection_id: str = None,
|
||||
async def stopPoll(self, chat_id: Union[int, str], message_id,
|
||||
reply_markup=None):
|
||||
"""Stop a poll which was sent by the bot.
|
||||
|
||||
@@ -1878,7 +1815,6 @@ class TelegramBot:
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
emoji: str = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -2097,7 +2033,6 @@ class TelegramBot:
|
||||
send_email_to_provider: bool = None,
|
||||
is_flexible: bool = None,
|
||||
disable_notification: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -2177,7 +2112,6 @@ class TelegramBot:
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
disable_notification: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -2244,7 +2178,6 @@ class TelegramBot:
|
||||
disable_notification: bool = None,
|
||||
message_thread_id: int = None,
|
||||
protect_content: bool = None,
|
||||
message_effect_id: str = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
@@ -2392,7 +2325,6 @@ class TelegramBot:
|
||||
caption: str = None,
|
||||
parse_mode: str = None,
|
||||
caption_entities: list = None,
|
||||
show_caption_above_media: bool = None,
|
||||
disable_notification: bool = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup=None,
|
||||
@@ -3106,85 +3038,3 @@ class TelegramBot:
|
||||
'replaceStickerInSet',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def sendPaidMedia(self, chat_id: Union[int, str], star_count: int,
|
||||
media: List[InputPaidMedia],
|
||||
business_connection_id: str = None,
|
||||
caption: str = None, parse_mode: str = None,
|
||||
caption_entities: List[dict] = None,
|
||||
show_caption_above_media: bool = None,
|
||||
disable_notification: bool = None,
|
||||
protect_content: bool = None,
|
||||
reply_parameters: ReplyParameters = None,
|
||||
reply_markup = None):
|
||||
"""Send paid media to channel chats.
|
||||
|
||||
On success, the sent Message is returned.
|
||||
See https://core.telegram.org/bots/api#sendpaidmedia for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'sendPaidMedia',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def getStarTransactions(self,
|
||||
offset: int = None,
|
||||
limit: int = None):
|
||||
"""Returns the bot's Telegram Star transactions in chronological order.
|
||||
|
||||
On success, returns a StarTransactions object.
|
||||
See https://core.telegram.org/bots/api#getstartransactions for details.
|
||||
|
||||
`offset`: number of transactions to skip in the response (defaults to 0)
|
||||
`limit`: maximum number of transactions to be retrieved.
|
||||
Values between 1-100 are accepted (defaults to 100).
|
||||
"""
|
||||
return await self.api_request(
|
||||
'getStarTransactions',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def refundStarPayment(self,
|
||||
user_id: int,
|
||||
telegram_payment_charge_id: str):
|
||||
"""Refunds a successful payment in Telegram Stars.
|
||||
|
||||
Returns True on success.
|
||||
See https://core.telegram.org/bots/api#refundstarpayment for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'refundStarPayment',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def createChatSubscriptionInviteLink(self, chat_id: Union[int, str],
|
||||
name: str,
|
||||
subscription_period: int,
|
||||
subscription_price: int):
|
||||
"""Create a subscription invite link for a channel chat.
|
||||
|
||||
The bot must have the can_invite_users administrator rights.
|
||||
The link can be edited using the method editChatSubscriptionInviteLink
|
||||
or revoked using the method revokeChatInviteLink.
|
||||
Returns the new invite link as a ChatInviteLink object.
|
||||
See https://core.telegram.org/bots/api#createchatsubscriptioninvitelink
|
||||
for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'createChatSubscriptionInviteLink',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
async def editChatSubscriptionInviteLink(self, chat_id: Union[int, str],
|
||||
invite_link: str, name: str):
|
||||
"""Edit a subscription invite link created by the bot.
|
||||
|
||||
The bot must have the can_invite_users administrator rights.
|
||||
Returns the edited invite link as a ChatInviteLink object.
|
||||
See https://core.telegram.org/bots/api#editchatsubscriptioninvitelink
|
||||
for details.
|
||||
"""
|
||||
return await self.api_request(
|
||||
'editChatSubscriptionInviteLink',
|
||||
parameters=locals()
|
||||
)
|
||||
|
||||
@@ -22,16 +22,6 @@ davtelepot_messages = {
|
||||
}
|
||||
|
||||
default_admin_messages = {
|
||||
'become_admin': {
|
||||
'success': {
|
||||
'en': "🎉 You are now administrator! 👑",
|
||||
'it': "🎉 Ora hai diritti di amministrazione! 👑",
|
||||
},
|
||||
'wrong_token': {
|
||||
'en': "❌ Wrong token 🚷",
|
||||
'it': "❌ Password errata 🚷",
|
||||
},
|
||||
},
|
||||
'cancel': {
|
||||
'button': {
|
||||
'en': "↩️ Cancel",
|
||||
|
||||
Reference in New Issue
Block a user