1+ #(©)Codexbotz
2+ import os
3+ import asyncio
4+ from pyrogram import Client , filters , __version__
5+ from pyrogram .types import Message , InlineKeyboardMarkup , InlineKeyboardButton
6+ from pyrogram .errors import FloodWait
7+
8+ from bot import Bot
9+ from config import ADMINS , FORCE_MSG , START_MSG , OWNER_ID , CUSTOM_CAPTION , DISABLE_CHANNEL_BUTTON
10+ from helper_func import subscribed , encode , decode , get_messages
11+ from database .support import users_info
12+ from database .sql import add_user , query_msg
13+
14+
15+ #=====================================================================================##
16+
17+ USERS_LIST = """<b>⭕️Total:</b>\n \n ⭕️Subscribers - {}\n ⭕️Blocked- {}"""
18+
19+ WAIT_MSG = """"<b>Processing ...</b>"""
20+
21+ REPLY_ERROR = """<code>Use this command as a replay to any telegram message with out any spaces.</code>"""
22+
23+
24+ #=====================================================================================##
25+
26+
27+ @Bot .on_message (filters .command ('start' ) & filters .private & subscribed )
28+ async def start_command (client : Client , message : Message ):
29+ id = message .from_user .id
30+ user_name = '@' + message .from_user .username if message .from_user .username else None
31+ await add_user (id , user_name )
32+ text = message .text
33+ if len (text )> 7 :
34+ try :
35+ base64_string = text .split (" " , 1 )[1 ]
36+ except :
37+ return
38+ string = await decode (base64_string )
39+ argument = string .split ("-" )
40+ if len (argument ) == 3 :
41+ try :
42+ start = int (int (argument [1 ]) / abs (client .db_channel .id ))
43+ end = int (int (argument [2 ]) / abs (client .db_channel .id ))
44+ except :
45+ return
46+ if start <= end :
47+ ids = range (start ,end + 1 )
48+ else :
49+ ids = []
50+ i = start
51+ while True :
52+ ids .append (i )
53+ i -= 1
54+ if i < end :
55+ break
56+ elif len (argument ) == 2 :
57+ try :
58+ ids = [int (int (argument [1 ]) / abs (client .db_channel .id ))]
59+ except :
60+ return
61+ temp_msg = await message .reply ("Please wait..." )
62+ try :
63+ messages = await get_messages (client , ids )
64+ except :
65+ await message .reply_text ("Something went wrong..!" )
66+ return
67+ await temp_msg .delete ()
68+
69+ for msg in messages :
70+
71+ if bool (CUSTOM_CAPTION ) & bool (msg .document ):
72+ caption = CUSTOM_CAPTION .format (previouscaption = "" if not msg .caption else msg .caption .html , filename = msg .document .file_name )
73+ else :
74+ caption = "" if not msg .caption else msg .caption .html
75+
76+ if DISABLE_CHANNEL_BUTTON :
77+ reply_markup = msg .reply_markup
78+ else :
79+ reply_markup = None
80+
81+ try :
82+ await msg .copy (chat_id = message .from_user .id , caption = caption , parse_mode = 'html' , reply_markup = reply_markup )
83+ await asyncio .sleep (0.5 )
84+ except FloodWait as e :
85+ await asyncio .sleep (e .x )
86+ await msg .copy (chat_id = message .from_user .id , caption = caption , parse_mode = 'html' , reply_markup = reply_markup )
87+ except :
88+ pass
89+ return
90+ else :
91+ reply_markup = InlineKeyboardMarkup (
92+ [
93+ [
94+ InlineKeyboardButton ("😊 About Me" , callback_data = "about" ),
95+ InlineKeyboardButton ("🔒 Close" , callback_data = "close" )
96+ ]
97+ ]
98+ )
99+ await message .reply_text (
100+ text = START_MSG .format (
101+ first = message .from_user .first_name ,
102+ last = message .from_user .last_name ,
103+ username = None if not message .from_user .username else '@' + message .from_user .username ,
104+ mention = message .from_user .mention ,
105+ id = message .from_user .id
106+ ),
107+ reply_markup = reply_markup ,
108+ disable_web_page_preview = True ,
109+ quote = True
110+ )
111+ return
112+
113+ @Bot .on_message (filters .command ('start' ) & filters .private )
114+ async def not_joined (client : Client , message : Message ):
115+ reply_markup = InlineKeyboardMarkup ([[InlineKeyboardButton ("Join Channel" , url = client .invitelink )]])
116+ await message .reply (
117+ text = FORCE_MSG .format (
118+ first = message .from_user .first_name ,
119+ last = message .from_user .last_name ,
120+ username = None if not message .from_user .username else '@' + message .from_user .username ,
121+ mention = message .from_user .mention ,
122+ id = message .from_user .id
123+ ),
124+ reply_markup = reply_markup ,
125+ quote = True ,
126+ disable_web_page_preview = True
127+ )
128+
129+ @Bot .on_message (filters .private & filters .command ('users' ))
130+ async def subscribers_count (bot , m : Message ):
131+ id = m .from_user .id
132+ if id not in ADMINS :
133+ return
134+ msg = await m .reply_text (WAIT_MSG )
135+ messages = await users_info (bot )
136+ active = messages [0 ]
137+ blocked = messages [1 ]
138+ await m .delete ()
139+ await msg .edit (USERS_LIST .format (active , blocked ))
140+
141+
142+
143+ @Bot .on_message (filters .private & filters .command ('broadcast' ))
144+ async def send_text (bot , m : Message ):
145+ id = m .from_user .id
146+ if id not in ADMINS :
147+ return
148+ if (" " not in m .text ) and ("broadcast" in m .text ) and (m .reply_to_message is not None ):
149+ query = await query_msg ()
150+ for row in query :
151+ chat_id = int (row [0 ])
152+ try :
153+ await bot .copy_message (
154+ chat_id = chat_id ,
155+ from_chat_id = m .chat .id ,
156+ message_id = m .reply_to_message .message_id ,
157+ caption = m .caption ,
158+ reply_markup = m .reply_markup
159+ )
160+ except FloodWait as e :
161+ await asyncio .sleep (e .x )
162+ except Exception :
163+ pass
164+ else :
165+ msg = await m .reply_text (REPLY_ERROR , m .message_id )
166+ await asyncio .sleep (8 )
167+ await msg .delete ()
0 commit comments