diff --git a/aiogram_bot/filters/__init__.py b/aiogram_bot/filters/__init__.py index 1cd40c0..c5ebeb5 100644 --- a/aiogram_bot/filters/__init__.py +++ b/aiogram_bot/filters/__init__.py @@ -6,6 +6,7 @@ def setup(dispatcher: Dispatcher): logger.info("Configure filters...") + from .contains_bot_token import ContainsBotToken from .has_permissions import BotHasPermissions, HasPermissions from .is_reply import IsReplyFilter from .superuser import IsSuperuserFilter @@ -22,3 +23,4 @@ def setup(dispatcher: Dispatcher): dispatcher.filters_factory.bind(BotHasPermissions, event_handlers=text_messages) dispatcher.filters_factory.bind(ChatPropertyFilter, event_handlers=text_messages) dispatcher.filters_factory.bind(IsSuperuserFilter) + dispatcher.filters_factory.bind(ContainsBotToken) diff --git a/aiogram_bot/filters/contains_bot_token.py b/aiogram_bot/filters/contains_bot_token.py new file mode 100644 index 0000000..53f1090 --- /dev/null +++ b/aiogram_bot/filters/contains_bot_token.py @@ -0,0 +1,24 @@ +import re +import typing +from dataclasses import dataclass + +from aiogram import types +from aiogram.dispatcher.filters import BoundFilter + + +@dataclass +class ContainsBotToken(BoundFilter): + """ + Filtered message should contain working token for Telegram bot + """ + + key = "contains_bot_token" + + token_regex = re.compile(r"(\d{0,16}:[a-zA-Z0-9_\-]{35})") + + async def check(self, message: types.Message) -> typing.Union[bool, typing.Dict[str, str]]: + txt = message.text or message.caption + result = self.token_regex.search(txt) + if result is None: + return False + return {"token": result.group(0)} diff --git a/aiogram_bot/handlers/__init__.py b/aiogram_bot/handlers/__init__.py index be9e6b9..a8dcf76 100644 --- a/aiogram_bot/handlers/__init__.py +++ b/aiogram_bot/handlers/__init__.py @@ -11,3 +11,4 @@ from . import superuser from . import hastebin from . import channel_filter +from . import token_finder diff --git a/aiogram_bot/handlers/chat_settings.py b/aiogram_bot/handlers/chat_settings.py index 2186716..805eb55 100644 --- a/aiogram_bot/handlers/chat_settings.py +++ b/aiogram_bot/handlers/chat_settings.py @@ -11,13 +11,13 @@ from aiogram_bot.models.user import User from aiogram_bot.utils.chat_admin import get_chat_administrator from aiogram_bot.utils.chat_settings import ( + PROPERTY_BAN_CHANNELS, + PROPERTY_DEL_CHANNEL_MESSAGES, + PROPERTY_JOIN, cb_chat_settings, cb_user_settings, get_chat_settings_markup, get_user_settings_markup, - PROPERTY_JOIN, - PROPERTY_BAN_CHANNELS, - PROPERTY_DEL_CHANNEL_MESSAGES, ) _ = i18n.gettext diff --git a/aiogram_bot/handlers/token_finder.py b/aiogram_bot/handlers/token_finder.py new file mode 100644 index 0000000..6b5472f --- /dev/null +++ b/aiogram_bot/handlers/token_finder.py @@ -0,0 +1,23 @@ +from aiogram import Bot, types +from aiogram.dispatcher.handler import SkipHandler + +from aiogram_bot.misc import dp, i18n + +_ = i18n.gettext + + +@dp.message_handler( + chat_type=[types.ChatType.GROUP, types.ChatType.SUPERGROUP], contains_bot_token=True +) +async def found_token_in_msg(message: types.Message, token: str): + try: + temp_bot = Bot(token, validate_token=True) + temp_bot_data = await temp_bot.get_me() + except Exception: + raise SkipHandler + else: + await message.reply( + _( + "[ALERT] You posted a token, go revoke it with @BotFather.\n\nToken exposed: @{exposed_bot_username}" + ).format(exposed_bot_username=temp_bot_data.username) + ) diff --git a/locales/bot.pot b/locales/bot.pot index a10d81e..2738f74 100644 --- a/locales/bot.pot +++ b/locales/bot.pot @@ -1,14 +1,14 @@ # Translations template for aiogram_bot. -# Copyright (C) 2021 Illemius +# Copyright (C) 2023 Illemius # This file is distributed under the same license as the aiogram_bot project. -# FIRST AUTHOR , 2021. +# FIRST AUTHOR , 2023. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: aiogram_bot 0.1\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-12-09 23:51+0200\n" +"POT-Creation-Date: 2023-06-10 03:39+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -161,39 +161,39 @@ msgstr "" msgid "Bad answer." msgstr "" -#: aiogram_bot/handlers/simple_admin.py:50 +#: aiogram_bot/handlers/simple_admin.py:52 msgid "" "Channel {channel} was permanently banned and the channel owner will no longer be able to send " "messages here on behalf of any of his channels." msgstr "" -#: aiogram_bot/handlers/simple_admin.py:86 +#: aiogram_bot/handlers/simple_admin.py:89 msgid "Read-only activated for user {user}. Duration: {duration}" msgstr "" -#: aiogram_bot/handlers/simple_admin.py:121 +#: aiogram_bot/handlers/simple_admin.py:125 msgid "User {user} banned for {duration}" msgstr "" -#: aiogram_bot/handlers/simple_admin.py:150 +#: aiogram_bot/handlers/simple_admin.py:160 msgid "" "Please use this command is only in reply to message what do you want to report and this message " "will be reported to chat administrators." msgstr "" -#: aiogram_bot/handlers/simple_admin.py:157 +#: aiogram_bot/handlers/simple_admin.py:175 msgid "[ALERT] User {user} is reported message in chat {chat}." msgstr "" -#: aiogram_bot/handlers/simple_admin.py:179 +#: aiogram_bot/handlers/simple_admin.py:192 msgid "This message is reported to chat administrators." msgstr "" -#: aiogram_bot/handlers/simple_admin.py:191 +#: aiogram_bot/handlers/simple_admin.py:204 msgid "User {user} leave this chat..." msgstr "" -#: aiogram_bot/handlers/simple_admin.py:227 +#: aiogram_bot/handlers/simple_admin.py:240 msgid "Channel {channel} allowed in this chat" msgstr "" @@ -205,6 +205,13 @@ msgstr "" msgid "Failed to set is_superuser to {is_superuser} for user {user}" msgstr "" +#: aiogram_bot/handlers/token_finder.py:20 +msgid "" +"[ALERT] You posted a token, go revoke it with @BotFather.\n" +"\n" +"Token exposed: @{exposed_bot_username}" +msgstr "" + #: aiogram_bot/utils/chat_settings.py:29 msgid "Settings for chat {chat_title}" msgstr "" diff --git a/locales/en/LC_MESSAGES/bot.po b/locales/en/LC_MESSAGES/bot.po index 2c3e26d..24ff072 100644 --- a/locales/en/LC_MESSAGES/bot.po +++ b/locales/en/LC_MESSAGES/bot.po @@ -1,14 +1,14 @@ # English translations for aiogram_bot. -# Copyright (C) 2021 Illemius +# Copyright (C) 2023 Illemius # This file is distributed under the same license as the aiogram_bot # project. -# FIRST AUTHOR , 2021. +# FIRST AUTHOR , 2023. # msgid "" msgstr "" "Project-Id-Version: aiogram_bot 0.1\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-12-09 23:51+0200\n" +"POT-Creation-Date: 2023-06-10 03:39+0300\n" "PO-Revision-Date: 2019-10-22 00:12+0300\n" "Last-Translator: \n" "Language: en\n" @@ -166,39 +166,39 @@ msgstr "" msgid "Bad answer." msgstr "" -#: aiogram_bot/handlers/simple_admin.py:50 +#: aiogram_bot/handlers/simple_admin.py:52 msgid "" "Channel {channel} was permanently banned and the channel owner will no " "longer be able to send messages here on behalf of any of his channels." msgstr "" -#: aiogram_bot/handlers/simple_admin.py:86 +#: aiogram_bot/handlers/simple_admin.py:89 msgid "Read-only activated for user {user}. Duration: {duration}" msgstr "" -#: aiogram_bot/handlers/simple_admin.py:121 +#: aiogram_bot/handlers/simple_admin.py:125 msgid "User {user} banned for {duration}" msgstr "" -#: aiogram_bot/handlers/simple_admin.py:150 +#: aiogram_bot/handlers/simple_admin.py:160 msgid "" "Please use this command is only in reply to message what do you want to " "report and this message will be reported to chat administrators." msgstr "" -#: aiogram_bot/handlers/simple_admin.py:157 +#: aiogram_bot/handlers/simple_admin.py:175 msgid "[ALERT] User {user} is reported message in chat {chat}." msgstr "🔥🔥🔥 User {user} is reported message in chat {chat}." -#: aiogram_bot/handlers/simple_admin.py:179 +#: aiogram_bot/handlers/simple_admin.py:192 msgid "This message is reported to chat administrators." msgstr "" -#: aiogram_bot/handlers/simple_admin.py:191 +#: aiogram_bot/handlers/simple_admin.py:204 msgid "User {user} leave this chat..." msgstr "" -#: aiogram_bot/handlers/simple_admin.py:227 +#: aiogram_bot/handlers/simple_admin.py:240 msgid "Channel {channel} allowed in this chat" msgstr "" @@ -210,6 +210,16 @@ msgstr "" msgid "Failed to set is_superuser to {is_superuser} for user {user}" msgstr "" +#: aiogram_bot/handlers/token_finder.py:20 +msgid "" +"[ALERT] You posted a token, go revoke it with @BotFather.\n" +"\n" +"Token exposed: @{exposed_bot_username}" +msgstr "" +"🔥 You posted a token, go revoke it with @BotFather.\n" +"\n" +"Token exposed: @{exposed_bot_username}" + #: aiogram_bot/utils/chat_settings.py:29 msgid "Settings for chat {chat_title}" msgstr "" @@ -253,3 +263,15 @@ msgstr "" #~ msgid "Join filter re-configured" #~ msgstr "" +#~ msgid "" +#~ "⚠️ You posted a token, go revoke it with @BotFather.\n" +#~ "\n" +#~ "Token exposed: @{exposed_bot_username}" +#~ msgstr "" + +#~ msgid "" +#~ "[ALERT]You posted a token, go revoke it with @BotFather.\n" +#~ "\n" +#~ "Token exposed: @{exposed_bot_username}" +#~ msgstr "" + diff --git a/locales/ru/LC_MESSAGES/bot.po b/locales/ru/LC_MESSAGES/bot.po index 7664d94..1a4532d 100644 --- a/locales/ru/LC_MESSAGES/bot.po +++ b/locales/ru/LC_MESSAGES/bot.po @@ -1,25 +1,24 @@ # Russian translations for aiogram_bot. -# Copyright (C) 2021 Illemius +# Copyright (C) 2023 Illemius # This file is distributed under the same license as the aiogram_bot # project. -# FIRST AUTHOR , 2021. +# FIRST AUTHOR , 2023. # msgid "" msgstr "" "Project-Id-Version: aiogram_bot 0.1\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-12-09 23:51+0200\n" +"POT-Creation-Date: 2023-06-10 03:39+0300\n" "PO-Revision-Date: 2021-12-09 23:53+0200\n" "Last-Translator: \n" "Language: ru\n" "Language-Team: ru \n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" -"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " +"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.9.1\n" -"X-Generator: Poedit 3.0\n" #: aiogram_bot/handlers/base.py:18 msgid "" @@ -29,8 +28,8 @@ msgid "" "My source code: {source_url}" msgstr "" "Привет, {user}.\n" -"Отправь /help если хочешь прочитать список моих команд. Так же, если хочешь " -"изменить язык - отправь команду /settings.\n" +"Отправь /help если хочешь прочитать список моих команд. Так же, если " +"хочешь изменить язык - отправь команду /settings.\n" "\n" "Мои исходники: {source_url}" @@ -161,14 +160,14 @@ msgstr "Я человек" #: aiogram_bot/handlers/new_chat_members.py:87 msgid "" "{users}, Welcome to the chat. \n" -"Please confirm that you are a human. User filter is enabled in this chat, so " -"if you don't answer my question, I will be forced to remove you from this " -"chat." +"Please confirm that you are a human. User filter is enabled in this chat," +" so if you don't answer my question, I will be forced to remove you from " +"this chat." msgstr "" "Привет, {users}!\n" "Пожалуйста подтверди, что ты человек. В этом чате включен фильтр новых " -"пользователей, поэтому, если ты не ответишь на мой вопрос, я буду вынужден " -"прогнать тебя из чата." +"пользователей, поэтому, если ты не ответишь на мой вопрос, я буду " +"вынужден прогнать тебя из чата." #: aiogram_bot/handlers/new_chat_members.py:123 msgid "This message is not for you!" @@ -182,23 +181,23 @@ msgstr "Хороший ответ!" msgid "Bad answer." msgstr "Плохой ответ." -#: aiogram_bot/handlers/simple_admin.py:50 +#: aiogram_bot/handlers/simple_admin.py:52 msgid "" "Channel {channel} was permanently banned and the channel owner will no " "longer be able to send messages here on behalf of any of his channels." msgstr "" -"Канал {channel} заблокирован, его владелец больше не сможет писать от имени " -"любого из своих каналов в этом чате." +"Канал {channel} заблокирован, его владелец больше не сможет писать от " +"имени любого из своих каналов в этом чате." -#: aiogram_bot/handlers/simple_admin.py:86 +#: aiogram_bot/handlers/simple_admin.py:89 msgid "Read-only activated for user {user}. Duration: {duration}" msgstr "Пользователь {user} помещен в RO на {duration}" -#: aiogram_bot/handlers/simple_admin.py:121 +#: aiogram_bot/handlers/simple_admin.py:125 msgid "User {user} banned for {duration}" msgstr "Пользователь {user} забанен на {duration}" -#: aiogram_bot/handlers/simple_admin.py:150 +#: aiogram_bot/handlers/simple_admin.py:160 msgid "" "Please use this command is only in reply to message what do you want to " "report and this message will be reported to chat administrators." @@ -206,31 +205,43 @@ msgstr "" "Пожалуйста, используй эту команду только в ответ на другое сообщение и я " "сообщу про него администрации чата." -#: aiogram_bot/handlers/simple_admin.py:157 +#: aiogram_bot/handlers/simple_admin.py:175 msgid "[ALERT] User {user} is reported message in chat {chat}." msgstr "🔥 Пользователь {user} сообщает про сообщение в чате {chat}." -#: aiogram_bot/handlers/simple_admin.py:179 +#: aiogram_bot/handlers/simple_admin.py:192 msgid "This message is reported to chat administrators." msgstr "Я сообщил про это сообщение администрации чата." -#: aiogram_bot/handlers/simple_admin.py:191 +#: aiogram_bot/handlers/simple_admin.py:204 msgid "User {user} leave this chat..." msgstr "Пользователь {user} покинул этот чат..." -#: aiogram_bot/handlers/simple_admin.py:227 +#: aiogram_bot/handlers/simple_admin.py:240 msgid "Channel {channel} allowed in this chat" msgstr "Теперь канал {channel} разрешен в этом чате" #: aiogram_bot/handlers/superuser.py:25 msgid "Successful changed is_superuser to {is_superuser} for user {user}" msgstr "" -"Успешно обновлен флаг is_superuser на {is_superuser} для пользователя {user}" +"Успешно обновлен флаг is_superuser на {is_superuser} для пользователя " +"{user}" #: aiogram_bot/handlers/superuser.py:30 msgid "Failed to set is_superuser to {is_superuser} for user {user}" msgstr "" -"Не удалось изменить флаг is_superuser {is_superuser} для пользователя{user}" +"Не удалось изменить флаг is_superuser {is_superuser} для " +"пользователя{user}" + +#: aiogram_bot/handlers/token_finder.py:20 +msgid "" +"[ALERT] You posted a token, go revoke it with @BotFather.\n" +"\n" +"Token exposed: @{exposed_bot_username}" +msgstr "" +"🔥 Ты разместил токен бота, сбрось его в @BotFather.\n" +"\n" +"Токен размещен: @{exposed_bot_username}" #: aiogram_bot/utils/chat_settings.py:29 msgid "Settings for chat {chat_title}" @@ -266,3 +277,16 @@ msgstr "{status} Не беспокоить" #~ msgid "Join filter re-configured" #~ msgstr "Фильтр входа в чат перенастроен" + +#~ msgid "" +#~ "⚠️ You posted a token, go revoke it with @BotFather.\n" +#~ "\n" +#~ "Token exposed: @{exposed_bot_username}" +#~ msgstr "" + +#~ msgid "" +#~ "[ALERT]You posted a token, go revoke it with @BotFather.\n" +#~ "\n" +#~ "Token exposed: @{exposed_bot_username}" +#~ msgstr "" + diff --git a/locales/uk/LC_MESSAGES/bot.po b/locales/uk/LC_MESSAGES/bot.po index b8eb023..71335c9 100644 --- a/locales/uk/LC_MESSAGES/bot.po +++ b/locales/uk/LC_MESSAGES/bot.po @@ -1,25 +1,24 @@ # Ukrainian translations for aiogram_bot. -# Copyright (C) 2021 Illemius +# Copyright (C) 2023 Illemius # This file is distributed under the same license as the aiogram_bot # project. -# FIRST AUTHOR , 2021. +# FIRST AUTHOR , 2023. # msgid "" msgstr "" "Project-Id-Version: aiogram_bot 0.1\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-12-09 23:51+0200\n" +"POT-Creation-Date: 2023-06-10 03:39+0300\n" "PO-Revision-Date: 2021-12-09 23:53+0200\n" "Last-Translator: \n" "Language: uk\n" "Language-Team: uk \n" -"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 " -"&& (n%100<10 || n%100>=20) ? 1 : 2);\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " +"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.9.1\n" -"X-Generator: Poedit 3.0\n" #: aiogram_bot/handlers/base.py:18 msgid "" @@ -29,8 +28,8 @@ msgid "" "My source code: {source_url}" msgstr "" "Привіт, {user}.\n" -"Надішли /help якщо хочеш побачити список моїх команд, або /settings якщо хочеш " -"змінити мову.\n" +"Надішли /help якщо хочеш побачити список моїх команд, або /settings якщо " +"хочеш змінити мову.\n" "\n" "Мій код: {source_url}" @@ -161,8 +160,9 @@ msgstr "Я людина" #: aiogram_bot/handlers/new_chat_members.py:87 msgid "" "{users}, Welcome to the chat. \n" -"Please confirm that you are a human. User filter is enabled in this chat, so if " -"you don't answer my question, I will be forced to remove you from this chat." +"Please confirm that you are a human. User filter is enabled in this chat," +" so if you don't answer my question, I will be forced to remove you from " +"this chat." msgstr "" "Вітаю, {users}.\n" "Будь ласка, підтверди що ти людина. В цьому чаті ввімкнуто фільтр нових " @@ -181,43 +181,43 @@ msgstr "Гарна відповідь!" msgid "Bad answer." msgstr "Погана відповідь." -#: aiogram_bot/handlers/simple_admin.py:50 +#: aiogram_bot/handlers/simple_admin.py:52 msgid "" -"Channel {channel} was permanently banned and the channel owner will no longer " -"be able to send messages here on behalf of any of his channels." +"Channel {channel} was permanently banned and the channel owner will no " +"longer be able to send messages here on behalf of any of his channels." msgstr "" -"Канал {channel} заблоковано, його власник більше не зможе писати від імені " -"своїх каналів в цьому чаті." +"Канал {channel} заблоковано, його власник більше не зможе писати від " +"імені своїх каналів в цьому чаті." -#: aiogram_bot/handlers/simple_admin.py:86 +#: aiogram_bot/handlers/simple_admin.py:89 msgid "Read-only activated for user {user}. Duration: {duration}" msgstr "Користувачу {user} заборонено писати в чаті на {duration}" -#: aiogram_bot/handlers/simple_admin.py:121 +#: aiogram_bot/handlers/simple_admin.py:125 msgid "User {user} banned for {duration}" msgstr "Користувача {user} заблоковано на {duration}" -#: aiogram_bot/handlers/simple_admin.py:150 +#: aiogram_bot/handlers/simple_admin.py:160 msgid "" -"Please use this command is only in reply to message what do you want to report " -"and this message will be reported to chat administrators." +"Please use this command is only in reply to message what do you want to " +"report and this message will be reported to chat administrators." msgstr "" -"Будь ласка, використовуй дану команду тільки у відповідь на інше повідомлення і " -"я повідомлю про нього адміністрації чату." +"Будь ласка, використовуй дану команду тільки у відповідь на інше " +"повідомлення і я повідомлю про нього адміністрації чату." -#: aiogram_bot/handlers/simple_admin.py:157 +#: aiogram_bot/handlers/simple_admin.py:175 msgid "[ALERT] User {user} is reported message in chat {chat}." msgstr "🔥 Користувач {user} кличе адміністрацію в чаті {chat}." -#: aiogram_bot/handlers/simple_admin.py:179 +#: aiogram_bot/handlers/simple_admin.py:192 msgid "This message is reported to chat administrators." msgstr "Я повідомим адміністрацію чату про це повідомлення." -#: aiogram_bot/handlers/simple_admin.py:191 +#: aiogram_bot/handlers/simple_admin.py:204 msgid "User {user} leave this chat..." msgstr "Користувач {user} покинув цей чат..." -#: aiogram_bot/handlers/simple_admin.py:227 +#: aiogram_bot/handlers/simple_admin.py:240 msgid "Channel {channel} allowed in this chat" msgstr "Канал {channel} заблоковано у цьому чаті" @@ -229,6 +229,13 @@ msgstr "Успішно встановлено is_superuser на {is_superuser} msgid "Failed to set is_superuser to {is_superuser} for user {user}" msgstr "Не вдалось встановити is_superuser на {is_superuser} користувачу {user}" +#: aiogram_bot/handlers/token_finder.py:20 +msgid "" +"[ALERT] You posted a token, go revoke it with @BotFather.\n" +"\n" +"Token exposed: @{exposed_bot_username}" +msgstr "" + #: aiogram_bot/utils/chat_settings.py:29 msgid "Settings for chat {chat_title}" msgstr "Налаштування чату {chat_title}" @@ -263,3 +270,16 @@ msgstr "{status} Не турбувати" #~ msgid "Join filter re-configured" #~ msgstr "Фільтр входу користувачів переналаштовано" + +#~ msgid "" +#~ "⚠️ You posted a token, go revoke it with @BotFather.\n" +#~ "\n" +#~ "Token exposed: @{exposed_bot_username}" +#~ msgstr "" + +#~ msgid "" +#~ "[ALERT]You posted a token, go revoke it with @BotFather.\n" +#~ "\n" +#~ "Token exposed: @{exposed_bot_username}" +#~ msgstr "" +