o
    eOj+"                     @   s  d dl Z d dlZd dl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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l.m Z/ d dl0m Z1 d dl2m Z3 d dl4m Z5 d dl6m Z7 dddZ8dddZ9dddZ:e;dkre <e:  dS dS )    N)Bot
Dispatcher)DefaultBotProperties)	ParseMode)RedisStorage)logger)Redis)settings)close_db)BotFilterMiddleware)DatabaseMiddleware)UserRegisterMiddleware)BanCheckMiddleware)SubscriptionMiddleware)ThrottlingMiddleware)routerreturnc                   C   s2   t   t jtjddd t jdddddd	 d
S )zLoguru konfiguratsiyasiz<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>INFO)formatlevelzlogs/kinobot.logz10 MBz7 dayszipDEBUG)rotation	retentioncompressionr   N)r   removeaddsysstderr r   r   5/var/www/www-root/data/www/ai-bot.pdev.uz/bot/main.pysetup_logging%   s   
r!   c                     sf   dd l } ddlm} | j|dtjdd}| j|d}dd |_t	d	tj d
 |
 I d H  d S )Nr   )appz0.0.0.0warning)r"   hostport	log_level)configc                   S   s   d S )Nr   r   r   r   r    <lambda>A   s    z"run_admin_server.<locals>.<lambda>zAdmin panel http://0.0.0.0:z portida ishga tushmoqda...)uvicorn
admin.mainr"   Configr	   
admin_portServerinstall_signal_handlersr   infoserve)r)   	admin_appr'   serverr   r   r    run_admin_server6   s   
r3   c               	      sF  t   td tjtjdd} t| d}ttj	t
tjdd}t|d}|jt  |jt  |jt  |jt  |jt  |jt  |jt  |jt  |jt  |jt  |jt| d |jt  |t |t |t |t |t |t |t |t  |t! |t" |t# |t$ dd	l%m&} |' d
|fdd}ddl%m(}m)}m*} |ddd|ddd|dddg}	|j+|	| dI d H  d}
d}z|,|
I d H  |-|I d H  W n
 t.y   Y nw |	|ddd|ddd|ddd|dddg }tj/D ]}z|j+|||d dI d H  W q+ t.yH   Y q+w td! |j0||1 d"g}tj2rb|3t4  z%t5j6| I d H  W td# |j78 I d H  t9 I d H  | : I d H  d S td# |j78 I d H  t9 I d H  | : I d H  w )$NzKinoBot ishga tushmoqda...F)decode_responses)redis)
parse_mode)tokendefault)storager   )
ErrorEventeventc              	      sn   t d| j  tjD ]'}z| j|dt| jd d  d| jj dI d H  W q t	y4   Y qw d S )NzKutilmagan xato: u9   ❌ <b>Kutilmagan xato yuz berdi!</b>

💬 Xabar: <code>i  u    </code>
ℹ️ Update ID: <code>z</code>)
r   	exceptionr	   super_admin_listbotsend_messagestrupdate	update_id	Exception)r;   admin_idr   r   r    global_error_handler|   s    
z"main.<locals>.global_error_handler)
BotCommandBotCommandScopeDefaultBotCommandScopeChatstartzBotni boshlash)commanddescriptionsearchzKino qidirishhelpYordam)scopeu   🎬 KinoBot — O'zbek kinolar boti

Bu bot orqali minglab kinolarni bepul tomosha qilishingiz mumkin!

📌 Foydalanish:
• Kino kodini yuboring → kino darhol keladi
• /search — kino nomini qidirish

▶️ Boshlash uchun Start tugmasini bosing!u1   🎬 Kino kodini yuboring — kino darhol keladi!adminzAdmin panelbanzUserni ban qilishunbanzUnban qilishuserinfozUser ma'lumoti)chat_idz Bot muvaffaqiyatli ishga tushdi!)allowed_updateszBot to'xtatilmoqda...);r!   r   r/   r   from_urlr	   	redis_urlr   r   	bot_tokenr   r   HTMLr   message
middlewarer   callback_queryr   r   r   r   r   channel_postinclude_routerchannel_post_routerstart_routersubscription_routersearch_routeradmin_panel_routeradmin_channels_routeradmin_stats_routeradmin_admins_routeradmin_broadcast_routeradmin_moderation_routeradmin_movies_routerfallback_routeraiogram.typesr:   errorrF   rG   rH   set_my_commandsset_my_descriptionset_my_short_descriptionrC   r=   start_pollingresolve_used_update_types	run_adminappendr3   asynciogathersessioncloser
   aclose)r5   r9   r>   dpr:   rE   rF   rG   rH   user_commandsbot_descriptionbot_short_descriptionadmin_commandsrD   
coroutinesr   r   r    mainF   s   


























r   __main__)r   N)=rt   r   aiogramr   r   aiogram.client.defaultr   aiogram.enumsr   aiogram.fsm.storage.redisr   logurur   redis.asyncior   
bot.configr	   bot.database.connectionr
   bot.middlewares.bot_filterr   bot.middlewares.databaser   bot.middlewares.user_registerr   bot.middlewares.ban_checkr   bot.middlewares.subscriptionr   bot.middlewares.throttlingr   bot.handlers.user.startr   r`   bot.handlers.user.searchrb   bot.handlers.user.subscriptionra   bot.handlers.user.fallbackrj   bot.handlers.channel_postr_   bot.handlers.admin.panelrc   bot.handlers.admin.channelsrd   bot.handlers.admin.statsre   bot.handlers.admin.adminsrf   bot.handlers.admin.broadcastrg   bot.handlers.admin.moderationrh   bot.handlers.admin.moviesri   r!   r3   r   __name__runr   r   r   r    <module>   sF    


 