-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
354 lines (309 loc) · 14.5 KB
/
main.py
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
import telebot
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
import uuid
import threading
import requests
# Replace with your bot's token
API_TOKEN = 'Your Bot Token Goes Here'
bot = telebot.TeleBot(API_TOKEN)
# Dictionary to store file data with unique identifiers
file_storage = {}
# Dictionary to store user settings
user_settings = {}
@bot.message_handler(commands=['start'])
def send_welcome(message):
command_parts = message.text.split()
if len(command_parts) > 1:
# Handle file retrieval if a file ID is passed
file_id = command_parts[1]
if file_id in file_storage:
file_info = file_storage[file_id]
file_type = file_info['type']
if file_type == 'document':
bot.send_document(message.chat.id, file_info['file_id'])
elif file_type == 'photo':
bot.send_photo(message.chat.id, file_info['file_id'])
elif file_type == 'video':
bot.send_video(message.chat.id, file_info['file_id'])
elif file_type == 'audio':
bot.send_audio(message.chat.id, file_info['file_id'])
elif file_type == 'text':
bot.send_message(message.chat.id, f"📄 Text Content:\n\n{file_info['content']}")
return
# Default welcome message with channel join prompt
user_name = message.from_user.first_name or "User"
welcome_text = (
f"⚡ <b>Hello {user_name}</b>\n\n"
"⚡️ Pʟs Jᴏɪɴ Oᴜʀ Mᴀɪɴ Cʜᴀɴɴᴇʟ\nAɴᴅ EɴJᴏʏ Oᴜʀ Lᴏᴏᴛs.."
)
# Buttons for joining channels
join_markup = InlineKeyboardMarkup(row_width=1)
join_markup.add(
InlineKeyboardButton("Join Main Channel", url="https://t.me/ModVipRM"),
InlineKeyboardButton("Join Developer Channel", url="https://t.me/ModviprmBackup"),
InlineKeyboardButton("Check Membership", callback_data="check_membership")
)
# Send welcome message with join buttons
bot.send_message(
message.chat.id,
welcome_text,
parse_mode="HTML",
reply_markup=join_markup
)
@bot.callback_query_handler(func=lambda call: call.data == "check_membership")
def check_membership(call):
user_id = call.message.chat.id
channels = ["@abir_x_official", "@abir_x_official_developer"]
try:
for channel in channels:
member_status = bot.get_chat_member(channel, user_id).status
if member_status not in ["member", "administrator", "creator"]:
bot.send_message(
call.message.chat.id,
"❌ You need to join all channels to access the bot's features."
)
return
# Show the main menu if the user is a member of both channels
main_menu(call.message.chat.id)
except Exception as e:
bot.send_message(
call.message.chat.id,
"❌ Unable to verify membership. Please ensure the channels are public and accessible."
)
print(f"Error: {e}")
def main_menu(chat_id):
# Main menu after joining channels
menu = InlineKeyboardMarkup(row_width=2)
menu.add(
InlineKeyboardButton("Aᴅᴅ Fɪʟᴇ [Sɪɴɢʟᴇ]", callback_data="add_file"),
InlineKeyboardButton("Lɪɴᴋ Sʜᴏʀᴛᴇɴᴇʀ", callback_data="link_shortener"),
InlineKeyboardButton("Mᴜʟᴛɪᴘʟᴇ [Fɪʟᴇs]", callback_data="multiple_files"),
InlineKeyboardButton("⚡ Eᴅɪᴛ [Sᴇᴛᴛɪɴɢs]", callback_data="edit_settings"),
InlineKeyboardButton("Aʙᴏᴜᴛ Mᴇ", callback_data="about_me"),
InlineKeyboardButton("Cʟᴏsᴇ", callback_data="close")
)
bot.send_message(
chat_id,
"✅ You have joined all channels. Welcome to the main menu!",
reply_markup=menu
)
# Handler for the "Mᴜʟᴛɪᴘʟᴇ [Fɪʟᴇs]" button
@bot.callback_query_handler(func=lambda call: call.data == "multiple_files")
def multiple_files_handler(call):
user_files = []
file_storage[call.message.chat.id] = user_files
markup = InlineKeyboardMarkup(row_width=1)
markup.add(InlineKeyboardButton("Aᴅᴅ Mᴏʀᴇ", callback_data="add_more"),
InlineKeyboardButton("Cᴀɴᴄᴇʟ Tᴏ Aᴅᴅ", callback_data="back_to_main"))
bot.send_message(
call.message.chat.id,
"🔥 Sᴇɴᴅ Mᴇssᴀɢᴇ Oʀ Fɪʟᴇs \nTʜᴀᴛ Yᴏᴜ Wᴀɴᴛ Tᴏ Aᴅᴅ...\n\nTᴏ Cᴀɴᴄᴇʟ: /cancel",
reply_markup=markup
)
# Helper function for generating shareable links
def generate_shareable_link(bot_username, unique_id):
return f"https://t.me/{bot_username}?start={unique_id}"
# Process multiple file uploads
@bot.message_handler(
func=lambda message: isinstance(file_storage.get(message.chat.id), list),
content_types=['document', 'photo', 'video', 'audio', 'text']
)
def handle_multiple_file_upload(message):
user_files = file_storage.get(message.chat.id, [])
unique_id = str(uuid.uuid4())
# Store file data globally by unique ID
if message.document:
file_data = {'type': 'document', 'file_id': message.document.file_id}
elif message.photo:
file_data = {'type': 'photo', 'file_id': message.photo[-1].file_id}
elif message.video:
file_data = {'type': 'video', 'file_id': message.video.file_id}
elif message.audio:
file_data = {'type': 'audio', 'file_id': message.audio.file_id}
elif message.text:
file_data = {'type': 'text', 'content': message.text}
else:
return
# Save the file data globally
file_storage[unique_id] = file_data
user_files.append(unique_id)
# Update user-specific file list
file_storage[message.chat.id] = user_files
if len(user_files) < 3:
markup = InlineKeyboardMarkup(row_width=1)
markup.add(
InlineKeyboardButton("Aᴅᴅ Mᴏʀᴇ", callback_data="add_more"),
InlineKeyboardButton("Cᴀɴᴄᴇʟ Tᴏ Aᴅᴅ", callback_data="back_to_main")
)
bot.send_message(
message.chat.id,
f"✅ Fɪʟᴇ Uᴘʟᴏᴀᴅᴇᴅ Sᴜᴄᴄᴇssғᴜʟʟʏ...\n\nYᴏᴜ ʜᴀᴠᴇ Uᴘʟᴏᴀᴅᴇᴅ {len(user_files)} ғɪʟᴇs.",
reply_markup=markup
)
else:
bot_username = bot.get_me().username
shareable_links = [
generate_shareable_link(bot_username, file_id)
for file_id in user_files
]
links_text = "\n\n".join(shareable_links)
markup = InlineKeyboardMarkup(row_width=1)
markup.add(
InlineKeyboardButton("Sʜᴀʀᴇ Lɪɴᴋs", callback_data="share_links"),
InlineKeyboardButton("Rᴇᴛᴜʀɴ Bᴀᴄᴋ Tᴏ Mᴀɪɴ Mᴇɴᴜ", callback_data="back_to_main")
)
bot.send_message(
message.chat.id,
f"✅ Fɪʟᴇs Uᴘʟᴏᴀᴅᴇᴅ Sᴜᴄᴄᴇssғᴜʟʟʏ...\n\n⚡️ Sʜᴀʀᴇᴀʙʟᴇ Lɪɴᴋs:\n\n{links_text}",
reply_markup=markup
)
# Clear user-specific list
file_storage[message.chat.id] = []
@bot.callback_query_handler(func=lambda call: call.data == "add_more")
def add_more_files(call):
bot.send_message(
call.message.chat.id,
"🔥 Sᴇɴᴅ Mᴏʀᴇ Mᴇssᴀɢᴇs Oʀ Fɪʟᴇs...\n\nTᴏ Cᴀɴᴄᴇʟ: /cancel"
)
# Handler for the "Cᴀɴᴄᴇʟ Tᴏ Aᴅᴅ" button
@bot.callback_query_handler(func=lambda call: call.data == "back_to_main")
def back_to_main(call):
send_welcome(call.message)
# Handle user cancellation with /cancel command
@bot.message_handler(commands=['cancel'])
def cancel_add_file(message):
if isinstance(file_storage.get(message.chat.id), list):
# Clear the file storage for the user
file_storage[message.chat.id] = []
bot.send_message(
message.chat.id,
"❌ Yᴏᴜ Hᴀᴠᴇ Cᴀɴᴄᴇʟʟᴇᴅ Sᴜᴄᴄᴇssғᴜʟʟʏ\nTᴏ Aᴅᴅ Fɪʟᴇs..."
)
send_welcome(message)
# Handler for the "Lɪɴᴋ Sʜᴏʀᴛᴇɴᴇʀ" button
@bot.callback_query_handler(func=lambda call: call.data == "link_shortener")
def link_shortener_handler(call):
link_shortener_text = "🔥 Eɴᴛᴇʀ Yᴏᴜʀ Lɪɴᴋ..."
link_shortener_markup = InlineKeyboardMarkup(row_width=1)
link_shortener_markup.add(
InlineKeyboardButton("Sʜᴏʀᴛᴇɴ Lɪɴᴋ", callback_data="generate_short_link"),
InlineKeyboardButton("Rᴇᴛᴜʀɴ Bᴀᴄᴋ", callback_data="back_to_main")
)
bot.send_message(
call.message.chat.id,
link_shortener_text,
reply_markup=link_shortener_markup
)
# Handler for the "Generate Short Link" button
@bot.callback_query_handler(func=lambda call: call.data == "generate_short_link")
def generate_short_link(call):
bot.send_message(
call.message.chat.id,
"🔥 Eɴᴛᴇʀ Yᴏᴜʀ Lɪɴᴋ..."
)
bot.register_next_step_handler(call.message, process_short_link)
def process_short_link(message):
url = message.text.strip()
try:
response = requests.get(f'https://tinyurl.com/api-create.php?url={url}')
short_link = response.text
markup = InlineKeyboardMarkup(row_width=1)
shorten_link_button = InlineKeyboardButton("Sʜᴏʀᴛᴇɴ Lɪɴᴋ", url=short_link)
markup.add(shorten_link_button)
bot.send_message(
message.chat.id,
"✅ Hᴇʀᴇ ɪs Yᴏᴜʀ Sʜᴏʀᴛᴇɴᴇᴅ Lɪɴᴋ:",
reply_markup=markup
)
except:
bot.send_message(
message.chat.id,
"❌ Iɴᴠᴀʟɪᴅ Uʀʟ..."
)
# Handler for the "⚡ Edit [Settings]" button
@bot.callback_query_handler(func=lambda call: call.data == "edit_settings")
def edit_settings(call):
user_id = call.message.chat.id
if user_id not in user_settings:
user_settings[user_id] = {"auto_delete": False, "protect_content": False}
settings_text = "⚙️ <b>Eᴅɪᴛ Sᴇᴛᴛɪɴɢs</b>"
settings_markup = InlineKeyboardMarkup(row_width=1)
auto_delete_button_text = "Auto Delete: On 🔥" if user_settings[user_id]["auto_delete"] else "Auto Delete: Off"
settings_markup.add(InlineKeyboardButton(auto_delete_button_text, callback_data="toggle_auto_delete"))
protect_content_button_text = "Protect Content: On 🔒" if user_settings[user_id]["protect_content"] else "Protect Content: Off"
settings_markup.add(InlineKeyboardButton(protect_content_button_text, callback_data="toggle_protect_content"))
settings_markup.add(InlineKeyboardButton("Return Back To Page", callback_data="back_to_main"))
bot.edit_message_text(
chat_id=call.message.chat.id,
message_id=call.message.message_id,
text=settings_text,
parse_mode="HTML",
reply_markup=settings_markup
)
# Handler for toggling auto delete
@bot.callback_query_handler(func=lambda call: call.data == "toggle_auto_delete")
def toggle_auto_delete(call):
user_id = call.message.chat.id
user_settings[user_id]["auto_delete"] = not user_settings[user_id]["auto_delete"]
edit_settings(call)
# Handler for toggling protect content
@bot.callback_query_handler(func=lambda call: call.data == "toggle_protect_content")
def toggle_protect_content(call):
user_id = call.message.chat.id
user_settings[user_id]["protect_content"] = not user_settings[user_id]["protect_content"]
edit_settings(call)
# Handler for the "Add File [Single]" button
@bot.callback_query_handler(func=lambda call: call.data == "add_file")
def add_file_prompt(call):
bot.send_message(
call.message.chat.id,
"🔥 Sᴇɴᴅ Mᴇssᴀɢᴇ Oʀ Fɪʟᴇ \nTʜᴀᴛ Yᴏᴜ Wᴀɴᴛ Tᴏ Aᴅᴅ...\n\nTᴏ Cᴀɴᴄᴇʟ: /cancel"
)
file_storage[call.message.chat.id] = "awaiting_file"
# Handle file upload
@bot.message_handler(func=lambda message: file_storage.get(message.chat.id) == "awaiting_file", content_types=['document', 'photo', 'video', 'audio', 'text'])
def handle_file_upload(message):
unique_id = str(uuid.uuid4())
if message.document:
file_storage[unique_id] = {'type': 'document', 'file_id': message.document.file_id}
elif message.photo:
file_storage[unique_id] = {'type': 'photo', 'file_id': message.photo[-1].file_id}
elif message.video:
file_storage[unique_id] = {'type': 'video', 'file_id': message.video.file_id}
elif message.audio:
file_storage[unique_id] = {'type': 'audio', 'file_id': message.audio.file_id}
elif message.text:
file_storage[unique_id] = {'type': 'text', 'content': message.text}
file_storage[message.chat.id] = None
file_link = f"https://t.me/{bot.get_me().username}?start={unique_id}"
bot.send_message(
message.chat.id,
f"✅ Uᴘʟᴏᴀᴅᴇᴅ SᴜᴄᴄᴇssFᴜʟʟʏ...\n\n⚡️ Lɪɴᴋ:\n{file_link}"
)
if user_settings.get(message.chat.id, {}).get("auto_delete", False):
def delete_file():
del file_storage[unique_id]
bot.send_message(message.chat.id, f"❌ Fɪʟᴇ [{unique_id}] Hᴀs Bᴇᴇɴ Aᴜᴛᴏᴍᴀᴛɪᴄᴀʟʟʏ Dᴇʟᴇᴛᴇᴅ")
timer = threading.Timer(1800, delete_file) # 30 minutes
timer.start()
# Handler for the "Aʙᴏᴜᴛ Mᴇ" button
@bot.callback_query_handler(func=lambda call: call.data == "about_me")
def about_me(call):
about_text = (
"╔════════════⦿\n"
"├⋗ Cʀᴇᴀᴛᴏʀ: ⏤͟͞〲ᗩᗷiᖇ 𓊈乂ᗪ𓊉\n"
"├⋗ Lᴀɴɢᴜᴀɢᴇ: Pʏᴛʜᴏɴ\n"
"├⋗ Bᴏᴛ Usᴇʀɴᴀᴍᴇ: @Kalyani_Priya_Darshan_Bot\n"
"├⋗ Mᴀɪɴ Cʜᴀɴɴᴇʟ: @ModVipRM\n"
"├⋗ Sᴜᴘᴘᴏʀᴛ Gʀᴏᴜᴘ: @ModVipRM_Discussion\n"
"╚═════════════════⦿"
)
close_markup = InlineKeyboardMarkup(row_width=1)
close_markup.add(InlineKeyboardButton("Cʟᴏsᴇ", callback_data="close"))
bot.send_message(call.message.chat.id, about_text, reply_markup=close_markup)
# Handler for the "Close" button
@bot.callback_query_handler(func=lambda call: call.data == "close")
def close(call):
send_welcome(call.message)
# Start polling to keep the bot running
bot.polling()