o
    {g                      @   s  d dl mZmZ d dlmZmZ d dlmZmZ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mZmZmZmZ ejed
ej@ ej@ dedefddZejedej@ dedefddZejedej@ dedefddZejedej@ dedefddZ ejejej!@ ej"@ ej @ ej# @ ej @ ej$ @ dedefddZ%ej&e'd
dedefddZ(ed)d
d)dd)dd)dd *d!+  d"S )#    )Clientfilters)ChatAdminRequiredUserNotParticipant)CallbackQueryChatPermissionsInlineKeyboardButtonInlineKeyboardMarkupMessage)LOGS)is_user_admin   )gen_inline_keyboard   )BotHelpConfigSymbolsdbhellbotforcesubclientmessagec              
      sd  t |jdk r|dI d H S zt|j| jjI d H }|s+|d| dI d H W S W n tyA   |d| dI d H  Y S w |jd }z
| |I d H }W n t	yo } z|d| dI d H W  Y d }~S d }~ww t|| jjI d H s|dI d H S t
|jj|jI d H  |d	|j d
|j dI d H  |jjtjvrtj|jj d S d S )Nr   z%Give a channel username with command!z&To use forcesub i must be an admin in !r   **Error:**
``z$Make me admin in that channel first!uo   **📌 𝖢𝗁𝖺𝗍 𝖥𝗈𝗋𝖼𝖾𝗌𝗎𝖻 𝖤𝗇𝖺𝖻𝗅𝖾𝖽!** 

__Users must join__ z (`z`) __to chat here!__)lencommand
reply_textr   chatmeidr   get_chat	Exceptionr   add_forcesubtitler   	FORCESUBSadd)r   r   is_admin	must_joinr   e r*   W/var/www/bot.gig.net.ua/public_html/telegram/P1/HellBot/Hellbot/plugins/bot/forcesub.py	force_sub   s>   
$
r,   
unforcesubc              
      sv  t |jdk r|dI d H S t|j| jjI d H s#|dI d H S d|jd  krFt	|jjI d H  t
j|jj |dI d H S zVt|jjt|jd I d H rt|jjt|jd I d H }|r||d|jd  d| d	I d H W S t
j|jj |d|jd  d
I d H W S |dI d H W S  ty } z|d| d	I d H W  Y d }~S d }~ww )Nr   zZGive a channel username with command or give 'all' to remove all forcesubs from this chat!#To use forcesub i must be an admin!allr   u   **📌 Forcesub disabled!**u   **📌 Removed Forcesub `z/`!**

**Remaining Forcesub(s) in this chat:** `r   z`!**u+   **📌 This chat is not forcesub enabled!**r   )r   r   r   r   r   r   r    lowerr   rm_all_forcesubr   r%   removeis_forcesubintrm_forcesubr"   )r   r   	remainingr)   r*   r*   r+   unforce_sub1   s6   
  $r7   listforcesubc                    s   t |j| jjI d H s|dI d H S tj}d}t|dkrM|D ]*}z| |d I d H }|d|j	 d|j d7 }W q!   |d|d  d7 }Y q!nd	}||I d H  d S )
Nr.    r   r      **📌 ** (``)
** - `Invalid Chat!`
u$   **📌 No Forcesub Enabled in Bot!**)
r   r   r   r    r   r   r%   r   r!   r$   )r   r   all_forcesubstextr   r   r*   r*   r+   list_force_subsR   s   r@   getforcesubc                    s   t |jdk r|j}nz| |jd I d H }W n   |dI d H  Y S t|jI d H }|rhdt |d  d}|d D ]&}z| |I d H }|d|j d|j d	7 }W q@   |d| d
7 }Y q@nd}||I d H  d S )Nr   r   z **Invalid Channel Username/ID!**z**This chat has r(   z forcesub(s):**
r:   r;   r<   r=   u*   **📌 No Forcesub Enabled in This Chat!**)	r   r   r   r!   r   r   get_forcesubr    r$   )r   r   r   	mustjoinsr?   r(   r*   r*   r+   rA   g   s&   c           	         sf  |j jtjvr
d S t|j | jjsd S g }t|j jI d H }t|d D ]K\}}z| 	||j
jI d H  W q& tyS   | |I d H }|d| |df Y q& ty[   Y q& tyq } zt| W Y d }~q&d }~ww t|dkrzd S t|d}|tdd|j
j d|j j g |jd	|j j d
tj dtj dtj d	dt|dI d H  d S )Nr(   zJoin urlr   r   u   Unmute 🗣️zforcesub:unmute::u   **👋 Welcome to zH!**

To be able to chat here, you must follow the instructions below:
  z> __Click the buttons below to join our important channels.__  zA __After joining all channels, press the unmute button below.__  z __Then you can chat here.__T)disable_web_page_previewreply_markup)r   r    r   r%   r   r   r   rB   	enumerateget_chat_member	from_userr   export_chat_invite_linkappendr   r"   r   warningr   r   r   r   r$   r   anchorr	   )	r   r   	btns_listrC   ir(   invite_linkr)   	join_btnsr*   r*   r+   handle_force_sub   sN   


rS   cbc                    s  |j d}|d dkrzt|d |jjjks$|jdddI d H W S t|jjjI d H }|d D ]\}z| 	t||j
jI d H  W q3 tyZ   |jd	ddI d H  Y   W S  tyo   |jd
ddI d H  Y   W S  ty } z|d| dI d H W  Y d }~  W S d }~ww tdd}|jjt|d |I d H  W n ty } z|d| dI d H W  Y d }~S d }~ww |jdddI d H  |j I d H S d S )NrE   r   unmute   z**This is not for this chat!**T)
show_alertr(   z%**You must join all channels first!**zBI'm not admin in some of the channels! Ask owner to make me admin.r   r   )can_send_messagesr   u   **📌 Unmuted!**)datasplitr4   r   r   r    answerr   rB   rI   rJ   r   r   r"   r   restrict_memberdelete)r   rT   rY   r(   r   r)   permissionsr*   r*   r+   forcesub_cb   sD   *
"$r_   ForceSubzKThis command is used to force users to join some channels to chat in group.z?This command is used to remove channels from forcesub in group.z1This command is used to list all forcesub in bot.z.This command is used to get forcesub in group.u   ForceSub 🚀N),pyrogramr   r   pyrogram.errorsr   r   pyrogram.typesr   r   r   r	   r
   Hellbot.corer   Hellbot.functions.adminsr   btnsGr   r9   r   r   r   r   r   bot
on_messager   
AUTH_USERSgroupr,   r7   r@   rA   incomingnew_chat_membersservicer   rS   on_callback_queryregexr_   r&   infodoner*   r*   r*   r+   <module>   sd     	+"
