blob: 046037d88506282733b69714ca8a6aa55470c9ef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
from aiogram import types as t
from aiogram.dispatcher.middlewares import BaseMiddleware
from shared.database import Message
from shared.instances import session
from shared.samples import samples
class MessageMiddleware(BaseMiddleware):
async def on_pre_process_message(self, msg: t.Message, data: dict) -> None:
text = msg.text or msg.caption
if text is not None and not text.startswith("/"):
with session.begin() as s:
s.add(
Message(
chat_id=msg.chat.id,
message_id=msg.message_id,
user_id=msg.from_user.id,
message=text,
)
)
samples.get(msg.chat.id).feed(text)
|