Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,7 @@ import asyncio
|
|
| 23 |
import httpx
|
| 24 |
import gradio as gr
|
| 25 |
import threading
|
|
|
|
| 26 |
from datetime import datetime
|
| 27 |
from fastapi import Request
|
| 28 |
from fastapi.responses import JSONResponse
|
|
@@ -44,14 +45,11 @@ API_HEALTH = "https://costum-boomber-api.vercel.app/api/health"
|
|
| 44 |
|
| 45 |
bot = Bot(token=BOT_TOKEN)
|
| 46 |
|
| 47 |
-
# --- DATABASE & STATE ---
|
| 48 |
DB_FILE = "users.json"
|
| 49 |
USER_DB = {}
|
| 50 |
seen_users = set()
|
| 51 |
MAINTENANCE_MODE = False
|
| 52 |
-
BLACKLISTED_NUMBERS = set()
|
| 53 |
|
| 54 |
-
# --- STATE MACHINE ---
|
| 55 |
ASK_NUMBER, ASK_MESSAGE, ASK_COUNT = range(3)
|
| 56 |
WAITING_FOR_ADMIN_PASS = 99
|
| 57 |
|
|
@@ -72,7 +70,7 @@ def save_db():
|
|
| 72 |
with open(DB_FILE, "w") as f:
|
| 73 |
json.dump(USER_DB, f)
|
| 74 |
except Exception as e:
|
| 75 |
-
print(f"DB Save Error: {e}")
|
| 76 |
|
| 77 |
def load_db():
|
| 78 |
global USER_DB
|
|
@@ -81,8 +79,9 @@ def load_db():
|
|
| 81 |
with open(DB_FILE, "r") as f:
|
| 82 |
data = json.load(f)
|
| 83 |
USER_DB = {int(k): v for k, v in data.items()}
|
|
|
|
| 84 |
except Exception as e:
|
| 85 |
-
print(f"DB Load Error: {e}")
|
| 86 |
|
| 87 |
def background_saver():
|
| 88 |
while True:
|
|
@@ -93,14 +92,14 @@ threading.Thread(target=background_saver, daemon=True).start()
|
|
| 93 |
load_db()
|
| 94 |
|
| 95 |
# -------------------------------------------------------------------
|
| 96 |
-
# 4. ZEROGPU
|
| 97 |
# -------------------------------------------------------------------
|
| 98 |
@spaces.GPU(duration=10)
|
| 99 |
def _zerogpu_register():
|
| 100 |
return "gpu-ready"
|
| 101 |
|
| 102 |
# -------------------------------------------------------------------
|
| 103 |
-
# 5.
|
| 104 |
# -------------------------------------------------------------------
|
| 105 |
async def send_log(text: str):
|
| 106 |
try:
|
|
@@ -140,316 +139,315 @@ def get_admin_menu_keyboard():
|
|
| 140 |
])
|
| 141 |
|
| 142 |
# -------------------------------------------------------------------
|
| 143 |
-
# 6. MAIN
|
| 144 |
# -------------------------------------------------------------------
|
| 145 |
async def process_update(update: Update):
|
| 146 |
global MAINTENANCE_MODE
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
db_user = get_user(user_id)
|
| 154 |
-
|
| 155 |
-
if db_user.get("banned"):
|
| 156 |
-
if msg: await bot.send_message(chat_id=user_id, text=f"🚫 <b>Banned.</b>\nReason: {db_user.get('ban_reason')}", parse_mode="HTML")
|
| 157 |
-
return
|
| 158 |
-
|
| 159 |
-
if msg and msg.text:
|
| 160 |
-
text = msg.text.strip()
|
| 161 |
|
| 162 |
-
|
| 163 |
-
if text.startswith("/"):
|
| 164 |
-
db_user["state"] = None # Cancel any ongoing flow
|
| 165 |
-
|
| 166 |
-
# 1. Handle /start
|
| 167 |
-
if text == "/start":
|
| 168 |
-
if user_id not in seen_users:
|
| 169 |
-
seen_users.add(user_id)
|
| 170 |
-
await send_log(f"👤 <b>NEW USER</b>\nID: <code>{user_id}</code>\nUsername: @{user.username or 'None'}")
|
| 171 |
-
|
| 172 |
-
is_owner = (user_id == ADMIN_ID)
|
| 173 |
-
if not is_owner:
|
| 174 |
-
if not await check_channel_membership(user_id):
|
| 175 |
-
await bot.send_message(chat_id=user_id, text="🔒 <b>Access Denied</b>\nJoin channel first.", parse_mode="HTML", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("📢 Join Channel", url=f"https://t.me/{CHANNEL_ID.replace('@', '')}")]]))
|
| 176 |
-
return
|
| 177 |
-
|
| 178 |
-
db_user["verified"] = True
|
| 179 |
-
if not db_user["accepted"]:
|
| 180 |
-
disclaimer_text = (
|
| 181 |
-
"⚠️ <b>LEGAL DISCLAIMER & TERMS OF SERVICE</b> ⚠️\n\n"
|
| 182 |
-
"<b>1. EDUCATIONAL USE ONLY</b>\n"
|
| 183 |
-
"This bot is strictly for educational purposes, API testing, and network stress simulations. You must not use it to harass or spam.\n\n"
|
| 184 |
-
"<b>2. CONSENT</b>\n"
|
| 185 |
-
"You confirm you have explicit permission from the owner of the target phone number to send these test messages.\n\n"
|
| 186 |
-
"<b>3. LOGGING & DATA</b>\n"
|
| 187 |
-
"All actions, including your Telegram ID, target numbers, and messages, are logged to a private database. If you abuse this bot, you will be banned.\n\n"
|
| 188 |
-
"<b>4. NO LIABILITY</b>\n"
|
| 189 |
-
"The developers are not responsible for any legal or personal consequences of your actions.\n\n"
|
| 190 |
-
"<b>By clicking 'I Accept', you agree to these terms.</b>"
|
| 191 |
-
)
|
| 192 |
-
await bot.send_message(chat_id=user_id, text=disclaimer_text, parse_mode="HTML", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("✅ I Accept & Agree", callback_data="accept_disclaimer")]]))
|
| 193 |
-
return
|
| 194 |
-
|
| 195 |
-
await bot.send_message(chat_id=user_id, text=f"👋 Welcome back, <b>{user.first_name}</b>!", parse_mode="HTML", reply_markup=get_main_menu_keyboard())
|
| 196 |
-
return
|
| 197 |
|
| 198 |
-
#
|
| 199 |
-
if
|
| 200 |
-
db_user
|
| 201 |
-
await bot.send_message(chat_id=user_id, text="🔐 <b>Admin Login</b>\nEnter password:")
|
| 202 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
admin_text = (
|
| 208 |
-
"👑 <b>ADMIN DASHBOARD</b>\n\n"
|
| 209 |
-
"<b>Available Commands:</b>\n"
|
| 210 |
-
"• /ban <id> <reason> - Ban a user\n"
|
| 211 |
-
"• /unban <id> - Unban a user\n"
|
| 212 |
-
"• /warn <id> <reason> - Issue warning\n"
|
| 213 |
-
"• /setvip <id> - Toggle VIP status\n"
|
| 214 |
-
"• /broadcast <msg> - Send to all users\n\n"
|
| 215 |
-
"<i>Use the buttons below for interactive menus.</i>"
|
| 216 |
-
)
|
| 217 |
-
await bot.send_message(chat_id=user_id, text=admin_text, parse_mode="HTML", reply_markup=get_admin_menu_keyboard())
|
| 218 |
-
return
|
| 219 |
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
await bot.send_message(chat_id=user_id, text=f"✅ User {target} unbanned.")
|
| 242 |
-
return
|
| 243 |
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
tu["warnings"] = tu.get("warnings", 0) + 1
|
| 258 |
-
if tu["warnings"] >= 3:
|
| 259 |
-
tu["banned"] = True
|
| 260 |
-
tu["ban_reason"] = "3 Warnings reached"
|
| 261 |
-
await bot.send_message(chat_id=user_id, text=f"🚫 User {target} auto-banned (3 warnings).")
|
| 262 |
-
else:
|
| 263 |
-
await bot.send_message(chat_id=user_id, text=f"⚠️ User {target} warned ({tu['warnings']}/3). Reason: {reason}")
|
| 264 |
-
return
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
await bot.send_message(chat_id=uid, text=msg_text)
|
| 273 |
-
count += 1
|
| 274 |
-
except: pass
|
| 275 |
-
await bot.send_message(chat_id=user_id, text=f"✅ Sent to {count} users.")
|
| 276 |
-
return
|
| 277 |
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
|
|
|
|
|
|
| 287 |
else:
|
| 288 |
-
|
| 289 |
-
await bot.send_message(chat_id=user_id, text="❌ Incorrect password.")
|
| 290 |
return
|
| 291 |
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
|
|
|
|
|
|
| 311 |
return
|
| 312 |
|
| 313 |
-
if
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
db_user["daily_requests"] = 0
|
| 317 |
-
db_user["last_reset"] = today
|
| 318 |
-
|
| 319 |
-
if db_user.get("daily_requests", 0) >= 5:
|
| 320 |
-
await bot.send_message(chat_id=user_id, text="❌ Daily limit reached (5/5). Use /claim or try tomorrow.")
|
| 321 |
-
db_user["state"] = None
|
| 322 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
|
|
|
|
|
|
|
|
|
| 327 |
return
|
| 328 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
db_user["state"] = None
|
| 330 |
-
db_user["daily_requests"] = db_user.get("daily_requests", 0) + 1
|
| 331 |
-
db_user["last_attack_time"] = time.time()
|
| 332 |
-
|
| 333 |
-
await bot.send_message(chat_id=user_id, text="⏳ Sending...")
|
| 334 |
-
url = f"{API_BASE}?count={count}&msg={db_user['target_msg']}&number={db_user['target_number']}"
|
| 335 |
-
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 336 |
-
try:
|
| 337 |
-
resp = await client.get(url)
|
| 338 |
-
data = resp.json()
|
| 339 |
-
if resp.status_code == 200 and data.get("ok"):
|
| 340 |
-
sent = data.get('sent', 0)
|
| 341 |
-
db_user["stats"]["requests"] += 1
|
| 342 |
-
db_user["stats"]["sent"] += sent
|
| 343 |
-
reply = (
|
| 344 |
-
f"✅ <b>Attack Successful!</b>\n\n"
|
| 345 |
-
f"🎯 Target: <code>{db_user['target_number']}</code>\n"
|
| 346 |
-
f"🔁 Rounds: {count}\n"
|
| 347 |
-
f"💥 Fired: {sent} messages\n"
|
| 348 |
-
f"<i>(Shotgun Mode: 1 round = 10 msgs)</i>\n"
|
| 349 |
-
f"⏱️ Time: {data.get('elapsedSec')}s"
|
| 350 |
-
)
|
| 351 |
-
await bot.send_message(chat_id=user_id, text=reply, parse_mode="HTML", reply_markup=get_main_menu_keyboard())
|
| 352 |
-
else:
|
| 353 |
-
await bot.send_message(chat_id=user_id, text="❌ API Error.", reply_markup=get_main_menu_keyboard())
|
| 354 |
-
except Exception:
|
| 355 |
-
await bot.send_message(chat_id=user_id, text="❌ Network Error.", reply_markup=get_main_menu_keyboard())
|
| 356 |
-
return
|
| 357 |
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
if data in ["menu_main", "accept_disclaimer", "menu_attack", "menu_profile", "menu_claim", "menu_health", "menu_help"]:
|
| 366 |
-
db_user["state"] = None
|
| 367 |
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
|
| 373 |
-
|
| 374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
await safe_edit_message(user_id, cb_query.message.message_id, "🎉 <b>SUCCESS!</b>\nYou claimed 1 extra attack!", get_main_menu_keyboard())
|
| 410 |
-
|
| 411 |
-
elif data == "menu_health":
|
| 412 |
-
await safe_edit_message(user_id, cb_query.message.message_id, "📡 Pinging...", None)
|
| 413 |
-
try:
|
| 414 |
-
async with httpx.AsyncClient() as client:
|
| 415 |
-
r = await client.get(API_HEALTH, timeout=5)
|
| 416 |
-
d = r.json()
|
| 417 |
-
txt = f"**API STATUS**\nNodes: {d.get('dbs')}\nDevices: {d.get('cachedDevices')}" if d.get("ok") else "🔴 API Down."
|
| 418 |
-
await safe_edit_message(user_id, cb_query.message.message_id, txt, get_main_menu_keyboard())
|
| 419 |
-
except:
|
| 420 |
-
await safe_edit_message(user_id, cb_query.message.message_id, "🔴 API unreachable.", get_main_menu_keyboard())
|
| 421 |
-
|
| 422 |
-
elif data == "menu_help":
|
| 423 |
-
txt = (
|
| 424 |
-
"📖 <b>Available Commands</b>\n\n"
|
| 425 |
-
"• /start - Show Main Menu\n"
|
| 426 |
-
"• /send - Start an attack\n"
|
| 427 |
-
"• /health - Check API status\n"
|
| 428 |
-
"• /delete_history - Clear your history\n\n"
|
| 429 |
-
"<i>Tip: Use the buttons below for quick access.</i>"
|
| 430 |
-
)
|
| 431 |
-
await safe_edit_message(user_id, cb_query.message.message_id, txt, get_main_menu_keyboard())
|
| 432 |
-
|
| 433 |
-
elif data == "admin_users":
|
| 434 |
-
if not db_user.get("is_admin"): return
|
| 435 |
-
txt = f"👥 <b>Total Users: {len(USER_DB)}</b>\nBanned: {sum(1 for u in USER_DB.values() if u.get('banned'))}\nVIPs: {sum(1 for u in USER_DB.values() if u.get('is_vip'))}"
|
| 436 |
-
await safe_edit_message(user_id, cb_query.message.message_id, txt, get_admin_menu_keyboard())
|
| 437 |
-
|
| 438 |
-
elif data == "admin_maintenance":
|
| 439 |
-
if not db_user.get("is_admin"): return
|
| 440 |
-
MAINTENANCE_MODE = not MAINTENANCE_MODE
|
| 441 |
-
await safe_edit_message(user_id, cb_query.message.message_id, f"🛠️ Maintenance: {'ON' if MAINTENANCE_MODE else 'OFF'}", get_admin_menu_keyboard())
|
| 442 |
-
|
| 443 |
-
elif data == "admin_stats":
|
| 444 |
-
if not db_user.get("is_admin"): return
|
| 445 |
-
total_req = sum(u.get("stats", {}).get("requests", 0) for u in USER_DB.values())
|
| 446 |
-
total_sent = sum(u.get("stats", {}).get("sent", 0) for u in USER_DB.values())
|
| 447 |
-
txt = f"📊 <b>Global Stats</b>\nTotal Attacks: {total_req}\nTotal Msgs: {total_sent}"
|
| 448 |
-
await safe_edit_message(user_id, cb_query.message.message_id, txt, get_admin_menu_keyboard())
|
| 449 |
-
return
|
| 450 |
|
| 451 |
# -------------------------------------------------------------------
|
| 452 |
-
# 7. WEBHOOK
|
| 453 |
# -------------------------------------------------------------------
|
| 454 |
async def telegram_webhook(request: Request):
|
| 455 |
try:
|
|
@@ -465,7 +463,7 @@ async def health_check(request: Request):
|
|
| 465 |
return JSONResponse({"status": "ok", "bot": "running"})
|
| 466 |
|
| 467 |
# -------------------------------------------------------------------
|
| 468 |
-
# 8.
|
| 469 |
# -------------------------------------------------------------------
|
| 470 |
with gr.Blocks(title="Bot Host") as demo:
|
| 471 |
gr.Markdown("# 🤖 Bot is Running")
|
|
|
|
| 23 |
import httpx
|
| 24 |
import gradio as gr
|
| 25 |
import threading
|
| 26 |
+
import traceback
|
| 27 |
from datetime import datetime
|
| 28 |
from fastapi import Request
|
| 29 |
from fastapi.responses import JSONResponse
|
|
|
|
| 45 |
|
| 46 |
bot = Bot(token=BOT_TOKEN)
|
| 47 |
|
|
|
|
| 48 |
DB_FILE = "users.json"
|
| 49 |
USER_DB = {}
|
| 50 |
seen_users = set()
|
| 51 |
MAINTENANCE_MODE = False
|
|
|
|
| 52 |
|
|
|
|
| 53 |
ASK_NUMBER, ASK_MESSAGE, ASK_COUNT = range(3)
|
| 54 |
WAITING_FOR_ADMIN_PASS = 99
|
| 55 |
|
|
|
|
| 70 |
with open(DB_FILE, "w") as f:
|
| 71 |
json.dump(USER_DB, f)
|
| 72 |
except Exception as e:
|
| 73 |
+
print(f"❌ DB Save Error: {e}")
|
| 74 |
|
| 75 |
def load_db():
|
| 76 |
global USER_DB
|
|
|
|
| 79 |
with open(DB_FILE, "r") as f:
|
| 80 |
data = json.load(f)
|
| 81 |
USER_DB = {int(k): v for k, v in data.items()}
|
| 82 |
+
print(f"✅ Loaded {len(USER_DB)} users from DB.")
|
| 83 |
except Exception as e:
|
| 84 |
+
print(f"❌ DB Load Error: {e}")
|
| 85 |
|
| 86 |
def background_saver():
|
| 87 |
while True:
|
|
|
|
| 92 |
load_db()
|
| 93 |
|
| 94 |
# -------------------------------------------------------------------
|
| 95 |
+
# 4. ZEROGPU HANDLER
|
| 96 |
# -------------------------------------------------------------------
|
| 97 |
@spaces.GPU(duration=10)
|
| 98 |
def _zerogpu_register():
|
| 99 |
return "gpu-ready"
|
| 100 |
|
| 101 |
# -------------------------------------------------------------------
|
| 102 |
+
# 5. HELPERS
|
| 103 |
# -------------------------------------------------------------------
|
| 104 |
async def send_log(text: str):
|
| 105 |
try:
|
|
|
|
| 139 |
])
|
| 140 |
|
| 141 |
# -------------------------------------------------------------------
|
| 142 |
+
# 6. MAIN HANDLER
|
| 143 |
# -------------------------------------------------------------------
|
| 144 |
async def process_update(update: Update):
|
| 145 |
global MAINTENANCE_MODE
|
| 146 |
+
try:
|
| 147 |
+
user = update.effective_user
|
| 148 |
+
if not user: return
|
| 149 |
+
user_id = user.id
|
| 150 |
+
msg = update.message
|
| 151 |
+
cb_query = update.callback_query
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
+
db_user = get_user(user_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
+
# --- BAN CHECK ---
|
| 156 |
+
if db_user.get("banned"):
|
| 157 |
+
if msg: await bot.send_message(chat_id=user_id, text=f"🚫 <b>Banned.</b>\nReason: {db_user.get('ban_reason')}", parse_mode="HTML")
|
|
|
|
| 158 |
return
|
| 159 |
+
|
| 160 |
+
# --- TEXT COMMANDS ---
|
| 161 |
+
if msg and msg.text:
|
| 162 |
+
text = msg.text.strip()
|
| 163 |
|
| 164 |
+
# Reset state for any new command
|
| 165 |
+
if text.startswith("/"):
|
| 166 |
+
db_user["state"] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
+
# 1. /start
|
| 169 |
+
if text == "/start":
|
| 170 |
+
if user_id not in seen_users:
|
| 171 |
+
seen_users.add(user_id)
|
| 172 |
+
await send_log(f"👤 <b>NEW USER</b>\nID: <code>{user_id}</code>\nUsername: @{user.username or 'None'}")
|
| 173 |
+
|
| 174 |
+
if user_id != ADMIN_ID:
|
| 175 |
+
if not await check_channel_membership(user_id):
|
| 176 |
+
await bot.send_message(chat_id=user_id, text="🔒 <b>Access Denied</b>\nJoin channel first.", parse_mode="HTML", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("📢 Join Channel", url=f"https://t.me/{CHANNEL_ID.replace('@', '')}")]]))
|
| 177 |
+
return
|
| 178 |
+
|
| 179 |
+
db_user["verified"] = True
|
| 180 |
+
if not db_user["accepted"]:
|
| 181 |
+
disclaimer = (
|
| 182 |
+
"⚠️ <b>LEGAL DISCLAIMER & TERMS OF SERVICE</b> ⚠️\n\n"
|
| 183 |
+
"<b>1. EDUCATIONAL USE ONLY</b>\nStrictly for testing. Do not use to harass.\n\n"
|
| 184 |
+
"<b>2. CONSENT</b>\nYou confirm you have permission from the target number's owner.\n\n"
|
| 185 |
+
"<b>3. LOGGING</b>\nAll actions are logged. Abuse = ban.\n\n"
|
| 186 |
+
"<b>By clicking 'I Accept', you agree.</b>"
|
| 187 |
+
)
|
| 188 |
+
await bot.send_message(chat_id=user_id, text=disclaimer, parse_mode="HTML", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("✅ I Accept & Agree", callback_data="accept_disclaimer")]]))
|
| 189 |
+
return
|
| 190 |
+
|
| 191 |
+
await bot.send_message(chat_id=user_id, text=f"👋 Welcome back, <b>{user.first_name}</b>!", parse_mode="HTML", reply_markup=get_main_menu_keyboard())
|
| 192 |
+
return
|
| 193 |
|
| 194 |
+
# 2. /admin
|
| 195 |
+
if text == "/admin":
|
| 196 |
+
db_user["state"] = WAITING_FOR_ADMIN_PASS
|
| 197 |
+
await bot.send_message(chat_id=user_id, text="🔐 <b>Admin Login</b>\nEnter password:")
|
| 198 |
+
return
|
| 199 |
+
|
| 200 |
+
# 3. /admin_panel
|
| 201 |
+
if text == "/admin_panel":
|
| 202 |
+
if db_user.get("is_admin"):
|
| 203 |
+
admin_text = (
|
| 204 |
+
"👑 <b>ADMIN DASHBOARD</b>\n\n"
|
| 205 |
+
"<b>Commands:</b>\n"
|
| 206 |
+
"/ban <id> <reason> | /unban <id>\n"
|
| 207 |
+
"/warn <id> <reason> | /setvip <id>\n"
|
| 208 |
+
"/broadcast <msg>"
|
| 209 |
+
)
|
| 210 |
+
await bot.send_message(chat_id=user_id, text=admin_text, parse_mode="HTML", reply_markup=get_admin_menu_keyboard())
|
| 211 |
+
return
|
| 212 |
|
| 213 |
+
# 4. /delete_history
|
| 214 |
+
if text == "/delete_history":
|
| 215 |
+
await bot.send_message(chat_id=user_id, text="✅ <b>History Deletion Scheduled</b>\nData will be purged in 24 hours.", parse_mode="HTML")
|
| 216 |
+
return
|
|
|
|
|
|
|
| 217 |
|
| 218 |
+
# 5. Admin: /ban
|
| 219 |
+
if text.startswith("/ban ") and db_user.get("is_admin"):
|
| 220 |
+
parts = text.split(" ", 2)
|
| 221 |
+
if len(parts) >= 2:
|
| 222 |
+
target = int(parts[1])
|
| 223 |
+
reason = parts[2] if len(parts) > 2 else "No reason"
|
| 224 |
+
get_user(target)["banned"] = True
|
| 225 |
+
get_user(target)["ban_reason"] = reason
|
| 226 |
+
await bot.send_message(chat_id=user_id, text=f"✅ User {target} banned.")
|
| 227 |
+
return
|
| 228 |
|
| 229 |
+
# 6. Admin: /unban
|
| 230 |
+
if text.startswith("/unban ") and db_user.get("is_admin"):
|
| 231 |
+
target = int(text.split(" ")[1])
|
| 232 |
+
get_user(target)["banned"] = False
|
| 233 |
+
await bot.send_message(chat_id=user_id, text=f"✅ User {target} unbanned.")
|
| 234 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
+
# 7. Admin: /setvip
|
| 237 |
+
if text.startswith("/setvip ") and db_user.get("is_admin"):
|
| 238 |
+
target = int(text.split(" ")[1])
|
| 239 |
+
get_user(target)["is_vip"] = not get_user(target).get("is_vip", False)
|
| 240 |
+
await bot.send_message(chat_id=user_id, text=f"✅ VIP toggled for {target}.")
|
| 241 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
+
# 8. Admin: /warn
|
| 244 |
+
if text.startswith("/warn ") and db_user.get("is_admin"):
|
| 245 |
+
parts = text.split(" ", 2)
|
| 246 |
+
target = int(parts[1])
|
| 247 |
+
reason = parts[2] if len(parts) > 2 else "No reason"
|
| 248 |
+
tu = get_user(target)
|
| 249 |
+
tu["warnings"] = tu.get("warnings", 0) + 1
|
| 250 |
+
if tu["warnings"] >= 3:
|
| 251 |
+
tu["banned"] = True
|
| 252 |
+
tu["ban_reason"] = "3 Warnings"
|
| 253 |
+
await bot.send_message(chat_id=user_id, text=f"🚫 User {target} auto-banned.")
|
| 254 |
else:
|
| 255 |
+
await bot.send_message(chat_id=user_id, text=f"⚠️ User {target} warned ({tu['warnings']}/3).")
|
|
|
|
| 256 |
return
|
| 257 |
|
| 258 |
+
# 9. Admin: /broadcast
|
| 259 |
+
if text.startswith("/broadcast ") and db_user.get("is_admin"):
|
| 260 |
+
msg_text = text.replace("/broadcast ", "")
|
| 261 |
+
count = 0
|
| 262 |
+
for uid in USER_DB.keys():
|
| 263 |
+
try:
|
| 264 |
+
await bot.send_message(chat_id=uid, text=msg_text)
|
| 265 |
+
count += 1
|
| 266 |
+
except: pass
|
| 267 |
+
await bot.send_message(chat_id=user_id, text=f"✅ Sent to {count} users.")
|
| 268 |
+
return
|
| 269 |
+
|
| 270 |
+
# --- STATE MACHINE ---
|
| 271 |
+
if db_user.get("state"):
|
| 272 |
+
state = db_user["state"]
|
| 273 |
+
print(f"[DEBUG] User {user_id} in state {state}, input: {text}")
|
| 274 |
|
| 275 |
+
if state == WAITING_FOR_ADMIN_PASS:
|
| 276 |
+
if text == ADMIN_PASSWORD:
|
| 277 |
+
db_user["is_admin"] = True
|
| 278 |
+
db_user["state"] = None
|
| 279 |
+
await bot.send_message(chat_id=user_id, text="✅ <b>Admin Mode Enabled.</b>\nUse /admin_panel.")
|
| 280 |
+
else:
|
| 281 |
+
db_user["state"] = None
|
| 282 |
+
await bot.send_message(chat_id=user_id, text="❌ Incorrect password.")
|
| 283 |
return
|
| 284 |
|
| 285 |
+
if state == ASK_NUMBER:
|
| 286 |
+
if not text.isdigit() or len(text) != 10:
|
| 287 |
+
await bot.send_message(chat_id=user_id, text="❌ Invalid number. Enter 10 digits:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
return
|
| 289 |
+
db_user["target_number"] = text
|
| 290 |
+
db_user["state"] = ASK_MESSAGE
|
| 291 |
+
save_db() # Explicit save
|
| 292 |
+
await bot.send_message(chat_id=user_id, text="💬 Enter message:")
|
| 293 |
+
|
| 294 |
+
elif state == ASK_MESSAGE:
|
| 295 |
+
db_user["target_msg"] = text
|
| 296 |
+
db_user["state"] = ASK_COUNT
|
| 297 |
+
save_db() # Explicit save
|
| 298 |
+
await bot.send_message(chat_id=user_id, text="🔢 Count (1-10):")
|
| 299 |
|
| 300 |
+
elif state == ASK_COUNT:
|
| 301 |
+
try:
|
| 302 |
+
count = int(text)
|
| 303 |
+
if count < 1 or count > 10: raise ValueError
|
| 304 |
+
except:
|
| 305 |
+
await bot.send_message(chat_id=user_id, text="❌ Enter number 1-10.")
|
| 306 |
return
|
| 307 |
|
| 308 |
+
if not db_user.get("is_admin") and not db_user.get("is_vip"):
|
| 309 |
+
today = str(datetime.now().date())
|
| 310 |
+
if db_user.get("last_reset") != today:
|
| 311 |
+
db_user["daily_requests"] = 0
|
| 312 |
+
db_user["last_reset"] = today
|
| 313 |
+
|
| 314 |
+
if db_user.get("daily_requests", 0) >= 5:
|
| 315 |
+
await bot.send_message(chat_id=user_id, text="❌ Daily limit reached (5/5).")
|
| 316 |
+
db_user["state"] = None
|
| 317 |
+
return
|
| 318 |
+
|
| 319 |
+
time_since_last = time.time() - db_user.get("last_attack_time", 0)
|
| 320 |
+
if time_since_last < 30:
|
| 321 |
+
await bot.send_message(chat_id=user_id, text=f"⏳ Wait {int(30 - time_since_last)}s.")
|
| 322 |
+
return
|
| 323 |
+
|
| 324 |
+
db_user["state"] = None
|
| 325 |
+
db_user["daily_requests"] = db_user.get("daily_requests", 0) + 1
|
| 326 |
+
db_user["last_attack_time"] = time.time()
|
| 327 |
+
save_db()
|
| 328 |
+
|
| 329 |
+
await bot.send_message(chat_id=user_id, text="⏳ Sending...")
|
| 330 |
+
url = f"{API_BASE}?count={count}&msg={db_user['target_msg']}&number={db_user['target_number']}"
|
| 331 |
+
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 332 |
+
try:
|
| 333 |
+
resp = await client.get(url)
|
| 334 |
+
data = resp.json()
|
| 335 |
+
if resp.status_code == 200 and data.get("ok"):
|
| 336 |
+
sent = data.get('sent', 0)
|
| 337 |
+
db_user["stats"]["requests"] += 1
|
| 338 |
+
db_user["stats"]["sent"] += sent
|
| 339 |
+
reply = (
|
| 340 |
+
f"✅ <b>Attack Successful!</b>\n\n"
|
| 341 |
+
f"🎯 Target: <code>{db_user['target_number']}</code>\n"
|
| 342 |
+
f"🔁 Rounds: {count}\n"
|
| 343 |
+
f"💥 Fired: {sent} messages\n"
|
| 344 |
+
f"<i>(Shotgun: 1 round = 10 msgs)</i>\n"
|
| 345 |
+
f"⏱️ Time: {data.get('elapsedSec')}s"
|
| 346 |
+
)
|
| 347 |
+
await bot.send_message(chat_id=user_id, text=reply, parse_mode="HTML", reply_markup=get_main_menu_keyboard())
|
| 348 |
+
else:
|
| 349 |
+
await bot.send_message(chat_id=user_id, text="❌ API Error.", reply_markup=get_main_menu_keyboard())
|
| 350 |
+
except Exception as e:
|
| 351 |
+
print(f"[API ERROR] {e}")
|
| 352 |
+
await bot.send_message(chat_id=user_id, text="❌ Network Error.", reply_markup=get_main_menu_keyboard())
|
| 353 |
+
return
|
| 354 |
+
|
| 355 |
+
# --- CALLBACKS ---
|
| 356 |
+
if cb_query:
|
| 357 |
+
try: await bot.answer_callback_query(callback_query_id=cb_query.id)
|
| 358 |
+
except: pass
|
| 359 |
+
data = cb_query.data
|
| 360 |
+
|
| 361 |
+
if data in ["menu_main", "accept_disclaimer", "menu_attack", "menu_profile", "menu_claim", "menu_health", "menu_help"]:
|
| 362 |
db_user["state"] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
|
| 364 |
+
if data == "accept_disclaimer":
|
| 365 |
+
db_user["accepted"] = True
|
| 366 |
+
db_user["verified"] = True
|
| 367 |
+
await safe_edit_message(user_id, cb_query.message.message_id, "👋 Welcome! Choose an option:", get_main_menu_keyboard())
|
| 368 |
+
|
| 369 |
+
elif data == "menu_main":
|
| 370 |
+
await safe_edit_message(user_id, cb_query.message.message_id, "👋 <b>Main Menu</b>", get_main_menu_keyboard())
|
|
|
|
|
|
|
| 371 |
|
| 372 |
+
elif data == "menu_attack":
|
| 373 |
+
if MAINTENANCE_MODE and not db_user.get("is_admin"):
|
| 374 |
+
await safe_edit_message(user_id, cb_query.message.message_id, "🛠️ Under maintenance.", get_main_menu_keyboard())
|
| 375 |
+
return
|
| 376 |
+
db_user["state"] = ASK_NUMBER
|
| 377 |
+
save_db()
|
| 378 |
+
await safe_edit_message(user_id, cb_query.message.message_id, "📱 Enter target number:")
|
| 379 |
+
|
| 380 |
+
elif data == "menu_profile":
|
| 381 |
+
stats = db_user["stats"]
|
| 382 |
+
vip = "👑 VIP" if db_user.get("is_vip") else "👤 Standard"
|
| 383 |
+
text = f"👤 <b>{user.first_name}</b>\nRank: {vip}\nAttacks: {stats['requests']} | Msgs: {stats['sent']}\nDaily: {db_user.get('daily_requests')}/5"
|
| 384 |
+
await safe_edit_message(user_id, cb_query.message.message_id, text, get_main_menu_keyboard())
|
| 385 |
+
|
| 386 |
+
elif data == "menu_claim":
|
| 387 |
+
await safe_edit_message(user_id, cb_query.message.message_id, "🔄 Checking...", None)
|
| 388 |
+
await asyncio.sleep(0.5)
|
| 389 |
+
await safe_edit_message(user_id, cb_query.message.message_id, "🎰 Rolling...", None)
|
| 390 |
+
await asyncio.sleep(0.5)
|
| 391 |
+
await safe_edit_message(user_id, cb_query.message.message_id, "🎁 Unboxing...", None)
|
| 392 |
+
await asyncio.sleep(0.5)
|
| 393 |
+
|
| 394 |
+
now = time.time()
|
| 395 |
+
if now - db_user.get("claim_time", 0) < 86400:
|
| 396 |
+
rem = int(86400 - (now - db_user.get("claim_time", 0)))
|
| 397 |
+
await safe_edit_message(user_id, cb_query.message.message_id, f"⏳ Claim in {rem//3600}h.", get_main_menu_keyboard())
|
| 398 |
+
else:
|
| 399 |
+
db_user["claim_time"] = now
|
| 400 |
+
db_user["daily_requests"] = max(0, db_user.get("daily_requests", 0) - 1)
|
| 401 |
+
save_db()
|
| 402 |
+
await safe_edit_message(user_id, cb_query.message.message_id, "🎉 <b>SUCCESS!</b>\nYou claimed 1 extra attack!", get_main_menu_keyboard())
|
| 403 |
|
| 404 |
+
elif data == "menu_health":
|
| 405 |
+
await safe_edit_message(user_id, cb_query.message.message_id, "📡 Pinging...", None)
|
| 406 |
+
try:
|
| 407 |
+
async with httpx.AsyncClient() as client:
|
| 408 |
+
r = await client.get(API_HEALTH, timeout=5)
|
| 409 |
+
d = r.json()
|
| 410 |
+
txt = f"**API STATUS**\nNodes: {d.get('dbs')}\nDevices: {d.get('cachedDevices')}" if d.get("ok") else "🔴 API Down."
|
| 411 |
+
await safe_edit_message(user_id, cb_query.message.message_id, txt, get_main_menu_keyboard())
|
| 412 |
+
except:
|
| 413 |
+
await safe_edit_message(user_id, cb_query.message.message_id, "🔴 Unreachable.", get_main_menu_keyboard())
|
| 414 |
|
| 415 |
+
elif data == "menu_help":
|
| 416 |
+
txt = (
|
| 417 |
+
"📖 <b>Commands</b>\n\n"
|
| 418 |
+
"• /start - Main Menu\n• /send - Attack\n• /health - API\n• /delete_history - Clear\n\n"
|
| 419 |
+
"<i>Click buttons below.</i>"
|
| 420 |
+
)
|
| 421 |
+
await safe_edit_message(user_id, cb_query.message.message_id, txt, get_main_menu_keyboard())
|
| 422 |
+
|
| 423 |
+
elif data == "admin_users":
|
| 424 |
+
if not db_user.get("is_admin"): return
|
| 425 |
+
txt = f"👥 <b>Total: {len(USER_DB)}</b>\nBanned: {sum(1 for u in USER_DB.values() if u.get('banned'))}\nVIPs: {sum(1 for u in USER_DB.values() if u.get('is_vip'))}"
|
| 426 |
+
await safe_edit_message(user_id, cb_query.message.message_id, txt, get_admin_menu_keyboard())
|
| 427 |
+
|
| 428 |
+
elif data == "admin_maintenance":
|
| 429 |
+
if not db_user.get("is_admin"): return
|
| 430 |
+
MAINTENANCE_MODE = not MAINTENANCE_MODE
|
| 431 |
+
await safe_edit_message(user_id, cb_query.message.message_id, f"🛠️ Maintenance: {'ON' if MAINTENANCE_MODE else 'OFF'}", get_admin_menu_keyboard())
|
| 432 |
+
|
| 433 |
+
elif data == "admin_stats":
|
| 434 |
+
if not db_user.get("is_admin"): return
|
| 435 |
+
total_req = sum(u.get("stats", {}).get("requests", 0) for u in USER_DB.values())
|
| 436 |
+
total_sent = sum(u.get("stats", {}).get("sent", 0) for u in USER_DB.values())
|
| 437 |
+
txt = f"📊 <b>Global</b>\nAttacks: {total_req}\nMsgs: {total_sent}"
|
| 438 |
+
await safe_edit_message(user_id, cb_query.message.message_id, txt, get_admin_menu_keyboard())
|
| 439 |
+
return
|
| 440 |
|
| 441 |
+
except Exception as e:
|
| 442 |
+
# THIS PRINTS TO THE HF CONSOLE IF ANYTHING FAILS
|
| 443 |
+
print(f"🔥 CRITICAL ERROR: {e}")
|
| 444 |
+
traceback.print_exc()
|
| 445 |
+
try:
|
| 446 |
+
await bot.send_message(chat_id=user_id, text="⚠️ Internal Error. Please try /start again.")
|
| 447 |
+
except: pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
|
| 449 |
# -------------------------------------------------------------------
|
| 450 |
+
# 7. WEBHOOK
|
| 451 |
# -------------------------------------------------------------------
|
| 452 |
async def telegram_webhook(request: Request):
|
| 453 |
try:
|
|
|
|
| 463 |
return JSONResponse({"status": "ok", "bot": "running"})
|
| 464 |
|
| 465 |
# -------------------------------------------------------------------
|
| 466 |
+
# 8. LAUNCH
|
| 467 |
# -------------------------------------------------------------------
|
| 468 |
with gr.Blocks(title="Bot Host") as demo:
|
| 469 |
gr.Markdown("# 🤖 Bot is Running")
|