Import statements refactored

This commit is contained in:
Davte 2020-11-15 21:34:18 +01:00
parent 773fe1fdb1
commit fda4cac348
Signed by: Davte
GPG Key ID: 209AE674A0007425
6 changed files with 35 additions and 16 deletions

View File

@ -15,8 +15,8 @@ __version__ = "2.6.19"
__maintainer__ = "Davide Testa"
__contact__ = "t.me/davte"
from . import (administration_tools, authorization, bot, helper, languages,
suggestions, useful_tools, utilities)
from . import (administration_tools, api, authorization, bot, helper, languages,
messages, suggestions, useful_tools, utilities)
__all__ = [administration_tools, authorization, bot, helper, languages,
suggestions, useful_tools, utilities]
__all__ = [administration_tools, api, authorization, bot, helper, languages,
messages, suggestions, useful_tools, utilities]

View File

@ -23,7 +23,7 @@ from typing import Union, List, Tuple
from sqlalchemy.exc import ResourceClosedError
# Project modules
from . import messages
from .messages import default_admin_messages, default_talk_messages
from .bot import Bot
from .utilities import (
async_wrapper, CachedPage, Confirmator, extract, get_cleaned_text,
@ -362,7 +362,10 @@ async def _talk_button(bot: Bot,
len(arguments) < 1
or type(arguments[0]) is not int
):
result = "Errore!"
result = bot.get_message(
'talk', 'error', 'text',
update=update, user_record=user_record
)
else:
with bot.db as db:
other_user_record = db['users'].find_one(
@ -381,7 +384,10 @@ async def _talk_button(bot: Bot,
len(arguments) < 1
or type(arguments[0]) is not int
):
result = "Errore!"
result = bot.get_message(
'talk', 'error', 'text',
update=update, user_record=user_record
)
elif not Confirmator.get('stop_bots').confirm(telegram_id):
result = bot.get_message(
'talk', 'end_session',
@ -1705,7 +1711,7 @@ async def _father_button(bot: Bot, user_record: OrderedDict,
prefix='father:///',
delimiter='|',
data=['settings', 'edit', 'select',
selected_record['id'], 'edit_descr']
selected_record['id'], 'edit_description']
),
make_button(
text=bot.get_message(
@ -1731,7 +1737,7 @@ async def _father_button(bot: Bot, user_record: OrderedDict,
],
2
)
elif len(data) > 3 and data[3] == 'edit_descr':
elif len(data) > 3 and data[3] == 'edit_description':
result, text, reply_markup = await edit_bot_father_settings_via_message(
bot=bot,
user_record=user_record,
@ -1812,10 +1818,10 @@ def init(telegram_bot: Bot,
)
asyncio.ensure_future(get_package_updates(telegram_bot))
if talk_messages is None:
talk_messages = messages.default_talk_messages
talk_messages = default_talk_messages
telegram_bot.messages['talk'] = talk_messages
if admin_messages is None:
admin_messages = messages.default_admin_messages
admin_messages = default_admin_messages
telegram_bot.messages['admin'] = admin_messages
db = telegram_bot.db
if 'bot_father_commands' not in db.tables:

View File

@ -10,7 +10,7 @@ import aiohttp
from bs4 import BeautifulSoup
# Project modules
from . import api
from .api import TelegramBot
api_url = "https://core.telegram.org/bots/api"
@ -105,7 +105,7 @@ async def print_api_methods(loop=None,
"""Get information from Telegram bot API web page."""
if loop is None:
loop = asyncio.get_event_loop()
implemented_methods = dir(api.TelegramBot)
implemented_methods = dir(TelegramBot)
async with aiohttp.ClientSession(
loop=loop,
timeout=aiohttp.ClientTimeout(

View File

@ -3225,9 +3225,14 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
and 'photos' in user_profile_photos
and len(user_profile_photos['photos'])):
current_photo = user_profile_photos['photos'][0][0]
if (user_picture_record is None
or current_photo['file_id']
!= user_picture_record['telegram_file_id']):
if (
user_picture_record is None
or (
isinstance(user_picture_record, dict)
and current_photo['file_id']
!= user_picture_record['telegram_file_id']
)
):
db['user_profile_photos'].insert(dict(
user_id=user_record['id'],
telegram_file_id=current_photo['file_id'],

View File

@ -985,6 +985,12 @@ default_talk_messages = {
'en': 'End session?',
'it': 'Chiudere la sessione?',
},
'error': {
'text': {
'en': "❌️ Error!",
'it': "❌️ Errore!"
},
},
'help_text': {
'en': 'Press the button to search for user.',
'it': 'Premi il pulsante per scegliere un utente.',

View File

@ -1,3 +1,5 @@
aiohttp
bs4
dataset
beautifulsoup4
SQLAlchemy