added OwnerMiddleware

This commit is contained in:
Alexey Sokolov
2022-08-23 00:42:30 +03:00
parent 4aaed03655
commit 3753f4c6ef
4 changed files with 22 additions and 2 deletions

19
telegram/middlewares.py Normal file
View File

@@ -0,0 +1,19 @@
import logging
from aiogram.types import Message
from aiogram.dispatcher.middlewares import BaseMiddleware
from config import Config
class OwnerMiddleware(BaseMiddleware):
"""
Ignore commands from non-owner.
"""
def __init__(self):
self.bot_owner = Config().bot_owner
super(OwnerMiddleware, self).__init__()
async def on_pre_process_message(self, message: Message, _):
if message.chat.id != self.bot_owner:
message.text = ''