mirror of
https://github.com/civsocit/olgram.git
synced 2023-07-22 01:29:12 +03:00
Merge branch 'main' into stable
This commit is contained in:
commit
a262d4e488
@ -31,5 +31,5 @@ REDIS_PATH=redis://redis
|
|||||||
# Set log level, can be CRITICAL, ERROR, WARNING, INFO, DEBUG. By default it set to WARNING.
|
# Set log level, can be CRITICAL, ERROR, WARNING, INFO, DEBUG. By default it set to WARNING.
|
||||||
LOGLEVEL=
|
LOGLEVEL=
|
||||||
|
|
||||||
# Uncomment this to switch bot language to Chinese
|
# Uncomment this to switch bot language to English
|
||||||
# O_LANG=zh
|
# O_LANG=en
|
||||||
|
@ -549,9 +549,9 @@ msgstr "Promotion code withdrawn"
|
|||||||
|
|
||||||
#: olgram/commands/promo.py:70
|
#: olgram/commands/promo.py:70
|
||||||
msgid ""
|
msgid ""
|
||||||
"Укажите аргумент: промокод. Например: <pre>/set_promo my-promo-code</pre>"
|
"Укажите аргумент: промокод. Например: <pre>/setpromo my-promo-code</pre>"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Specify the argument: promo code. For example: <pre>/set_promo my-promo-"
|
"Specify the argument: promo code. For example: <pre>/setpromo my-promo-"
|
||||||
"code</pre>"
|
"code</pre>"
|
||||||
|
|
||||||
#: olgram/commands/promo.py:78 olgram/commands/promo.py:82
|
#: olgram/commands/promo.py:78 olgram/commands/promo.py:82
|
||||||
|
@ -556,9 +556,9 @@ msgstr "Промокод відкликаний"
|
|||||||
|
|
||||||
#: olgram/commands/promo.py:70
|
#: olgram/commands/promo.py:70
|
||||||
msgid ""
|
msgid ""
|
||||||
"Укажите аргумент: промокод. Например: <pre>/set_promo my-promo-code</pre>"
|
"Укажите аргумент: промокод. Например: <pre>/setpromo my-promo-code</pre>"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Зазначте аргумент: промокод. Наприклад: <pre>/set_promo my-promo-code</pre>"
|
"Зазначте аргумент: промокод. Наприклад: <pre>/setpromo my-promo-code</pre>"
|
||||||
|
|
||||||
#: olgram/commands/promo.py:78 olgram/commands/promo.py:82
|
#: olgram/commands/promo.py:78 olgram/commands/promo.py:82
|
||||||
msgid "Промокод не найден"
|
msgid "Промокод не найден"
|
||||||
|
2
main.py
2
main.py
@ -25,7 +25,7 @@ async def init_database():
|
|||||||
|
|
||||||
async def init_olgram():
|
async def init_olgram():
|
||||||
from olgram.router import bot, dp
|
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
|
from aiogram.types import BotCommand
|
||||||
await bot.set_my_commands(
|
await bot.set_my_commands(
|
||||||
[
|
[
|
||||||
|
@ -60,14 +60,14 @@ async def del_promo(message: types.Message, state: FSMContext):
|
|||||||
|
|
||||||
|
|
||||||
@dp.message_handler(commands=["setpromo"], state="*")
|
@dp.message_handler(commands=["setpromo"], state="*")
|
||||||
async def set_promo(message: types.Message, state: FSMContext):
|
async def setpromo(message: types.Message, state: FSMContext):
|
||||||
"""
|
"""
|
||||||
Команда /setpromo
|
Команда /setpromo
|
||||||
"""
|
"""
|
||||||
|
|
||||||
arg = message.get_args()
|
arg = message.get_args()
|
||||||
if not arg:
|
if not arg:
|
||||||
return await message.answer(_("Укажите аргумент: промокод. Например: <pre>/set_promo my-promo-code</pre>"),
|
return await message.answer(_("Укажите аргумент: промокод. Например: <pre>/setpromo my-promo-code</pre>"),
|
||||||
parse_mode="HTML")
|
parse_mode="HTML")
|
||||||
|
|
||||||
arg = arg.strip()
|
arg = arg.strip()
|
||||||
|
@ -41,13 +41,13 @@ class OlgramSettings(AbstractSettings):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def version(cls):
|
def version(cls):
|
||||||
return "0.4.3"
|
return "0.5.0"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@lru_cache
|
@lru_cache
|
||||||
def admin_id(cls):
|
def admin_ids(cls):
|
||||||
_id = cls._get_env("ADMIN_ID", True)
|
_ids = cls._get_env("ADMIN_ID", True)
|
||||||
return int(_id) if _id else None
|
return set(map(int, _ids.split(","))) if _ids else None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@lru_cache
|
@lru_cache
|
||||||
@ -105,7 +105,7 @@ class ServerSettings(AbstractSettings):
|
|||||||
return int(timedelta(days=1).total_seconds() * 1000.0)
|
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')
|
format='%(asctime)s %(levelname)-8s %(message)s')
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import aiogram.types as types
|
import aiogram.types as types
|
||||||
from aiogram.dispatcher.handler import CancelHandler, current_handler
|
from aiogram.dispatcher.handler import CancelHandler, current_handler
|
||||||
from aiogram.dispatcher.middlewares import BaseMiddleware
|
from aiogram.dispatcher.middlewares import BaseMiddleware
|
||||||
|
import typing as ty
|
||||||
from locales.locale import _
|
from locales.locale import _
|
||||||
|
|
||||||
|
|
||||||
@ -19,8 +20,8 @@ def public():
|
|||||||
|
|
||||||
|
|
||||||
class AccessMiddleware(BaseMiddleware):
|
class AccessMiddleware(BaseMiddleware):
|
||||||
def __init__(self, access_chat_id: int):
|
def __init__(self, access_chat_ids: ty.Iterable[int]):
|
||||||
self._access_chat_id = access_chat_id
|
self._access_chat_ids = access_chat_ids
|
||||||
super(AccessMiddleware, self).__init__()
|
super(AccessMiddleware, self).__init__()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -29,25 +30,25 @@ class AccessMiddleware(BaseMiddleware):
|
|||||||
return handler and getattr(handler, "access_public", False)
|
return handler and getattr(handler, "access_public", False)
|
||||||
|
|
||||||
async def on_process_message(self, message: types.Message, data: dict):
|
async def on_process_message(self, message: types.Message, data: dict):
|
||||||
admin_id = self._access_chat_id
|
admin_ids = self._access_chat_ids
|
||||||
if not admin_id:
|
if not admin_ids:
|
||||||
return # Администратор бота вообще не указан
|
return # Администраторы бота вообще не указаны
|
||||||
|
|
||||||
if self._is_public_command(): # Эта команда разрешена всем пользователям
|
if self._is_public_command(): # Эта команда разрешена всем пользователям
|
||||||
return
|
return
|
||||||
|
|
||||||
if message.chat.id != admin_id:
|
if message.chat.id not in admin_ids:
|
||||||
await message.answer(_("Владелец бота ограничил доступ к этому функционалу 😞"))
|
await message.answer(_("Владелец бота ограничил доступ к этому функционалу 😞"))
|
||||||
raise CancelHandler()
|
raise CancelHandler()
|
||||||
|
|
||||||
async def on_process_callback_query(self, call: types.CallbackQuery, data: dict):
|
async def on_process_callback_query(self, call: types.CallbackQuery, data: dict):
|
||||||
admin_id = self._access_chat_id
|
admin_ids = self._access_chat_ids
|
||||||
if not admin_id:
|
if not admin_ids:
|
||||||
return # Администратор бота вообще не указан
|
return # Администраторы бота вообще не указаны
|
||||||
|
|
||||||
if self._is_public_command(): # Эта команда разрешена всем пользователям
|
if self._is_public_command(): # Эта команда разрешена всем пользователям
|
||||||
return
|
return
|
||||||
|
|
||||||
if call.message.chat.id != admin_id:
|
if call.message.chat.id not in admin_ids:
|
||||||
await call.answer(_("Владелец бота ограничил доступ к этому функционалу😞"))
|
await call.answer(_("Владелец бота ограничил доступ к этому функционалу😞"))
|
||||||
raise CancelHandler()
|
raise CancelHandler()
|
||||||
|
@ -319,7 +319,8 @@ class CustomRequestHandler(WebhookRequestHandler):
|
|||||||
types.ContentType.PHOTO,
|
types.ContentType.PHOTO,
|
||||||
types.ContentType.STICKER,
|
types.ContentType.STICKER,
|
||||||
types.ContentType.VIDEO,
|
types.ContentType.VIDEO,
|
||||||
types.ContentType.VOICE]
|
types.ContentType.VOICE,
|
||||||
|
types.ContentType.LOCATION]
|
||||||
dp.register_message_handler(message_handler, content_types=supported_messages)
|
dp.register_message_handler(message_handler, content_types=supported_messages)
|
||||||
dp.register_edited_message_handler(edited_message_handler, content_types=supported_messages)
|
dp.register_edited_message_handler(edited_message_handler, content_types=supported_messages)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user