-
Notifications
You must be signed in to change notification settings - Fork 849
Expand file tree
/
Copy pathstart.py
More file actions
322 lines (279 loc) · 12.8 KB
/
start.py
File metadata and controls
322 lines (279 loc) · 12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# Don't Remove Credit @CodeFlix_Bots, @rohit_1888
# Ask Doubt on telegram @CodeflixSupport
import asyncio
import os
import random
import sys
import time
import string
import string as rohit
from pyrogram import Client, filters, __version__
from pyrogram.enums import ParseMode
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant
from pyrogram.errors import FloodWait, UserIsBlocked, InputUserDeactivated, UserNotParticipant
from bot import Bot
from config import *
from helper_func import *
from database.database import *
# File auto-delete time in seconds (Set your desired time in seconds here)
FILE_AUTO_DELETE = TIME # Example: 3600 seconds (1 hour)
TUT_VID = f"{TUT_VID}"
@Bot.on_message(filters.command('start') & filters.private & subscribed1 & subscribed2 & subscribed3 & subscribed4)
async def start_command(client: Client, message: Message):
id = message.from_user.id
if not await present_user(id):
try:
await add_user(id)
except:
pass
# Check if user is an admin and treat them as verified
if id in ADMINS:
verify_status = {
'is_verified': True,
'verify_token': None, # Admins don't need a token
'verified_time': time.time(),
'link': ""
}
else:
verify_status = await get_verify_status(id)
# If TOKEN is enabled, handle verification logic
if TOKEN:
if verify_status['is_verified'] and VERIFY_EXPIRE < (time.time() - verify_status['verified_time']):
await update_verify_status(id, is_verified=False)
if "verify_" in message.text:
_, token = message.text.split("_", 1)
if verify_status['verify_token'] != token:
return await message.reply("Your token is invalid or expired. Try again by clicking /start.")
await update_verify_status(id, is_verified=True, verified_time=time.time())
if verify_status["link"] == "":
reply_markup = None
return await message.reply(
f"Your token has been successfully verified and is valid for {get_exp_time(VERIFY_EXPIRE)}",
reply_markup=reply_markup,
protect_content=False,
quote=True
)
if not verify_status['is_verified']:
token = ''.join(random.choices(rohit.ascii_letters + rohit.digits, k=10))
await update_verify_status(id, verify_token=token, link="")
link = await get_shortlink(SHORTLINK_URL, SHORTLINK_API, f'https://telegram.dog/{client.username}?start=verify_{token}')
btn = [
[InlineKeyboardButton("• ᴏᴘᴇɴ ʟɪɴᴋ •", url=link)],
[InlineKeyboardButton('• ʜᴏᴡ ᴛᴏ ᴏᴘᴇɴ ʟɪɴᴋ •', url=TUT_VID)]
]
return await message.reply(
f"<b>Your token has expired. Please refresh your token to continue.\n\nToken Timeout: {get_exp_time(VERIFY_EXPIRE)}\n\nWhat is the token?\n\nThis is an ads token. Passing one ad allows you to use the bot for {get_exp_time(VERIFY_EXPIRE)}</b>",
reply_markup=InlineKeyboardMarkup(btn),
protect_content=False,
quote=True
)
# Handle normal message flow
text = message.text
if len(text) > 7:
try:
base64_string = text.split(" ", 1)[1]
except IndexError:
return
string = await decode(base64_string)
argument = string.split("-")
ids = []
if len(argument) == 3:
try:
start = int(int(argument[1]) / abs(client.db_channel.id))
end = int(int(argument[2]) / abs(client.db_channel.id))
ids = range(start, end + 1) if start <= end else list(range(start, end - 1, -1))
except Exception as e:
print(f"Error decoding IDs: {e}")
return
elif len(argument) == 2:
try:
ids = [int(int(argument[1]) / abs(client.db_channel.id))]
except Exception as e:
print(f"Error decoding ID: {e}")
return
temp_msg = await message.reply("Please wait...")
try:
messages = await get_messages(client, ids)
except Exception as e:
await message.reply_text("Something went wrong!")
print(f"Error getting messages: {e}")
return
finally:
await temp_msg.delete()
codeflix_msgs = []
for msg in messages:
caption = (CUSTOM_CAPTION.format(previouscaption="" if not msg.caption else msg.caption.html,
filename=msg.document.file_name) if bool(CUSTOM_CAPTION) and bool(msg.document)
else ("" if not msg.caption else msg.caption.html))
reply_markup = msg.reply_markup if DISABLE_CHANNEL_BUTTON else None
try:
copied_msg = await msg.copy(chat_id=message.from_user.id, caption=caption, parse_mode=ParseMode.HTML,
reply_markup=reply_markup, protect_content=PROTECT_CONTENT)
codeflix_msgs.append(copied_msg)
except FloodWait as e:
await asyncio.sleep(e.x)
copied_msg = await msg.copy(chat_id=message.from_user.id, caption=caption, parse_mode=ParseMode.HTML,
reply_markup=reply_markup, protect_content=PROTECT_CONTENT)
codeflix_msgs.append(copied_msg)
except Exception as e:
print(f"Failed to send message: {e}")
pass
if FILE_AUTO_DELETE > 0:
notification_msg = await message.reply(
f"<b>This file will be deleted in {get_exp_time(FILE_AUTO_DELETE)}. Please save or forward it to your saved messages before it gets deleted.</b>"
)
await asyncio.sleep(FILE_AUTO_DELETE)
for snt_msg in codeflix_msgs:
if snt_msg:
try:
await snt_msg.delete()
except Exception as e:
print(f"Error deleting message {snt_msg.id}: {e}")
try:
reload_url = (
f"https://t.me/{client.username}?start={message.command[1]}"
if message.command and len(message.command) > 1
else None
)
keyboard = InlineKeyboardMarkup(
[[InlineKeyboardButton("ɢᴇᴛ ғɪʟᴇ ᴀɢᴀɪɴ!", url=reload_url)]]
) if reload_url else None
await notification_msg.edit(
"<b>ʏᴏᴜʀ ᴠɪᴅᴇᴏ / ꜰɪʟᴇ ɪꜱ ꜱᴜᴄᴄᴇꜱꜱꜰᴜʟʟʏ ᴅᴇʟᴇᴛᴇᴅ !!\n\nᴄʟɪᴄᴋ ʙᴇʟᴏᴡ ʙᴜᴛᴛᴏɴ ᴛᴏ ɢᴇᴛ ʏᴏᴜʀ ᴅᴇʟᴇᴛᴇᴅ ᴠɪᴅᴇᴏ / ꜰɪʟᴇ 👇</b>",
reply_markup=keyboard
)
except Exception as e:
print(f"Error updating notification with 'Get File Again' button: {e}")
else:
reply_markup = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("𝗔𝗯𝗼𝘂𝘁", callback_data = "about"),
InlineKeyboardButton('𝗖𝗵𝗮𝗻𝗻𝗲𝗹𝘀', url='https://t.me/cypherixsocity')
]
]
)
await message.reply_photo(
photo=START_PIC,
caption=START_MSG.format(
first=message.from_user.first_name,
last=message.from_user.last_name,
username=None if not message.from_user.username else '@' + message.from_user.username,
mention=message.from_user.mention,
id=message.from_user.id
),
reply_markup=reply_markup#,
#message_effect_id=5104841245755180586 # 🔥
)
return
#=====================================================================================##
# Don't Remove Credit @CodeFlix_Bots, @rohit_1888
# Ask Doubt on telegram @CodeflixSupport
@Bot.on_message(filters.command('start') & filters.private)
async def not_joined(client: Client, message: Message):
# Initialize buttons list
buttons = []
# Check if the first and second channels are both set
if FORCE_SUB_CHANNEL1 and FORCE_SUB_CHANNEL2:
buttons.append([
InlineKeyboardButton(text="• ᴊᴏɪɴ ᴄʜᴀɴɴᴇʟ", url=client.invitelink1),
InlineKeyboardButton(text="ᴊᴏɪɴ ᴄʜᴀɴɴᴇʟ •", url=client.invitelink2),
])
# Check if only the first channel is set
elif FORCE_SUB_CHANNEL1:
buttons.append([
InlineKeyboardButton(text="• ᴊᴏɪɴ ᴄʜᴀɴɴᴇʟ•", url=client.invitelink1)
])
# Check if only the second channel is set
elif FORCE_SUB_CHANNEL2:
buttons.append([
InlineKeyboardButton(text="• ᴊᴏɪɴ ᴄʜᴀɴɴᴇʟ•", url=client.invitelink2)
])
# Check if the third and fourth channels are set
if FORCE_SUB_CHANNEL3 and FORCE_SUB_CHANNEL4:
buttons.append([
InlineKeyboardButton(text="• ᴊᴏɪɴ ᴄʜᴀɴɴᴇʟ", url=client.invitelink3),
InlineKeyboardButton(text="ᴊᴏɪɴ ᴄʜᴀɴɴᴇʟ •", url=client.invitelink4),
])
# Check if only the first channel is set
elif FORCE_SUB_CHANNEL3:
buttons.append([
InlineKeyboardButton(text="• ᴊᴏɪɴ ᴄʜᴀɴɴᴇʟ•", url=client.invitelink3)
])
# Check if only the second channel is set
elif FORCE_SUB_CHANNEL4:
buttons.append([
InlineKeyboardButton(text="• ᴊᴏɪɴ ᴄʜᴀɴɴᴇʟ•", url=client.invitelink4)
])
# Append "Try Again" button if the command has a second argument
try:
buttons.append([
InlineKeyboardButton(
text="ʀᴇʟᴏᴀᴅ",
url=f"https://t.me/{client.username}?start={message.command[1]}"
)
])
except IndexError:
pass # Ignore if no second argument is present
await message.reply_photo(
photo=FORCE_PIC,
caption=FORCE_MSG.format(
first=message.from_user.first_name,
last=message.from_user.last_name,
username=None if not message.from_user.username else '@' + message.from_user.username,
mention=message.from_user.mention,
id=message.from_user.id
),
reply_markup=InlineKeyboardMarkup(buttons)#,
#message_effect_id=5104841245755180586 # Add the effect ID here
)
#=====================================================================================##
WAIT_MSG = "<b>Working....</b>"
REPLY_ERROR = "<code>Use this command as a reply to any telegram message without any spaces.</code>"
#=====================================================================================##
@Bot.on_message(filters.command('users') & filters.private & filters.user(ADMINS))
async def get_users(client: Bot, message: Message):
msg = await client.send_message(chat_id=message.chat.id, text=WAIT_MSG)
users = await full_userbase()
await msg.edit(f"{len(users)} users are using this bot")
@Bot.on_message(filters.private & filters.command('broadcast') & filters.user(ADMINS))
async def send_text(client: Bot, message: Message):
if message.reply_to_message:
query = await full_userbase()
broadcast_msg = message.reply_to_message
total = 0
successful = 0
blocked = 0
deleted = 0
unsuccessful = 0
pls_wait = await message.reply("<i>ʙʀᴏᴀᴅᴄᴀꜱᴛ ᴘʀᴏᴄᴇꜱꜱɪɴɢ....</i>")
for chat_id in query:
try:
await broadcast_msg.copy(chat_id)
successful += 1
except FloodWait as e:
await asyncio.sleep(e.x)
await broadcast_msg.copy(chat_id)
successful += 1
except UserIsBlocked:
await del_user(chat_id)
blocked += 1
except InputUserDeactivated:
await del_user(chat_id)
deleted += 1
except:
unsuccessful += 1
pass
total += 1
status = f"""<b><u>ʙʀᴏᴀᴅᴄᴀꜱᴛ...</u>
Total Users: <code>{total}</code>
Successful: <code>{successful}</code>
Blocked Users: <code>{blocked}</code>
Deleted Accounts: <code>{deleted}</code>
Unsuccessful: <code>{unsuccessful}</code></b>"""
return await pls_wait.edit(status)
else:
msg = await message.reply(REPLY_ERROR)
await asyncio.sleep(8)
await msg.delete()