
    i                     f    d dl mZmZmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ  G d de      Zy)	    )Any	AwaitableCallable)BaseMiddleware)TelegramObjectMessageCallbackQuery)Redis)settingsc                   h    e Zd ZdZddededz  fdZdeee	e
ef   gee   f   dede	e
ef   d	efd
Zy)ThrottlingMiddlewareux   
    Spam himoya — Redis orqali rate limiter.
    1 daqiqada THROTTLE_RATE dan ko'p so'rov yuborsa blok qilinadi.
    Nredisratec                 D    || _         |xs t        j                  | _        y N)r   r   throttle_rater   )selfr   r   s      H/home/empty/Documents/pet_projects/kinoBot/bot/middlewares/throttling.py__init__zThrottlingMiddleware.__init__   s    
2H22	    handlereventdatareturnc                   K   ddl m} |j                  d      }|r|j                  r |||       d {   S d|j                   }| j
                  j                  |       d {   }|dk(  r$| j
                  j                  |d       d {    || j                  kD  r,t        |t              r|j                  dd	       d {    y  |||       d {   S 7 7 {7 T7 7 w)
Nr   )Userevent_from_userz	throttle:   <   u   ⏳ Iltimos, biroz kuting...F)
show_alert)aiogram.typesr   getis_botidr   increxpirer   
isinstancer	   answer)r   r   r   r   TgUsertg_userkeycounts           r   __call__zThrottlingMiddleware.__call__   s      	1!%*;!<'.. ---'**&jjooc**A:**##C,,,499%/ll#AelTTTUD)))! . + -
 U *sW   2C*C 1C*&C"'(C*C$9C*	C&
C*C(C*"C*$C*&C*(C*r   )__name__
__module____qualname____doc__r
   intr   r   r   dictstrr   r   r-    r   r   r   r   
   sl    
3e 33: 3*>4S>:IcNJK* * 38n	*
 
*r   r   N)typingr   r   r   aiogramr   r!   r   r   r	   redis.asyncior
   
bot.configr   r   r5   r   r   <module>r:      s&    + + " @ @  $*> $*r   