From 6bfe00c2340e64f5264f12e268d6d67f7b187427 Mon Sep 17 00:00:00 2001 From: JSDio Date: Fri, 4 Mar 2022 22:19:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D0=BD=D0=BE=D1=81=D1=82=D1=8C=D1=8E=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=87=D0=B8=D0=B9=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=BE=D0=BD=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.dist | 6 ------ filters/__init__.py | 4 ++-- filters/group_chat.py | 9 +++++++++ handlers/__init__.py | 5 +++-- handlers/groups/__init__.py | 1 + handlers/groups/chat.py | 12 ++++++++++++ handlers/users/echo.py | 15 ++------------- 7 files changed, 29 insertions(+), 23 deletions(-) delete mode 100644 .env.dist create mode 100644 filters/group_chat.py create mode 100644 handlers/groups/chat.py diff --git a/.env.dist b/.env.dist deleted file mode 100644 index e8807d4..0000000 --- a/.env.dist +++ /dev/null @@ -1,6 +0,0 @@ -# ЭТО ПРИМЕР ФАЙЛА .env !! ВАМ НАДО ЭТОТ ФАЙЛ ПЕРЕИМЕНОВАТЬ И ВСТАВИТЬ ТУДА ЗНАЧЕНИЯ. -# ЭТИ КОММЕНТАРИИ НАДО УДАЛИТЬ! - -ADMINS=12345678,12345677,12345676 -BOT_TOKEN=123452345243:Asdfasdfasf -ip=localhost diff --git a/filters/__init__.py b/filters/__init__.py index 40de5d0..dd80b20 100644 --- a/filters/__init__.py +++ b/filters/__init__.py @@ -1,9 +1,9 @@ from aiogram import Dispatcher from loader import dp -# from .is_admin import AdminFilter +from .group_chat import IsGroup if __name__ == "filters": - # dp.filters_factory.bind(AdminFilter) + dp.filters_factory.bind(IsGroup) pass diff --git a/filters/group_chat.py b/filters/group_chat.py new file mode 100644 index 0000000..c8e8015 --- /dev/null +++ b/filters/group_chat.py @@ -0,0 +1,9 @@ +from aiogram import types +from aiogram.dispatcher.filters import BoundFilter + +class IsGroup(BoundFilter): + async def check(self, message: types.Message) -> bool: + return message.chat.type in ( + types.ChatType.GROUP, + types.ChatType.SUPERGROUP + ) \ No newline at end of file diff --git a/handlers/__init__.py b/handlers/__init__.py index ed49383..10a2233 100644 --- a/handlers/__init__.py +++ b/handlers/__init__.py @@ -1,5 +1,6 @@ -from . import errors -from . import users from . import groups from . import channels +from . import errors +from . import users + diff --git a/handlers/groups/__init__.py b/handlers/groups/__init__.py index e69de29..88558e9 100644 --- a/handlers/groups/__init__.py +++ b/handlers/groups/__init__.py @@ -0,0 +1 @@ +from . import chat \ No newline at end of file diff --git a/handlers/groups/chat.py b/handlers/groups/chat.py new file mode 100644 index 0000000..f670d31 --- /dev/null +++ b/handlers/groups/chat.py @@ -0,0 +1,12 @@ +from aiogram import types +from aiogram.dispatcher import FSMContext +from filters import IsGroup +from loader import dp + + + + +@dp.message_handler(IsGroup(), content_types=types.ContentTypes.ANY) +async def bot_echo_all(message: types.Message, state: FSMContext): + if message.sender_chat is not None: + await message.delete() \ No newline at end of file diff --git a/handlers/users/echo.py b/handlers/users/echo.py index f7fa79c..ad8143a 100644 --- a/handlers/users/echo.py +++ b/handlers/users/echo.py @@ -5,17 +5,6 @@ from loader import dp # Эхо хендлер, куда летят текстовые сообщения без указанного состояния -@dp.message_handler(state=None) +@dp.message_handler() async def bot_echo(message: types.Message): - await message.answer(f"Эхо без состояния." - f"Сообщение:\n" - f"{message.text}") - - -# Эхо хендлер, куда летят ВСЕ сообщения с указанным состоянием -@dp.message_handler(state="*", content_types=types.ContentTypes.ANY) -async def bot_echo_all(message: types.Message, state: FSMContext): - state = await state.get_state() - await message.answer(f"Эхо в состоянии {state}.\n" - f"\nСодержание сообщения:\n" - f"{message}") + await message.answer(f"Просто добавь меня в чат и я начну удалять сообщения от каналов!")