From 41bc5b68a427b42c0ea658cec727b146c7622b67 Mon Sep 17 00:00:00 2001 From: Davte Date: Mon, 20 Apr 2020 18:20:44 +0200 Subject: [PATCH 1/4] Fix authorization function so that it extracts user_record from update --- davtelepot/__init__.py | 2 +- davtelepot/authorization.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index 3fa5e64..398057a 100644 --- a/davtelepot/__init__.py +++ b/davtelepot/__init__.py @@ -14,7 +14,7 @@ __author__ = "Davide Testa" __email__ = "davide@davte.it" __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __license__ = "GNU General Public License v3.0" -__version__ = "2.4.19" +__version__ = "2.4.20" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/davtelepot/authorization.py b/davtelepot/authorization.py index 0ace3e2..4738e33 100644 --- a/davtelepot/authorization.py +++ b/davtelepot/authorization.py @@ -235,6 +235,16 @@ def get_authorization_function(bot): def is_authorized(update, user_record=None, authorization_level=2): """Return True if user role is at least at `authorization_level`.""" + if user_record is None: + if ( + isinstance(update, dict) + and 'from' in update + and isinstance(update['from'], dict) + and 'id' in update['from'] + ): + user_record = bot.db['users'].find_one( + telegram_id=update['from']['id'] + ) user_role = bot.Role.get_user_role(user_record=user_record) if user_role.code == 0: return False From 5b215c584415578304c02948654efd2c306bbb41 Mon Sep 17 00:00:00 2001 From: Davte Date: Mon, 20 Apr 2020 18:21:37 +0200 Subject: [PATCH 2/4] New version --- davtelepot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index 398057a..acdf25d 100644 --- a/davtelepot/__init__.py +++ b/davtelepot/__init__.py @@ -14,7 +14,7 @@ __author__ = "Davide Testa" __email__ = "davide@davte.it" __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __license__ = "GNU General Public License v3.0" -__version__ = "2.4.20" +__version__ = "2.4.21" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" From 5439bb7ddfd0091286d013ec22d763c6ff4d25f1 Mon Sep 17 00:00:00 2001 From: Davte Date: Mon, 20 Apr 2020 18:23:30 +0200 Subject: [PATCH 3/4] Typo in italian /version command --- davtelepot/__init__.py | 2 +- davtelepot/messages.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index acdf25d..0d27f84 100644 --- a/davtelepot/__init__.py +++ b/davtelepot/__init__.py @@ -14,7 +14,7 @@ __author__ = "Davide Testa" __email__ = "davide@davte.it" __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __license__ = "GNU General Public License v3.0" -__version__ = "2.4.21" +__version__ = "2.4.22" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/davtelepot/messages.py b/davtelepot/messages.py index 651b5e4..5e2071e 100644 --- a/davtelepot/messages.py +++ b/davtelepot/messages.py @@ -249,8 +249,8 @@ default_admin_messages = { 'result': { 'en': "Last commit: {last_commit}\n" "davtelepot version: {davtelepot_version}", - 'it': "Ultimo commit: {last_commit}" - "Version di davtelepot: {davtelepot_version}", + 'it': "Ultimo commit: {last_commit}\n" + "Versione di davtelepot: {davtelepot_version}", }, } } From 9c73337c53a8cc527ca17ea22764480071ad8c35 Mon Sep 17 00:00:00 2001 From: Davte Date: Mon, 20 Apr 2020 19:01:58 +0200 Subject: [PATCH 4/4] Allow multilanguage support for inline query answers --- davtelepot/__init__.py | 2 +- davtelepot/api.py | 3 ++- davtelepot/bot.py | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index 0d27f84..e504cd2 100644 --- a/davtelepot/__init__.py +++ b/davtelepot/__init__.py @@ -14,7 +14,7 @@ __author__ = "Davide Testa" __email__ = "davide@davte.it" __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __license__ = "GNU General Public License v3.0" -__version__ = "2.4.22" +__version__ = "2.4.23" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/davtelepot/api.py b/davtelepot/api.py index a8de1e7..91f9b91 100644 --- a/davtelepot/api.py +++ b/davtelepot/api.py @@ -18,7 +18,8 @@ from aiohttp import web class TelegramError(Exception): """Telegram API exceptions class.""" - def __init__(self, error_code=0, description=None): + def __init__(self, error_code=0, description=None, ok=False, + *args, **kwargs): """Get an error response and return corresponding Exception.""" self._code = error_code if description is None: diff --git a/davtelepot/bot.py b/davtelepot/bot.py index fba6d3c..8df64a3 100644 --- a/davtelepot/bot.py +++ b/davtelepot/bot.py @@ -607,6 +607,32 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject): if 'switch_pm_parameter' in results: switch_pm_parameter = results['switch_pm_parameter'] results = results['answer'] + for result in results: + if ( + isinstance(result, dict) + and isinstance(result['title'], dict) + ): + result['title'] = self.get_message( + update=update, + user_record=user_record, + messages=result['title'] + ) + if ( + isinstance(result, dict) + and 'input_message_content' in result + and isinstance(result['input_message_content'], dict) + and 'message_text' in result['input_message_content'] + and isinstance( + result['input_message_content']['message_text'], + dict + ) + ): + result['input_message_content'][ + 'message_text'] = self.get_message( + update=update, + user_record=user_record, + messages=result['input_message_content']['message_text'] + ) try: await self.answer_inline_query( update=update,