From 1f4e2fc8fe4ae892e482dd08adc7489aa52e21fd Mon Sep 17 00:00:00 2001 From: Pavel Kirilin <win10@list.ru> Date: Sat, 8 Oct 2022 14:43:16 +0400 Subject: [PATCH] Added currency blocking. Signed-off-by: Pavel Kirilin <win10@list.ru> --- bot_s3rius/actions/converters/crypto_currency.py | 4 +++- bot_s3rius/actions/converters/currency.py | 13 ++++++++++++- bot_s3rius/config.py | 1 + bot_s3rius/utils/responses.py | 12 ++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/bot_s3rius/actions/converters/crypto_currency.py b/bot_s3rius/actions/converters/crypto_currency.py index 36eee36..365f69e 100644 --- a/bot_s3rius/actions/converters/crypto_currency.py +++ b/bot_s3rius/actions/converters/crypto_currency.py @@ -8,7 +8,7 @@ from telethon import events from bot_s3rius.config import config from bot_s3rius.utils.converters import get_info_from_group -from bot_s3rius.utils.responses import mark_unread +from bot_s3rius.utils.responses import cur_message, mark_unread logger = logging.getLogger(__name__) @@ -52,6 +52,7 @@ CURRENCY_PATTERN = ( pattern=re.compile(f".*{CURRENCY_PATTERN}.*", re.IGNORECASE | re.DOTALL) ) ) +@cur_message @mark_unread async def replace_crypto_currency(event: events.NewMessage.Event): groups = re.findall(CURRENCY_PATTERN, event.message.message, re.IGNORECASE) @@ -90,6 +91,7 @@ async def replace_crypto_currency(event: events.NewMessage.Event): @config.telegram_client.on(events.NewMessage(pattern="^.scc$")) +@cur_message @mark_unread async def supported_currencies(event): async with httpx.AsyncClient() as client: diff --git a/bot_s3rius/actions/converters/currency.py b/bot_s3rius/actions/converters/currency.py index da1951b..06bbe6f 100644 --- a/bot_s3rius/actions/converters/currency.py +++ b/bot_s3rius/actions/converters/currency.py @@ -7,7 +7,7 @@ from telethon import events from bot_s3rius.config import config from bot_s3rius.utils.converters import get_info_from_group -from bot_s3rius.utils.responses import mark_unread +from bot_s3rius.utils.responses import cur_message, mark_unread logger = logging.getLogger(__name__) @@ -43,6 +43,11 @@ CURRENCY_MAPPING = { "гривны": "UAH", "гривен": "UAH", "грiвен": "UAH", + "тенге": "KZT", + "Ñ‚Ñнге": "KZT", + "злоты": "PLN", + "лир": "TRY", + "драм": "AMD", } SUPPORTED_CURRENCIES = [ @@ -57,6 +62,10 @@ SUPPORTED_CURRENCIES = [ "CHF", "KRW", "JPY", + "KZT", + "PLN", + "TRY", + "AMD", ] MEMES = { @@ -76,6 +85,7 @@ CURRENCY_PATTERN = ( pattern=re.compile(f".*{CURRENCY_PATTERN}.*", re.IGNORECASE | re.DOTALL) ) ) +@cur_message @mark_unread async def replace_currency(event): async with httpx.AsyncClient() as f: @@ -113,6 +123,7 @@ async def replace_currency(event): @config.telegram_client.on(events.NewMessage(pattern="^.sc$")) +@cur_message @mark_unread async def supported_currencies(event): async with httpx.AsyncClient() as f: diff --git a/bot_s3rius/config.py b/bot_s3rius/config.py index 417c058..55c5f06 100644 --- a/bot_s3rius/config.py +++ b/bot_s3rius/config.py @@ -21,6 +21,7 @@ class Config(BaseSettings): debug_mode: bool = False flask_port: str = Field(name="flask_port", default="8080", env="BOT_FLASK_PORT") excluded_chats: List[str] = Field([], env="BOT_EXCLUDED_CHATS") + cur_excluded_chats: List[str] = Field([], env="CURRECNY_EXCLUDED_CHATS") telegram_client: TelegramClient = None @property diff --git a/bot_s3rius/utils/responses.py b/bot_s3rius/utils/responses.py index 9573c52..934c6dc 100644 --- a/bot_s3rius/utils/responses.py +++ b/bot_s3rius/utils/responses.py @@ -88,5 +88,17 @@ def danger_message(f): return wrapper +def cur_message(f): + @functools.wraps(f) + async def wrapper(event: events.NewMessage.Event): + chat = await event.get_chat() + if str(chat.id) in set(config.cur_excluded_chats): + logger.debug("Skipping sending message") + return + await f(event) + + return wrapper + + def check_if_only_smiles(message: str): return all([x in ")0." for x in message]) -- GitLab