Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aiogram_bot/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
24 changes: 24 additions & 0 deletions aiogram_bot/filters/contains_bot_token.py
Original file line number Diff line number Diff line change
@@ -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)}
1 change: 1 addition & 0 deletions aiogram_bot/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
from . import superuser
from . import hastebin
from . import channel_filter
from . import token_finder
6 changes: 3 additions & 3 deletions aiogram_bot/handlers/chat_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions aiogram_bot/handlers/token_finder.py
Original file line number Diff line number Diff line change
@@ -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)
)
29 changes: 18 additions & 11 deletions locales/bot.pot
Original file line number Diff line number Diff line change
@@ -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 <EMAIL@ADDRESS>, 2021.
# FIRST AUTHOR <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -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 "<b>Read-only</b> activated for user {user}. Duration: {duration}"
msgstr ""

#: aiogram_bot/handlers/simple_admin.py:121
#: aiogram_bot/handlers/simple_admin.py:125
msgid "User {user} <b>banned</b> 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 ""

Expand All @@ -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 ""
Expand Down
44 changes: 33 additions & 11 deletions locales/en/LC_MESSAGES/bot.po
Original file line number Diff line number Diff line change
@@ -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 <EMAIL@ADDRESS>, 2021.
# FIRST AUTHOR <EMAIL@ADDRESS>, 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"
Expand Down Expand Up @@ -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 "<b>Read-only</b> activated for user {user}. Duration: {duration}"
msgstr ""

#: aiogram_bot/handlers/simple_admin.py:121
#: aiogram_bot/handlers/simple_admin.py:125
msgid "User {user} <b>banned</b> 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 ""

Expand All @@ -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 ""
Expand Down Expand Up @@ -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 ""

Loading