o
    +h                     @   s  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 d dlmZmZ d dlmZmZ d dlmZ d d	lmZ d d
lZd d
lZd d
lZd d
lZd d
lZeddZe ZeeedZ ej!ej"d dZ#dZ$dZ%dZ&dZ'dZ(i Z)G dd deZ*G dd deZ+e j,dgddej-fddZ.e j,ej/j0ddej-fdd Z1e 2d!d" d#ej	fd$d%Z3e 2d&d" d#ej	fd'd(Z4e j,d)gd*d+dej-fd,d-Z5e j,e+j6d.dej-d/efd0d1Z7d2efd3d4Z8d5efd6d7Z9d8d9 Z:d
S ):    )Bot
Dispatchertypes)executor)InlineKeyboardButtonInlineKeyboardMarkupCallbackQuery)MemoryStorage)
FSMContext)StateStatesGroup)fmt_maintain_paramsfmt_type)ask)call_maintain_apiNz.7542850818:AAEvT7wQOTRmJm5m_3Td3CS_GLcR0nPdY6Q)token)storage)level	localhost3307root tg_chatl#+ c                   @      e Zd Ze ZdS )FormN)__name__
__module____qualname__r   waiting_for_confirm r   r   3/var/www/html/tg_maintain_bot/bot/tg_bot_aiogram.pyr   #       
r   c                   @   r   )StopMaintenanceN)r   r   r   r   waiting_for_platform_namer   r   r   r    r"   '   r!   r"   start)commandsmessagec                    s   |  dI d H  d S )NzHello! I'm a bot!)replyr&   r   r   r    send_welcome+   s   r)   )content_typesc                    s  | j j}t| j |dv rqt| jd}t|}|d dkr\t|}tt	 }|t
|< tdd}|tdd| d	d
tdd| dd
tdd| d
 tjt||dI d H  d S | jdksf| jdkrot| I d H  d S d S | jdks{| jdkrt| I d H  d S | dI d H  d S )N)group
supergroup)querytypeu   維護訊息   )	row_widthu+   ✅✅ 開啟我方“正式”平台維護confirm|u   |正式)callback_datau(   ✅ 開啟我方“測試”平台維護u   |測試u   ❌ 取消指令cancel|)chat_idtextreply_markup/stopz/stop@wsky_maintain_botu   我不提供私訊功能 📨)chatr.   printr5   r   r   r   struuiduuid4pending_confirmationsr   addr   botsend_messageGROUP_IDhandle_stopr'   )r&   	chat_typeresponser.   fmt_datauidkeyboardr   r   r    handle_group_text/   s.   

rH   c                 C      | j dS )Nr1   data
startswithcr   r   r    <lambda>Q       rO   callback_queryc                    s   |  dI d H  | jdd }t|}| jdd dk}t|r'g dng d|| jdI d H  |sCt| jj	j
d	I d H  d S tj| jj	j
| jjd d
I d H  t| jj	j
dI d H  d S )Nu   ✅ 維護流程已確認|r/      u   測試)   911機台測試站   飛龍測試站   魔方測試站)   911機台正式站   飛龍正式站   魔方正式站)maintain_platformrE   r?   u   ⚠️ 無效或過期的資料r4   
message_idr6   u   完成指令)answerrK   splitr=   getr   r&   r?   r@   r8   idedit_message_reply_markupr\   )rQ   rF   rE   is_testr   r   r    handle_confirmQ   s&   
rc   c                 C   rI   )Nr3   rJ   rM   r   r   r    rO   o   rP   c                    sN   |  dI d H  tj| jjj| jjd dI d H  t| jjjdI d H  d S )Nu   ❌ 已取消r[   u   ❌ 指令已取消)r]   r?   ra   r&   r8   r`   r\   r@   )rQ   r   r   r    handle_cancelo   s   rd   stop/)r%   commands_prefixc                    s&   |  dI d H  tj I d H  d S )Nu'   請輸入欲取消維護的平台名稱)r'   r"   r#   setr(   r   r   r    rB   }   s   rB   )stateri   c                    s`   | j  }tg d| dddddd| dI d H  | d| dI d H  | I d H  d S )N)rT   rU   rV   rW   rX   rY   r   )platforms_dates_timee_datee_timeT)rZ   rE   cancel_maintainr?   u   ✅ 已成功取消 u    的維護！)r5   stripr   upperr'   finish)r&   ri   platform_namer   r   r    handle_platform_name   s   
rt   r?   c                    s&   t jdddg}| |I d H  d S )Nr7   u   取消平台維護)commanddescription)r   
BotCommandset_my_commands)r?   r%   r   r   r    set_commands   s   ry   dpc                    s   t | jI d H  d S )N)ry   r?   )rz   r   r   r    
on_startup   s   r{   c                   C   s   t d tjtdtd d S )NzBot is runningT)skip_updatesr{   )r9   r   start_pollingrz   r{   r   r   r   r    init_bot_aiogram   s   r~   );aiogramr   r   r   aiogram.utilsr   aiogram.typesr   r   r   "aiogram.contrib.fsm_storage.memoryr	   aiogram.dispatcherr
    aiogram.dispatcher.filters.stater   r   utils.fmt_maintain_paramsr   r   openai_config.openai_utilsr   api.apir   sysospandaspdloggingr;   r?   r   rz   basicConfigINFOhostportuserpwddbrA   r=   r   r"   message_handlerMessager)   ContentTypeTEXTrH   callback_query_handlerrc   rd   rB   r#   rt   ry   r{   r~   r   r   r   r    <module>   sT    
!