
    soj5                     &   d dl Z d dlZd dlmZmZ d dlmZmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ 	 	 dde
j        dededededdfdZ 	 	 dde
j        dededededdfdZ!dededefdZ"dS )    N)UpdateMessage)	Forbidden
BadRequestTimedOut)ContextTypes)DisabledNotification)User)Notification)Screen)Keyboard)full_message_send)set_current_languageFcontextusernotificationshould_forward_messageupdatereturnc           	        K   |;t          j        d           t          j        t          j                               dS |rt	          | ||||           d{V  dS | j                            t	          | ||||                     dS )a)  
    Sends a notification to the user, fire and forget
    :param context: The context object
    :param user: User
    :param notification: Notification
    :param should_forward_message: If the message of the update should be forwarded
    :param update: The update object
    :return: None
    Nz,Trying to send a notification to a None user)loggingerror	tracebackformat_stacksend_notification_executeapplicationcreate_task)r   r   r   r   r   s        (/app/src/service/notification_service.pysend_notificationr      s      " |DEEEi,../// 		
 (T<)?
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	''%gt\CY[abb	
 	
 	
 	
 	
    c                   K   ddl m} t          |                                           |r|t	          d          t          ||          sdS t          j                                        r'|j	        t          j
                                        vrdS t          j                                        r|                    |            d{V sdS g }t          j        t          j        t          j        t          j        g}|j        |j        |j        |j        i}||                                z  }|                    t3          t4          j        |t          j        |          g           	 d}	|r	 |?t;          |dd          .|j                            |j	        d           d{V }
|
j         }	nw# tB          $ r  tE          j#        d	|j	         d
           Y nNtH          $ r!}tE          j#        d|            Y d}~n)d}~wtJ          $ r tE          j&        dd           Y nw xY wtO          | |(                                |j	        ||j)        |	|j*        dd|g
  
         d{V  dS # tB          $ r Y dS tV          $ r  tE          j#        d|j,                    Y dS tH          $ ra}t[          |          .                                }
d|
v rn*d|
v sd|
v r tE          j/        d|j,         d|            n|Y d}~dS Y d}~dS d}~ww xY w)a  
    Sends a notification to the user
    :param context: The context object
    :param user: User
    :param notification: Notification
    :param should_forward_message: If the message of the update should be forwarded
    :param update: The update object
    :return: None
    r   )NotificationTypeReservedKeysNz>If should_forward_message is not None, update must be not None)infoscreenprevious_screen_listmessageT)disable_notificationzCould not forward message to z/: User has not started bot in DM or blocked it.zCould not forward message: z)Unexpected error while forwarding message)exc_infoF)chat_idkeyboardr'   reply_to_message_iddisable_web_page_previewadd_delete_buttonshould_auto_deleteauthorized_usersz'Timed out sending notification to user 
bot_to_botzcannot start conversationszinvalid peerzCannot resolve peer for user z, skipping notification: )0;src.chat.private.screens.screen_settings_notifications_typer"   r   get_language
ValueError
is_enabledEnvLIMIT_TO_AUTHORIZED_USERSget_bool
tg_user_idAUTHORIZED_USERSget_listLIMIT_TO_AUTHORIZED_GROUPSin_authorized_groupsr   	PVT_STARTPVT_SETTINGSPVT_SETTINGS_NOTIFICATIONSPVT_SETTINGS_NOTIFICATIONS_TYPECATEGORYcategoryTYPEtypeget_keyboardappendr   phrases$PVT_KEY_MANAGE_NOTIFICATION_SETTINGS$PVT_SETTINGS_NOTIFICATIONS_TYPE_EDITgetattrr&   forward
message_idr   r   warningr   	Exceptionr   r   buildr'   r,   r   idstrlowerr#   )r   r   r   r   r   r"   inline_keyboardprevious_screensbutton_infoquote_message_idr&   es               r   r   r   5   sX     "      **,,--- [&.YZZZ dL))  	%..00O3#7#@#@#B#BBB %..00 t?X?XY`?a?a9a9a9a9a9a9a  -/O).	 	%-|/D$)<+<K
 |00222O< B%5	  	
	 	 	6! 	ZZ%'&)T*J*J*V-3^-C-Cd .D . . ( ( ( ( ( (G (/'9$  B B B  !A  !A  !A  !A  B  B  B  B  B  C C C Aa A ABBBBBBBB Z Z ZITXYYYYYYZ    O$!-!B 0%1%J"$"V
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
     M M MK$'KKLLLLLL   a&&,,..7"")W44'8Q8Q L^^^[\^^____G DDDDD `_____!si   ,I- 1AF3 2I- 3'H'I- 	H'%H<I- #H'$I- &H''AI- -
L:%L"	L+ALLc                 r    t          j        t           j        | k    t           j        |j        k              du S )z
    Checks if a notification is enabled for a user
    :param user: The user
    :param notification: Notification
    :return: True if the notification is enabled
    N)r	   get_or_noner   rD   )r   r   s     r   r4   r4      s<     	( %-/C/HLL]/]	
 	
 	r    )FN)#r   r   src.tg_compatr   r   src.tg_compat.errorr   r   r   src.tg_compat.extr   resources.EnvironmentEnvironmentr5   resources.phrasesrG   src.model.DisabledNotificationr	   src.model.Userr
   src.model.enums.Notificationr   src.model.enums.Screenr   src.model.pojo.Keyboardr   src.service.message_servicer   src.service.language_servicer   DEFAULT_TYPEboolr   r   r4    r    r   <module>rj      s        ) ) ) ) ) ) ) ) ? ? ? ? ? ? ? ? ? ? * * * * * * # # # # # # # # # # # # ? ? ? ? ? ?       5 5 5 5 5 5 ) ) ) ) ) ) , , , , , , 9 9 9 9 9 9 = = = = = = $)
 
&


 
 !	

 
 

 
 
 
L $)x x&x
x x !	x
 x 
x x x xvT  $      r    