From afc538952094729f81735784d4a3704e2329651c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ar=C4=89i?= Date: Sat, 29 Oct 2022 18:52:08 +0600 Subject: [PATCH 1/6] support multiple comma-separated values in ADMIN_ID --- main.py | 2 +- olgram/settings.py | 6 +++--- olgram/utils/permissions.py | 21 +++++++++++---------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index b901bb3..2c43145 100644 --- a/main.py +++ b/main.py @@ -25,7 +25,7 @@ async def init_database(): async def init_olgram(): from olgram.router import bot, dp - dp.setup_middleware(AccessMiddleware(OlgramSettings.admin_id())) + dp.setup_middleware(AccessMiddleware(OlgramSettings.admin_ids())) from aiogram.types import BotCommand await bot.set_my_commands( [ diff --git a/olgram/settings.py b/olgram/settings.py index 704ff7c..ab00348 100644 --- a/olgram/settings.py +++ b/olgram/settings.py @@ -45,9 +45,9 @@ class OlgramSettings(AbstractSettings): @classmethod @lru_cache - def admin_id(cls): - _id = cls._get_env("ADMIN_ID", True) - return int(_id) if _id else None + def admin_ids(cls): + _ids = cls._get_env("ADMIN_ID", True) + return set(map(int, _ids.split(","))) if _ids else None @classmethod @lru_cache diff --git a/olgram/utils/permissions.py b/olgram/utils/permissions.py index d1ad567..18209b2 100644 --- a/olgram/utils/permissions.py +++ b/olgram/utils/permissions.py @@ -1,6 +1,7 @@ import aiogram.types as types from aiogram.dispatcher.handler import CancelHandler, current_handler from aiogram.dispatcher.middlewares import BaseMiddleware +from collections.abc import Container from locales.locale import _ @@ -19,8 +20,8 @@ def public(): class AccessMiddleware(BaseMiddleware): - def __init__(self, access_chat_id: int): - self._access_chat_id = access_chat_id + def __init__(self, access_chat_ids: Container[int]): + self._access_chat_ids = access_chat_ids super(AccessMiddleware, self).__init__() @classmethod @@ -29,25 +30,25 @@ class AccessMiddleware(BaseMiddleware): return handler and getattr(handler, "access_public", False) async def on_process_message(self, message: types.Message, data: dict): - admin_id = self._access_chat_id - if not admin_id: - return # Администратор бота вообще не указан + admin_ids = self._access_chat_ids + if not admin_ids: + return # Администраторы бота вообще не указаны if self._is_public_command(): # Эта команда разрешена всем пользователям return - if message.chat.id != admin_id: + if message.chat.id not in admin_ids: await message.answer(_("Владелец бота ограничил доступ к этому функционалу 😞")) raise CancelHandler() async def on_process_callback_query(self, call: types.CallbackQuery, data: dict): - admin_id = self._access_chat_id - if not admin_id: - return # Администратор бота вообще не указан + admin_ids = self._access_chat_ids + if not admin_ids: + return # Администраторы бота вообще не указаны if self._is_public_command(): # Эта команда разрешена всем пользователям return - if call.message.chat.id != admin_id: + if call.message.chat.id not in admin_ids: await call.answer(_("Владелец бота ограничил доступ к этому функционалу😞")) raise CancelHandler() From 52864ed729200522821b615431174b57df688cbb Mon Sep 17 00:00:00 2001 From: walker Date: Sat, 29 Oct 2022 19:32:56 +0400 Subject: [PATCH 2/6] fix #19 --- locales/en/LC_MESSAGES/olgram.po | 4 ++-- locales/uk/LC_MESSAGES/olgram.po | 4 ++-- olgram/commands/promo.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/locales/en/LC_MESSAGES/olgram.po b/locales/en/LC_MESSAGES/olgram.po index 597aa77..397da69 100644 --- a/locales/en/LC_MESSAGES/olgram.po +++ b/locales/en/LC_MESSAGES/olgram.po @@ -549,9 +549,9 @@ msgstr "Promotion code withdrawn" #: olgram/commands/promo.py:70 msgid "" -"Укажите аргумент: промокод. Например:
/set_promo my-promo-code
" +"Укажите аргумент: промокод. Например:
/setpromo my-promo-code
" msgstr "" -"Specify the argument: promo code. For example:
/set_promo my-promo-"
+"Specify the argument: promo code. For example: 
/setpromo my-promo-"
 "code
" #: olgram/commands/promo.py:78 olgram/commands/promo.py:82 diff --git a/locales/uk/LC_MESSAGES/olgram.po b/locales/uk/LC_MESSAGES/olgram.po index 75e8b72..dfdd098 100644 --- a/locales/uk/LC_MESSAGES/olgram.po +++ b/locales/uk/LC_MESSAGES/olgram.po @@ -556,9 +556,9 @@ msgstr "Промокод відкликаний" #: olgram/commands/promo.py:70 msgid "" -"Укажите аргумент: промокод. Например:
/set_promo my-promo-code
" +"Укажите аргумент: промокод. Например:
/setpromo my-promo-code
" msgstr "" -"Зазначте аргумент: промокод. Наприклад:
/set_promo my-promo-code
" +"Зазначте аргумент: промокод. Наприклад:
/setpromo my-promo-code
" #: olgram/commands/promo.py:78 olgram/commands/promo.py:82 msgid "Промокод не найден" diff --git a/olgram/commands/promo.py b/olgram/commands/promo.py index 486bdb8..fe535e3 100644 --- a/olgram/commands/promo.py +++ b/olgram/commands/promo.py @@ -60,14 +60,14 @@ async def del_promo(message: types.Message, state: FSMContext): @dp.message_handler(commands=["setpromo"], state="*") -async def set_promo(message: types.Message, state: FSMContext): +async def setpromo(message: types.Message, state: FSMContext): """ Команда /setpromo """ arg = message.get_args() if not arg: - return await message.answer(_("Укажите аргумент: промокод. Например:
/set_promo my-promo-code
"), + return await message.answer(_("Укажите аргумент: промокод. Например:
/setpromo my-promo-code
"), parse_mode="HTML") arg = arg.strip() From d478e9d8e92a10ab69cb987f02ca1ade938cac68 Mon Sep 17 00:00:00 2001 From: walker Date: Sat, 29 Oct 2022 19:34:13 +0400 Subject: [PATCH 3/6] version bump --- olgram/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/olgram/settings.py b/olgram/settings.py index ab00348..56524a3 100644 --- a/olgram/settings.py +++ b/olgram/settings.py @@ -41,7 +41,7 @@ class OlgramSettings(AbstractSettings): @classmethod def version(cls): - return "0.4.3" + return "0.5.0" @classmethod @lru_cache From 6acc2068dec10b2ed2ef2e636af7846d172d323c Mon Sep 17 00:00:00 2001 From: walker Date: Sat, 29 Oct 2022 20:14:50 +0400 Subject: [PATCH 4/6] fix for prev --- olgram/utils/permissions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/olgram/utils/permissions.py b/olgram/utils/permissions.py index 18209b2..21954b7 100644 --- a/olgram/utils/permissions.py +++ b/olgram/utils/permissions.py @@ -1,7 +1,7 @@ import aiogram.types as types from aiogram.dispatcher.handler import CancelHandler, current_handler from aiogram.dispatcher.middlewares import BaseMiddleware -from collections.abc import Container +import typing as ty from locales.locale import _ @@ -20,7 +20,7 @@ def public(): class AccessMiddleware(BaseMiddleware): - def __init__(self, access_chat_ids: Container[int]): + def __init__(self, access_chat_ids: ty.Iterable[int]): self._access_chat_ids = access_chat_ids super(AccessMiddleware, self).__init__() From 756f0bd89af4cc7ace87abaeaa6d4e58e12a568b Mon Sep 17 00:00:00 2001 From: walker Date: Sat, 5 Nov 2022 00:40:26 +0400 Subject: [PATCH 5/6] minor fixes --- example.env | 4 ++-- olgram/settings.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example.env b/example.env index 0a79f40..11fa00e 100644 --- a/example.env +++ b/example.env @@ -31,5 +31,5 @@ REDIS_PATH=redis://redis # Set log level, can be CRITICAL, ERROR, WARNING, INFO, DEBUG. By default it set to WARNING. LOGLEVEL= -# Uncomment this to switch bot language to Chinese -# O_LANG=zh +# Uncomment this to switch bot language to English +# O_LANG=en diff --git a/olgram/settings.py b/olgram/settings.py index 56524a3..fed833f 100644 --- a/olgram/settings.py +++ b/olgram/settings.py @@ -105,7 +105,7 @@ class ServerSettings(AbstractSettings): return int(timedelta(days=1).total_seconds() * 1000.0) -logging.basicConfig(level=os.environ.get("LOGLEVEL", "WARNING"), +logging.basicConfig(level=os.environ.get("LOGLEVEL") or "WARNING", format='%(asctime)s %(levelname)-8s %(message)s') From bb1456dda1e6da83b48f568592bf48d196b8d87e Mon Sep 17 00:00:00 2001 From: walker Date: Sat, 5 Nov 2022 00:42:11 +0400 Subject: [PATCH 6/6] fix location forwarding --- server/custom.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/custom.py b/server/custom.py index d17aed6..837cfd5 100644 --- a/server/custom.py +++ b/server/custom.py @@ -319,7 +319,8 @@ class CustomRequestHandler(WebhookRequestHandler): types.ContentType.PHOTO, types.ContentType.STICKER, types.ContentType.VIDEO, - types.ContentType.VOICE] + types.ContentType.VOICE, + types.ContentType.LOCATION] dp.register_message_handler(message_handler, content_types=supported_messages) dp.register_edited_message_handler(edited_message_handler, content_types=supported_messages)