Compare commits
51 Commits
develop
...
3969794075
| Author | SHA1 | Date | |
|---|---|---|---|
|
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"
|
__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.6"
|
__version__ = "2.9.11"
|
||||||
__maintainer__ = "Davide Testa"
|
__maintainer__ = "Davide Testa"
|
||||||
__contact__ = "t.me/davte"
|
__contact__ = "t.me/davte"
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,10 @@ import asyncio
|
|||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import platform
|
|
||||||
import re
|
import re
|
||||||
import types
|
import types
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from importlib.metadata import version as get_package_version_from_metadata
|
|
||||||
from typing import Union, List, Tuple
|
from typing import Union, List, Tuple
|
||||||
|
|
||||||
# Third party modules
|
# Third party modules
|
||||||
@@ -29,8 +27,8 @@ from davtelepot.messages import default_admin_messages, default_talk_messages
|
|||||||
from davtelepot.bot import Bot
|
from davtelepot.bot import Bot
|
||||||
from davtelepot.utilities import (
|
from davtelepot.utilities import (
|
||||||
async_wrapper, CachedPage, Confirmator, extract, get_cleaned_text,
|
async_wrapper, CachedPage, Confirmator, extract, get_cleaned_text,
|
||||||
get_secure_key, get_user, clean_html_string, line_drawing_unordered_list,
|
get_user, clean_html_string, line_drawing_unordered_list, make_button,
|
||||||
make_button, make_inline_keyboard, remove_html_tags, send_part_of_text_file,
|
make_inline_keyboard, remove_html_tags, send_part_of_text_file,
|
||||||
send_csv_file, make_lines_of_buttons, join_path
|
send_csv_file, make_lines_of_buttons, join_path
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,13 +43,6 @@ variable_regex = re.compile(r"(?P<name>[a-zA-Z]\w*)\s*=\s*"
|
|||||||
r"\"[^\"]*\")")
|
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,
|
async def _forward_to(update,
|
||||||
bot: Bot,
|
bot: Bot,
|
||||||
sender,
|
sender,
|
||||||
@@ -232,9 +223,9 @@ def get_talk_panel(bot: Bot,
|
|||||||
return text, reply_markup
|
return text, reply_markup
|
||||||
|
|
||||||
|
|
||||||
async def talk_command(bot: Bot,
|
async def _talk_command(bot: Bot,
|
||||||
update,
|
update,
|
||||||
user_record):
|
user_record):
|
||||||
text = get_cleaned_text(
|
text = get_cleaned_text(
|
||||||
update,
|
update,
|
||||||
bot,
|
bot,
|
||||||
@@ -352,17 +343,17 @@ async def end_session(bot: Bot,
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
async def talk_button(bot: Bot,
|
async def _talk_button(bot: Bot,
|
||||||
update,
|
update,
|
||||||
user_record,
|
user_record,
|
||||||
data):
|
data):
|
||||||
telegram_id = user_record['telegram_id']
|
telegram_id = user_record['telegram_id']
|
||||||
command, *arguments = data
|
command, *arguments = data
|
||||||
result, text, reply_markup = '', '', None
|
result, text, reply_markup = '', '', None
|
||||||
if command == 'search':
|
if command == 'search':
|
||||||
bot.set_individual_text_message_handler(
|
bot.set_individual_text_message_handler(
|
||||||
await async_wrapper(
|
await async_wrapper(
|
||||||
talk_command,
|
_talk_command,
|
||||||
),
|
),
|
||||||
update
|
update
|
||||||
)
|
)
|
||||||
@@ -435,7 +426,7 @@ async def talk_button(bot: Bot,
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
async def restart_command(bot: Bot,
|
async def _restart_command(bot: Bot,
|
||||||
update,
|
update,
|
||||||
user_record):
|
user_record):
|
||||||
with bot.db as db:
|
with bot.db as db:
|
||||||
@@ -462,7 +453,7 @@ async def restart_command(bot: Bot,
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
async def stop_command(bot: Bot,
|
async def _stop_command(bot: Bot,
|
||||||
update,
|
update,
|
||||||
user_record):
|
user_record):
|
||||||
text = bot.get_message(
|
text = bot.get_message(
|
||||||
@@ -504,10 +495,10 @@ async def stop_bots(bot: Bot):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
async def stop_button(bot: Bot,
|
async def _stop_button(bot: Bot,
|
||||||
update,
|
update,
|
||||||
user_record,
|
user_record,
|
||||||
data: List[Union[int, str]]):
|
data: List[Union[int, str]]):
|
||||||
result, text, reply_markup = '', '', None
|
result, text, reply_markup = '', '', None
|
||||||
telegram_id = user_record['telegram_id']
|
telegram_id = user_record['telegram_id']
|
||||||
command = data[0] if len(data) > 0 else 'None'
|
command = data[0] if len(data) > 0 else 'None'
|
||||||
@@ -544,7 +535,7 @@ async def stop_button(bot: Bot,
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
async def send_bot_database(bot: Bot, user_record: OrderedDict, language: str):
|
async def _send_bot_database(bot: Bot, user_record: OrderedDict, language: str):
|
||||||
if not all(
|
if not all(
|
||||||
[
|
[
|
||||||
bot.db_url.endswith('.db'),
|
bot.db_url.endswith('.db'),
|
||||||
@@ -571,7 +562,7 @@ async def send_bot_database(bot: Bot, user_record: OrderedDict, language: str):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def query_command(bot, update, user_record):
|
async def _query_command(bot, update, user_record):
|
||||||
query = get_cleaned_text(
|
query = get_cleaned_text(
|
||||||
update,
|
update,
|
||||||
bot,
|
bot,
|
||||||
@@ -649,7 +640,7 @@ async def query_command(bot, update, user_record):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def query_button(bot, update, user_record, data):
|
async def _query_button(bot, update, user_record, data):
|
||||||
result, text, reply_markup = '', '', None
|
result, text, reply_markup = '', '', None
|
||||||
command = data[0] if len(data) else 'default'
|
command = data[0] if len(data) else 'default'
|
||||||
error_message = bot.get_message(
|
error_message = bot.get_message(
|
||||||
@@ -686,7 +677,7 @@ async def query_button(bot, update, user_record, data):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
async def log_command(bot, update, user_record):
|
async def _log_command(bot, update, user_record):
|
||||||
if bot.log_file_path is None:
|
if bot.log_file_path is None:
|
||||||
return bot.get_message(
|
return bot.get_message(
|
||||||
'admin', 'log_command', 'no_log',
|
'admin', 'log_command', 'no_log',
|
||||||
@@ -739,7 +730,7 @@ async def log_command(bot, update, user_record):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
async def errors_command(bot, update, user_record):
|
async def _errors_command(bot, update, user_record):
|
||||||
# Always send errors log file in private chat
|
# Always send errors log file in private chat
|
||||||
chat_id = update['from']['id']
|
chat_id = update['from']['id']
|
||||||
if bot.errors_file_path is None:
|
if bot.errors_file_path is None:
|
||||||
@@ -783,7 +774,7 @@ async def errors_command(bot, update, user_record):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
async def maintenance_command(bot, update, user_record):
|
async def _maintenance_command(bot, update, user_record):
|
||||||
maintenance_message = get_cleaned_text(update, bot, ['maintenance'])
|
maintenance_message = get_cleaned_text(update, bot, ['maintenance'])
|
||||||
if maintenance_message.startswith('{'):
|
if maintenance_message.startswith('{'):
|
||||||
maintenance_message = json.loads(maintenance_message)
|
maintenance_message = json.loads(maintenance_message)
|
||||||
@@ -873,12 +864,7 @@ async def get_new_versions(bot: Bot,
|
|||||||
"skipping...")
|
"skipping...")
|
||||||
continue
|
continue
|
||||||
new_version = web_page['info']['version']
|
new_version = web_page['info']['version']
|
||||||
try:
|
current_version = package.__version__
|
||||||
current_version = get_package_version(package)
|
|
||||||
except TypeError:
|
|
||||||
current_version = "NA"
|
|
||||||
logging.error("Could not get current version of "
|
|
||||||
"package %s", package.__name__)
|
|
||||||
notification_record = bot.db['updates_notifications'].find_one(
|
notification_record = bot.db['updates_notifications'].find_one(
|
||||||
package=package.__name__,
|
package=package.__name__,
|
||||||
order_by=['-id'],
|
order_by=['-id'],
|
||||||
@@ -897,18 +883,17 @@ async def get_new_versions(bot: Bot,
|
|||||||
return news
|
return news
|
||||||
|
|
||||||
|
|
||||||
async def version_command(bot: Bot, update: dict,
|
async def _version_command(bot: Bot, update: dict,
|
||||||
user_record: OrderedDict, language: str):
|
user_record: OrderedDict, language: str):
|
||||||
last_commit = await get_last_commit()
|
last_commit = await get_last_commit()
|
||||||
text = bot.get_message(
|
text = bot.get_message(
|
||||||
'admin', 'version_command', 'header',
|
'admin', 'version_command', 'header',
|
||||||
last_commit=last_commit,
|
last_commit=last_commit,
|
||||||
update=update, user_record=user_record
|
update=update, user_record=user_record
|
||||||
) + '\n\n'
|
) + '\n\n'
|
||||||
text += f'<b>Python: </b> <code>{platform.python_version()}</code>\n'
|
|
||||||
text += '\n'.join(
|
text += '\n'.join(
|
||||||
f"<b>{package.__name__}</b>: "
|
f"<b>{package.__name__}</b>: "
|
||||||
f"<code>{get_package_version(package)}</code>"
|
f"<code>{package.__version__}</code>"
|
||||||
for package in bot.packages
|
for package in bot.packages
|
||||||
)
|
)
|
||||||
temporary_message = await bot.send_message(
|
temporary_message = await bot.send_message(
|
||||||
@@ -952,7 +937,7 @@ async def notify_new_version(bot: Bot):
|
|||||||
order_by=['-id']
|
order_by=['-id']
|
||||||
)
|
)
|
||||||
current_versions = {
|
current_versions = {
|
||||||
f"{package.__name__}_version": get_package_version(package)
|
f"{package.__name__}_version": package.__version__
|
||||||
for package in bot.packages
|
for package in bot.packages
|
||||||
}
|
}
|
||||||
current_versions['last_commit'] = last_commit
|
current_versions['last_commit'] = last_commit
|
||||||
@@ -1047,7 +1032,7 @@ async def get_package_updates(bot: Bot,
|
|||||||
await asyncio.sleep(monitoring_interval)
|
await asyncio.sleep(monitoring_interval)
|
||||||
|
|
||||||
|
|
||||||
async def send_start_messages(bot: Bot):
|
async def _send_start_messages(bot: Bot):
|
||||||
"""Send restart messages at restart."""
|
"""Send restart messages at restart."""
|
||||||
for restart_message in bot.db['restart_messages'].find(sent=None):
|
for restart_message in bot.db['restart_messages'].find(sent=None):
|
||||||
asyncio.ensure_future(
|
asyncio.ensure_future(
|
||||||
@@ -1075,7 +1060,7 @@ async def send_start_messages(bot: Bot):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
async def load_talking_sessions(bot: Bot):
|
async def _load_talking_sessions(bot: Bot):
|
||||||
sessions = []
|
sessions = []
|
||||||
for session in bot.db.query(
|
for session in bot.db.query(
|
||||||
"""SELECT *
|
"""SELECT *
|
||||||
@@ -1154,7 +1139,7 @@ def get_custom_commands(bot: Bot, language: str = None) -> List[dict]:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def father_command(bot, language):
|
async def _father_command(bot, language):
|
||||||
modes = [
|
modes = [
|
||||||
{
|
{
|
||||||
key: (
|
key: (
|
||||||
@@ -1458,12 +1443,12 @@ async def edit_bot_father_settings_via_message(bot: Bot,
|
|||||||
return result, text, reply_markup
|
return result, text, reply_markup
|
||||||
|
|
||||||
|
|
||||||
async def father_button(bot: Bot, user_record: OrderedDict,
|
async def _father_button(bot: Bot, user_record: OrderedDict,
|
||||||
language: str, data: list):
|
language: str, data: list):
|
||||||
"""Handle BotFather button.
|
"""Handle BotFather button.
|
||||||
|
|
||||||
Operational modes
|
Operational modes
|
||||||
- main: back to main page (see `father_command`)
|
- main: back to main page (see _father_command)
|
||||||
- get: show commands stored by @BotFather
|
- get: show commands stored by @BotFather
|
||||||
- set: edit commands stored by @BotFather
|
- set: edit commands stored by @BotFather
|
||||||
"""
|
"""
|
||||||
@@ -1557,7 +1542,7 @@ async def father_button(bot: Bot, user_record: OrderedDict,
|
|||||||
elif command == 'main':
|
elif command == 'main':
|
||||||
return dict(
|
return dict(
|
||||||
text='',
|
text='',
|
||||||
edit=(await father_command(bot=bot, language=language))
|
edit=(await _father_command(bot=bot, language=language))
|
||||||
)
|
)
|
||||||
elif command == 'set':
|
elif command == 'set':
|
||||||
stored_commands = await bot.getMyCommands()
|
stored_commands = await bot.getMyCommands()
|
||||||
@@ -1825,8 +1810,8 @@ async def father_button(bot: Bot, user_record: OrderedDict,
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
async def config_command(bot: Bot, update: dict,
|
async def _config_command(bot: Bot, update: dict,
|
||||||
user_record: dict, language: str):
|
user_record: dict, language: str):
|
||||||
text = get_cleaned_text(
|
text = get_cleaned_text(
|
||||||
update,
|
update,
|
||||||
bot,
|
bot,
|
||||||
@@ -1859,50 +1844,6 @@ async def config_command(bot: Bot, update: dict,
|
|||||||
language=language)
|
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,
|
def init(telegram_bot: Bot,
|
||||||
talk_messages: dict = None,
|
talk_messages: dict = None,
|
||||||
admin_messages: dict = None,
|
admin_messages: dict = None,
|
||||||
@@ -1966,16 +1907,16 @@ def init(telegram_bot: Bot,
|
|||||||
|
|
||||||
# Tasks to complete before starting bot
|
# Tasks to complete before starting bot
|
||||||
@telegram_bot.additional_task(when='BEFORE')
|
@telegram_bot.additional_task(when='BEFORE')
|
||||||
async def _load_talking_sessions():
|
async def load_talking_sessions():
|
||||||
return await load_talking_sessions(bot=telegram_bot)
|
return await _load_talking_sessions(bot=telegram_bot)
|
||||||
|
|
||||||
@telegram_bot.additional_task(when='BEFORE', bot=telegram_bot)
|
@telegram_bot.additional_task(when='BEFORE', bot=telegram_bot)
|
||||||
async def notify_version(bot):
|
async def notify_version(bot):
|
||||||
return await notify_new_version(bot=bot)
|
return await notify_new_version(bot=bot)
|
||||||
|
|
||||||
@telegram_bot.additional_task('BEFORE')
|
@telegram_bot.additional_task('BEFORE')
|
||||||
async def _send_start_messages():
|
async def send_restart_messages():
|
||||||
return await send_start_messages(bot=telegram_bot)
|
return await _send_start_messages(bot=telegram_bot)
|
||||||
|
|
||||||
# Administration commands
|
# Administration commands
|
||||||
@telegram_bot.command(command='/db',
|
@telegram_bot.command(command='/db',
|
||||||
@@ -1984,10 +1925,10 @@ def init(telegram_bot: Bot,
|
|||||||
description=admin_messages[
|
description=admin_messages[
|
||||||
'db_command']['description'],
|
'db_command']['description'],
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _send_bot_database(bot, user_record, language):
|
async def send_bot_database(bot, user_record, language):
|
||||||
return await send_bot_database(bot=bot,
|
return await _send_bot_database(bot=bot,
|
||||||
user_record=user_record,
|
user_record=user_record,
|
||||||
language=language)
|
language=language)
|
||||||
|
|
||||||
@telegram_bot.command(command='/errors',
|
@telegram_bot.command(command='/errors',
|
||||||
aliases=[],
|
aliases=[],
|
||||||
@@ -1995,8 +1936,8 @@ def init(telegram_bot: Bot,
|
|||||||
description=admin_messages[
|
description=admin_messages[
|
||||||
'errors_command']['description'],
|
'errors_command']['description'],
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _errors_command(bot, update, user_record):
|
async def errors_command(bot, update, user_record):
|
||||||
return await errors_command(bot, update, user_record)
|
return await _errors_command(bot, update, user_record)
|
||||||
|
|
||||||
@telegram_bot.command(command='/father',
|
@telegram_bot.command(command='/father',
|
||||||
aliases=[],
|
aliases=[],
|
||||||
@@ -2007,14 +1948,14 @@ def init(telegram_bot: Bot,
|
|||||||
if key in ('description', )
|
if key in ('description', )
|
||||||
},
|
},
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _father_command(bot, language):
|
async def father_command(bot, language):
|
||||||
return await father_command(bot=bot, language=language)
|
return await _father_command(bot=bot, language=language)
|
||||||
|
|
||||||
@telegram_bot.button(prefix='father:///',
|
@telegram_bot.button(prefix='father:///',
|
||||||
separator='|',
|
separator='|',
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _father_button(bot, user_record, language, data):
|
async def query_button(bot, user_record, language, data):
|
||||||
return await father_button(bot=bot,
|
return await _father_button(bot=bot,
|
||||||
user_record=user_record,
|
user_record=user_record,
|
||||||
language=language,
|
language=language,
|
||||||
data=data)
|
data=data)
|
||||||
@@ -2025,16 +1966,16 @@ def init(telegram_bot: Bot,
|
|||||||
description=admin_messages[
|
description=admin_messages[
|
||||||
'log_command']['description'],
|
'log_command']['description'],
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _log_command(bot, update, user_record):
|
async def log_command(bot, update, user_record):
|
||||||
return await log_command(bot, update, user_record)
|
return await _log_command(bot, update, user_record)
|
||||||
|
|
||||||
@telegram_bot.command(command='/maintenance', aliases=[],
|
@telegram_bot.command(command='/maintenance', aliases=[],
|
||||||
show_in_keyboard=False,
|
show_in_keyboard=False,
|
||||||
description=admin_messages[
|
description=admin_messages[
|
||||||
'maintenance_command']['description'],
|
'maintenance_command']['description'],
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _maintenance_command(bot, update, user_record):
|
async def maintenance_command(bot, update, user_record):
|
||||||
return await maintenance_command(bot, update, user_record)
|
return await _maintenance_command(bot, update, user_record)
|
||||||
|
|
||||||
@telegram_bot.command(command='/query',
|
@telegram_bot.command(command='/query',
|
||||||
aliases=[],
|
aliases=[],
|
||||||
@@ -2042,16 +1983,16 @@ def init(telegram_bot: Bot,
|
|||||||
description=admin_messages[
|
description=admin_messages[
|
||||||
'query_command']['description'],
|
'query_command']['description'],
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _query_command(bot, update, user_record):
|
async def query_command(bot, update, user_record):
|
||||||
return await query_command(bot, update, user_record)
|
return await _query_command(bot, update, user_record)
|
||||||
|
|
||||||
@telegram_bot.button(prefix='db_query:///',
|
@telegram_bot.button(prefix='db_query:///',
|
||||||
separator='|',
|
separator='|',
|
||||||
description=admin_messages[
|
description=admin_messages[
|
||||||
'query_command']['description'],
|
'query_command']['description'],
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _query_button(bot, update, user_record, data):
|
async def query_button(bot, update, user_record, data):
|
||||||
return await query_button(bot, update, user_record, data)
|
return await _query_button(bot, update, user_record, data)
|
||||||
|
|
||||||
@telegram_bot.command(command='/restart',
|
@telegram_bot.command(command='/restart',
|
||||||
aliases=[],
|
aliases=[],
|
||||||
@@ -2059,8 +2000,8 @@ def init(telegram_bot: Bot,
|
|||||||
description=admin_messages[
|
description=admin_messages[
|
||||||
'restart_command']['description'],
|
'restart_command']['description'],
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _restart_command(bot, update, user_record):
|
async def restart_command(bot, update, user_record):
|
||||||
return await restart_command(bot, update, user_record)
|
return await _restart_command(bot, update, user_record)
|
||||||
|
|
||||||
@telegram_bot.command(command='/select',
|
@telegram_bot.command(command='/select',
|
||||||
aliases=[],
|
aliases=[],
|
||||||
@@ -2068,8 +2009,8 @@ def init(telegram_bot: Bot,
|
|||||||
description=admin_messages[
|
description=admin_messages[
|
||||||
'select_command']['description'],
|
'select_command']['description'],
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _select_command(bot, update, user_record):
|
async def select_command(bot, update, user_record):
|
||||||
return await query_command(bot, update, user_record)
|
return await _query_command(bot, update, user_record)
|
||||||
|
|
||||||
@telegram_bot.command(command='/stop',
|
@telegram_bot.command(command='/stop',
|
||||||
aliases=[],
|
aliases=[],
|
||||||
@@ -2077,16 +2018,16 @@ def init(telegram_bot: Bot,
|
|||||||
description=admin_messages[
|
description=admin_messages[
|
||||||
'stop_command']['description'],
|
'stop_command']['description'],
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _stop_command(bot, update, user_record):
|
async def stop_command(bot, update, user_record):
|
||||||
return await stop_command(bot, update, user_record)
|
return await _stop_command(bot, update, user_record)
|
||||||
|
|
||||||
@telegram_bot.button(prefix='stop:///',
|
@telegram_bot.button(prefix='stop:///',
|
||||||
separator='|',
|
separator='|',
|
||||||
description=admin_messages[
|
description=admin_messages[
|
||||||
'stop_command']['description'],
|
'stop_command']['description'],
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _stop_button(bot, update, user_record, data):
|
async def stop_button(bot, update, user_record, data):
|
||||||
return await stop_button(bot, update, user_record, data)
|
return await _stop_button(bot, update, user_record, data)
|
||||||
|
|
||||||
@telegram_bot.command(command='/talk',
|
@telegram_bot.command(command='/talk',
|
||||||
aliases=[],
|
aliases=[],
|
||||||
@@ -2094,14 +2035,14 @@ def init(telegram_bot: Bot,
|
|||||||
description=admin_messages[
|
description=admin_messages[
|
||||||
'talk_command']['description'],
|
'talk_command']['description'],
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _talk_command(bot, update, user_record):
|
async def talk_command(bot, update, user_record):
|
||||||
return await talk_command(bot, update, user_record)
|
return await _talk_command(bot, update, user_record)
|
||||||
|
|
||||||
@telegram_bot.button(prefix='talk:///',
|
@telegram_bot.button(prefix='talk:///',
|
||||||
separator='|',
|
separator='|',
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _talk_button(bot, update, user_record, data):
|
async def talk_button(bot, update, user_record, data):
|
||||||
return await talk_button(bot, update, user_record, data)
|
return await _talk_button(bot, update, user_record, data)
|
||||||
|
|
||||||
@telegram_bot.command(command='/version',
|
@telegram_bot.command(command='/version',
|
||||||
aliases=[],
|
aliases=[],
|
||||||
@@ -2112,11 +2053,11 @@ def init(telegram_bot: Bot,
|
|||||||
},
|
},
|
||||||
show_in_keyboard=False,
|
show_in_keyboard=False,
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _version_command(bot, update, user_record, language):
|
async def version_command(bot, update, user_record, language):
|
||||||
return await version_command(bot=bot,
|
return await _version_command(bot=bot,
|
||||||
update=update,
|
update=update,
|
||||||
user_record=user_record,
|
user_record=user_record,
|
||||||
language=language)
|
language=language)
|
||||||
|
|
||||||
@telegram_bot.command(command='/config',
|
@telegram_bot.command(command='/config',
|
||||||
aliases=[],
|
aliases=[],
|
||||||
@@ -2127,11 +2068,8 @@ def init(telegram_bot: Bot,
|
|||||||
},
|
},
|
||||||
show_in_keyboard=False,
|
show_in_keyboard=False,
|
||||||
authorization_level='admin')
|
authorization_level='admin')
|
||||||
async def _config_command(bot, update, user_record, language):
|
async def config_command(bot, update, user_record, language):
|
||||||
return await config_command(bot=bot,
|
return await _config_command(bot=bot,
|
||||||
update=update,
|
update=update,
|
||||||
user_record=user_record,
|
user_record=user_record,
|
||||||
language=language)
|
language=language)
|
||||||
|
|
||||||
if len(telegram_bot.administrators) == 0:
|
|
||||||
asyncio.ensure_future(create_promotion_command(bot=telegram_bot))
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,34 @@
|
|||||||
|
|
||||||
camelCase methods mirror API directly, while snake_case ones act as middleware
|
camelCase methods mirror API directly, while snake_case ones act as middleware
|
||||||
someway.
|
someway.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
```
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from davtelepot.bot import Bot
|
||||||
|
|
||||||
|
from data.passwords import my_token, my_other_token
|
||||||
|
|
||||||
|
long_polling_bot = Bot(token=my_token, database_url='my_db')
|
||||||
|
webhook_bot = Bot(token=my_other_token, hostname='example.com',
|
||||||
|
certificate='path/to/certificate.pem',
|
||||||
|
database_url='my_other_db')
|
||||||
|
|
||||||
|
@long_polling_bot.command('/foo')
|
||||||
|
async def foo_command(bot, update, user_record, language):
|
||||||
|
return "Bar!"
|
||||||
|
|
||||||
|
@webhook_bot.command('/bar')
|
||||||
|
async def bar_command(bot, update, user_record, language):
|
||||||
|
return "Foo!"
|
||||||
|
|
||||||
|
exit_state = Bot.run(
|
||||||
|
local_host='127.0.0.5',
|
||||||
|
port=8552
|
||||||
|
)
|
||||||
|
sys.exit(exit_state)
|
||||||
|
```
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Standard library modules
|
# Standard library modules
|
||||||
@@ -21,9 +49,7 @@ from typing import Callable, List, Union, Dict
|
|||||||
import aiohttp.web
|
import aiohttp.web
|
||||||
|
|
||||||
# Project modules
|
# Project modules
|
||||||
from davtelepot.api import (
|
from davtelepot.api import TelegramBot, TelegramError
|
||||||
LinkPreviewOptions, ReplyParameters, TelegramBot, TelegramError
|
|
||||||
)
|
|
||||||
from davtelepot.database import ObjectWithDatabase
|
from davtelepot.database import ObjectWithDatabase
|
||||||
from davtelepot.languages import MultiLanguageObject
|
from davtelepot.languages import MultiLanguageObject
|
||||||
from davtelepot.messages import davtelepot_messages
|
from davtelepot.messages import davtelepot_messages
|
||||||
@@ -1293,21 +1319,19 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
|
|
||||||
async def send_message(self, chat_id: Union[int, str] = None,
|
async def send_message(self, chat_id: Union[int, str] = None,
|
||||||
text: str = None,
|
text: str = None,
|
||||||
message_thread_id: int = None,
|
|
||||||
entities: List[dict] = None,
|
entities: List[dict] = None,
|
||||||
parse_mode: str = 'HTML',
|
parse_mode: str = 'HTML',
|
||||||
link_preview_options: LinkPreviewOptions = None,
|
message_thread_id: int = None,
|
||||||
disable_notification: bool = None,
|
|
||||||
protect_content: bool = None,
|
protect_content: bool = None,
|
||||||
disable_web_page_preview: bool = None,
|
disable_web_page_preview: bool = None,
|
||||||
|
disable_notification: bool = None,
|
||||||
reply_to_message_id: int = None,
|
reply_to_message_id: int = None,
|
||||||
allow_sending_without_reply: bool = None,
|
allow_sending_without_reply: bool = None,
|
||||||
|
reply_markup=None,
|
||||||
update: dict = None,
|
update: dict = None,
|
||||||
reply_to_update: bool = False,
|
reply_to_update: bool = False,
|
||||||
send_default_keyboard: bool = True,
|
send_default_keyboard: bool = True,
|
||||||
user_record: OrderedDict = None,
|
user_record: OrderedDict = None):
|
||||||
reply_parameters: ReplyParameters = None,
|
|
||||||
reply_markup=None):
|
|
||||||
"""Send text via message(s).
|
"""Send text via message(s).
|
||||||
|
|
||||||
This method wraps lower-level `TelegramBot.sendMessage` method.
|
This method wraps lower-level `TelegramBot.sendMessage` method.
|
||||||
@@ -1328,10 +1352,6 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
user_record = self.db['users'].find_one(telegram_id=chat_id)
|
user_record = self.db['users'].find_one(telegram_id=chat_id)
|
||||||
if reply_to_update and 'message_id' in update:
|
if reply_to_update and 'message_id' in update:
|
||||||
reply_to_message_id = update['message_id']
|
reply_to_message_id = update['message_id']
|
||||||
if disable_web_page_preview:
|
|
||||||
if link_preview_options is None:
|
|
||||||
link_preview_options = LinkPreviewOptions()
|
|
||||||
link_preview_options['is_disabled'] = True
|
|
||||||
if (
|
if (
|
||||||
send_default_keyboard
|
send_default_keyboard
|
||||||
and reply_markup is None
|
and reply_markup is None
|
||||||
@@ -1375,27 +1395,19 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
limit=self.__class__.TELEGRAM_MESSAGES_MAX_LEN - 100,
|
limit=self.__class__.TELEGRAM_MESSAGES_MAX_LEN - 100,
|
||||||
parse_mode=parse_mode
|
parse_mode=parse_mode
|
||||||
)
|
)
|
||||||
if reply_to_message_id:
|
|
||||||
if reply_parameters is None:
|
|
||||||
reply_parameters = ReplyParameters(message_id=reply_to_message_id)
|
|
||||||
reply_parameters['message_id'] = reply_to_message_id
|
|
||||||
if allow_sending_without_reply:
|
|
||||||
reply_parameters['allow_sending_without_reply'] = allow_sending_without_reply
|
|
||||||
if reply_to_update and 'chat' in update and 'id' in update['chat']:
|
|
||||||
if update['chat']['id'] != chat_id:
|
|
||||||
reply_parameters['chat_id'] = update['chat']['id']
|
|
||||||
for text_chunk, is_last in text_chunks:
|
for text_chunk, is_last in text_chunks:
|
||||||
_reply_markup = (reply_markup if is_last else None)
|
_reply_markup = (reply_markup if is_last else None)
|
||||||
sent_message_update = await self.sendMessage(
|
sent_message_update = await self.sendMessage(
|
||||||
chat_id=chat_id,
|
chat_id=chat_id,
|
||||||
text=text_chunk,
|
text=text_chunk,
|
||||||
message_thread_id=message_thread_id,
|
|
||||||
parse_mode=parse_mode,
|
parse_mode=parse_mode,
|
||||||
entities=entities,
|
entities=entities,
|
||||||
link_preview_options=link_preview_options,
|
message_thread_id=message_thread_id,
|
||||||
disable_notification=disable_notification,
|
|
||||||
protect_content=protect_content,
|
protect_content=protect_content,
|
||||||
reply_parameters=reply_parameters,
|
disable_web_page_preview=disable_web_page_preview,
|
||||||
|
disable_notification=disable_notification,
|
||||||
|
reply_to_message_id=reply_to_message_id,
|
||||||
|
allow_sending_without_reply=allow_sending_without_reply,
|
||||||
reply_markup=_reply_markup
|
reply_markup=_reply_markup
|
||||||
)
|
)
|
||||||
return sent_message_update
|
return sent_message_update
|
||||||
@@ -1419,7 +1431,6 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
parse_mode: str = 'HTML',
|
parse_mode: str = 'HTML',
|
||||||
entities: List[dict] = None,
|
entities: List[dict] = None,
|
||||||
disable_web_page_preview: bool = None,
|
disable_web_page_preview: bool = None,
|
||||||
link_preview_options: LinkPreviewOptions = None,
|
|
||||||
allow_sending_without_reply: bool = None,
|
allow_sending_without_reply: bool = None,
|
||||||
reply_markup=None,
|
reply_markup=None,
|
||||||
update: dict = None):
|
update: dict = None):
|
||||||
@@ -1452,10 +1463,6 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
)
|
)
|
||||||
):
|
):
|
||||||
if i == 0:
|
if i == 0:
|
||||||
if disable_web_page_preview:
|
|
||||||
if link_preview_options is None:
|
|
||||||
link_preview_options = LinkPreviewOptions()
|
|
||||||
link_preview_options['is_disabled'] = True
|
|
||||||
edited_message = await self.editMessageText(
|
edited_message = await self.editMessageText(
|
||||||
text=text_chunk,
|
text=text_chunk,
|
||||||
chat_id=chat_id,
|
chat_id=chat_id,
|
||||||
@@ -1463,7 +1470,7 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
inline_message_id=inline_message_id,
|
inline_message_id=inline_message_id,
|
||||||
parse_mode=parse_mode,
|
parse_mode=parse_mode,
|
||||||
entities=entities,
|
entities=entities,
|
||||||
link_preview_options=link_preview_options,
|
disable_web_page_preview=disable_web_page_preview,
|
||||||
reply_markup=(reply_markup if is_last else None)
|
reply_markup=(reply_markup if is_last else None)
|
||||||
)
|
)
|
||||||
if chat_id is None:
|
if chat_id is None:
|
||||||
@@ -1569,7 +1576,6 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
reply_markup=None,
|
reply_markup=None,
|
||||||
update: dict = None,
|
update: dict = None,
|
||||||
reply_to_update: bool = False,
|
reply_to_update: bool = False,
|
||||||
reply_parameters: ReplyParameters = None,
|
|
||||||
send_default_keyboard: bool = True,
|
send_default_keyboard: bool = True,
|
||||||
use_stored_file_id: bool = True):
|
use_stored_file_id: bool = True):
|
||||||
"""Send photos.
|
"""Send photos.
|
||||||
@@ -1593,15 +1599,6 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
chat_id = self.get_chat_id(update)
|
chat_id = self.get_chat_id(update)
|
||||||
if reply_to_update and 'message_id' in update:
|
if reply_to_update and 'message_id' in update:
|
||||||
reply_to_message_id = update['message_id']
|
reply_to_message_id = update['message_id']
|
||||||
if reply_to_message_id:
|
|
||||||
if reply_parameters is None:
|
|
||||||
reply_parameters = ReplyParameters(message_id=reply_to_message_id)
|
|
||||||
reply_parameters['message_id'] = reply_to_message_id
|
|
||||||
if allow_sending_without_reply:
|
|
||||||
reply_parameters['allow_sending_without_reply'] = allow_sending_without_reply
|
|
||||||
if reply_to_update and 'chat' in update and 'id' in update['chat']:
|
|
||||||
if update['chat']['id'] != chat_id:
|
|
||||||
reply_parameters['chat_id'] = update['chat']['id']
|
|
||||||
if (
|
if (
|
||||||
send_default_keyboard
|
send_default_keyboard
|
||||||
and reply_markup is None
|
and reply_markup is None
|
||||||
@@ -1655,7 +1652,8 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
parse_mode=parse_mode,
|
parse_mode=parse_mode,
|
||||||
caption_entities=caption_entities,
|
caption_entities=caption_entities,
|
||||||
disable_notification=disable_notification,
|
disable_notification=disable_notification,
|
||||||
reply_parameters=reply_parameters,
|
reply_to_message_id=reply_to_message_id,
|
||||||
|
allow_sending_without_reply=allow_sending_without_reply,
|
||||||
reply_markup=reply_markup
|
reply_markup=reply_markup
|
||||||
)
|
)
|
||||||
if isinstance(sent_update, Exception):
|
if isinstance(sent_update, Exception):
|
||||||
@@ -1703,7 +1701,6 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
reply_markup=None,
|
reply_markup=None,
|
||||||
update: dict = None,
|
update: dict = None,
|
||||||
reply_to_update: bool = False,
|
reply_to_update: bool = False,
|
||||||
reply_parameters: ReplyParameters = None,
|
|
||||||
send_default_keyboard: bool = True,
|
send_default_keyboard: bool = True,
|
||||||
use_stored_file_id: bool = True):
|
use_stored_file_id: bool = True):
|
||||||
"""Send audio files.
|
"""Send audio files.
|
||||||
@@ -1727,15 +1724,6 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
chat_id = self.get_chat_id(update)
|
chat_id = self.get_chat_id(update)
|
||||||
if reply_to_update and 'message_id' in update:
|
if reply_to_update and 'message_id' in update:
|
||||||
reply_to_message_id = update['message_id']
|
reply_to_message_id = update['message_id']
|
||||||
if reply_to_message_id:
|
|
||||||
if reply_parameters is None:
|
|
||||||
reply_parameters = ReplyParameters(message_id=reply_to_message_id)
|
|
||||||
reply_parameters['message_id'] = reply_to_message_id
|
|
||||||
if allow_sending_without_reply:
|
|
||||||
reply_parameters['allow_sending_without_reply'] = allow_sending_without_reply
|
|
||||||
if reply_to_update and 'chat' in update and 'id' in update['chat']:
|
|
||||||
if update['chat']['id'] != chat_id:
|
|
||||||
reply_parameters['chat_id'] = update['chat']['id']
|
|
||||||
if (
|
if (
|
||||||
send_default_keyboard
|
send_default_keyboard
|
||||||
and reply_markup is None
|
and reply_markup is None
|
||||||
@@ -1793,7 +1781,8 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
title=title,
|
title=title,
|
||||||
thumbnail=thumbnail,
|
thumbnail=thumbnail,
|
||||||
disable_notification=disable_notification,
|
disable_notification=disable_notification,
|
||||||
reply_parameters=reply_parameters,
|
reply_to_message_id=reply_to_message_id,
|
||||||
|
allow_sending_without_reply=allow_sending_without_reply,
|
||||||
reply_markup=reply_markup
|
reply_markup=reply_markup
|
||||||
)
|
)
|
||||||
if isinstance(sent_update, Exception):
|
if isinstance(sent_update, Exception):
|
||||||
@@ -1837,7 +1826,6 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
reply_markup=None,
|
reply_markup=None,
|
||||||
update: dict = None,
|
update: dict = None,
|
||||||
reply_to_update: bool = False,
|
reply_to_update: bool = False,
|
||||||
reply_parameters: ReplyParameters = None,
|
|
||||||
send_default_keyboard: bool = True,
|
send_default_keyboard: bool = True,
|
||||||
use_stored_file_id: bool = True):
|
use_stored_file_id: bool = True):
|
||||||
"""Send voice messages.
|
"""Send voice messages.
|
||||||
@@ -1861,15 +1849,6 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
chat_id = self.get_chat_id(update)
|
chat_id = self.get_chat_id(update)
|
||||||
if reply_to_update and 'message_id' in update:
|
if reply_to_update and 'message_id' in update:
|
||||||
reply_to_message_id = update['message_id']
|
reply_to_message_id = update['message_id']
|
||||||
if reply_to_message_id:
|
|
||||||
if reply_parameters is None:
|
|
||||||
reply_parameters = ReplyParameters(message_id=reply_to_message_id)
|
|
||||||
reply_parameters['message_id'] = reply_to_message_id
|
|
||||||
if allow_sending_without_reply:
|
|
||||||
reply_parameters['allow_sending_without_reply'] = allow_sending_without_reply
|
|
||||||
if reply_to_update and 'chat' in update and 'id' in update['chat']:
|
|
||||||
if update['chat']['id'] != chat_id:
|
|
||||||
reply_parameters['chat_id'] = update['chat']['id']
|
|
||||||
if (
|
if (
|
||||||
send_default_keyboard
|
send_default_keyboard
|
||||||
and reply_markup is None
|
and reply_markup is None
|
||||||
@@ -1924,7 +1903,8 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
caption_entities=caption_entities,
|
caption_entities=caption_entities,
|
||||||
duration=duration,
|
duration=duration,
|
||||||
disable_notification=disable_notification,
|
disable_notification=disable_notification,
|
||||||
reply_parameters=reply_parameters,
|
reply_to_message_id=reply_to_message_id,
|
||||||
|
allow_sending_without_reply=allow_sending_without_reply,
|
||||||
reply_markup=reply_markup
|
reply_markup=reply_markup
|
||||||
)
|
)
|
||||||
if isinstance(sent_update, Exception):
|
if isinstance(sent_update, Exception):
|
||||||
@@ -1971,7 +1951,6 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
document_name: str = None,
|
document_name: str = None,
|
||||||
update: dict = None,
|
update: dict = None,
|
||||||
reply_to_update: bool = False,
|
reply_to_update: bool = False,
|
||||||
reply_parameters: ReplyParameters = None,
|
|
||||||
send_default_keyboard: bool = True,
|
send_default_keyboard: bool = True,
|
||||||
use_stored_file_id: bool = False):
|
use_stored_file_id: bool = False):
|
||||||
"""Send a document.
|
"""Send a document.
|
||||||
@@ -2004,15 +1983,6 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
return
|
return
|
||||||
if reply_to_update and 'message_id' in update:
|
if reply_to_update and 'message_id' in update:
|
||||||
reply_to_message_id = update['message_id']
|
reply_to_message_id = update['message_id']
|
||||||
if reply_to_message_id:
|
|
||||||
if reply_parameters is None:
|
|
||||||
reply_parameters = ReplyParameters(message_id=reply_to_message_id)
|
|
||||||
reply_parameters['message_id'] = reply_to_message_id
|
|
||||||
if allow_sending_without_reply:
|
|
||||||
reply_parameters['allow_sending_without_reply'] = allow_sending_without_reply
|
|
||||||
if reply_to_update and 'chat' in update and 'id' in update['chat']:
|
|
||||||
if update['chat']['id'] != chat_id:
|
|
||||||
reply_parameters['chat_id'] = update['chat']['id']
|
|
||||||
if chat_id > 0:
|
if chat_id > 0:
|
||||||
user_record = self.db['users'].find_one(telegram_id=chat_id)
|
user_record = self.db['users'].find_one(telegram_id=chat_id)
|
||||||
language = self.get_language(update=update, user_record=user_record)
|
language = self.get_language(update=update, user_record=user_record)
|
||||||
@@ -2091,7 +2061,7 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
caption=caption,
|
caption=caption,
|
||||||
parse_mode=parse_mode,
|
parse_mode=parse_mode,
|
||||||
disable_notification=disable_notification,
|
disable_notification=disable_notification,
|
||||||
reply_parameters=reply_parameters,
|
reply_to_message_id=reply_to_message_id,
|
||||||
reply_markup=reply_markup,
|
reply_markup=reply_markup,
|
||||||
update=update,
|
update=update,
|
||||||
reply_to_update=reply_to_update,
|
reply_to_update=reply_to_update,
|
||||||
@@ -2122,7 +2092,8 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
caption_entities=caption_entities,
|
caption_entities=caption_entities,
|
||||||
disable_content_type_detection=disable_content_type_detection,
|
disable_content_type_detection=disable_content_type_detection,
|
||||||
disable_notification=disable_notification,
|
disable_notification=disable_notification,
|
||||||
reply_parameters=reply_parameters,
|
reply_to_message_id=reply_to_message_id,
|
||||||
|
allow_sending_without_reply=allow_sending_without_reply,
|
||||||
reply_markup=reply_markup
|
reply_markup=reply_markup
|
||||||
)
|
)
|
||||||
if isinstance(sent_update, Exception):
|
if isinstance(sent_update, Exception):
|
||||||
@@ -2156,8 +2127,7 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
return sent_update
|
return sent_update
|
||||||
|
|
||||||
async def download_file(self, file_id,
|
async def download_file(self, file_id,
|
||||||
file_name=None, path=None,
|
file_name=None, path=None):
|
||||||
prevent_overwriting: bool = False):
|
|
||||||
"""Given a telegram `file_id`, download the related file.
|
"""Given a telegram `file_id`, download the related file.
|
||||||
|
|
||||||
Telegram may not preserve the original file name and MIME type: the
|
Telegram may not preserve the original file name and MIME type: the
|
||||||
@@ -2181,9 +2151,8 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
if file_name is None:
|
if file_name is None:
|
||||||
file_name = get_secure_key(length=10)
|
file_name = get_secure_key(length=10)
|
||||||
file_complete_path = os.path.join(path, file_name)
|
file_complete_path = os.path.join(path, file_name)
|
||||||
if prevent_overwriting:
|
while os.path.exists(file_complete_path):
|
||||||
while os.path.exists(file_complete_path):
|
file_complete_path = file_complete_path + '1'
|
||||||
file_complete_path = file_complete_path + '1'
|
|
||||||
try:
|
try:
|
||||||
with open(file_complete_path, 'wb') as local_file:
|
with open(file_complete_path, 'wb') as local_file:
|
||||||
local_file.write(file_bytes)
|
local_file.write(file_bytes)
|
||||||
@@ -3534,7 +3503,7 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
Each bot will receive updates via long polling or webhook according to
|
Each bot will receive updates via long polling or webhook according to
|
||||||
its initialization parameters.
|
its initialization parameters.
|
||||||
A single aiohttp.web.Application instance will be run (cls.app) on
|
A single aiohttp.web.Application instance will be run (cls.app) on
|
||||||
local_host:port, and it may serve custom-defined routes as well.
|
local_host:port and it may serve custom-defined routes as well.
|
||||||
"""
|
"""
|
||||||
if local_host is not None:
|
if local_host is not None:
|
||||||
cls.local_host = local_host
|
cls.local_host = local_host
|
||||||
|
|||||||
@@ -22,16 +22,6 @@ davtelepot_messages = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default_admin_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': {
|
'cancel': {
|
||||||
'button': {
|
'button': {
|
||||||
'en': "↩️ Cancel",
|
'en': "↩️ Cancel",
|
||||||
|
|||||||
Reference in New Issue
Block a user