Update app.py
Browse files
app.py
CHANGED
|
@@ -39,12 +39,10 @@ API_HEALTH = "https://costum-boomber-api.vercel.app/api/health"
|
|
| 39 |
|
| 40 |
bot = Bot(token=BOT_TOKEN)
|
| 41 |
|
| 42 |
-
# In-Memory Database
|
| 43 |
USER_DB = {}
|
| 44 |
seen_users = set()
|
| 45 |
MAINTENANCE_MODE = False
|
| 46 |
|
| 47 |
-
# Bot States
|
| 48 |
ASK_NUMBER, ASK_MESSAGE, ASK_COUNT = range(3)
|
| 49 |
WAITING_FOR_ADMIN_PASS = 99
|
| 50 |
|
|
@@ -70,7 +68,7 @@ async def check_channel_membership(user_id: int) -> bool:
|
|
| 70 |
return member.status not in ['left', 'kicked', 'restricted']
|
| 71 |
except Exception as e:
|
| 72 |
print(f"Channel check error: {e}")
|
| 73 |
-
return True
|
| 74 |
|
| 75 |
def get_disclaimer_keyboard():
|
| 76 |
return InlineKeyboardMarkup([
|
|
@@ -124,7 +122,6 @@ async def process_update(update: Update):
|
|
| 124 |
msg = update.message
|
| 125 |
cb_query = update.callback_query
|
| 126 |
|
| 127 |
-
# Initialize User
|
| 128 |
if user_id not in USER_DB:
|
| 129 |
USER_DB[user_id] = {
|
| 130 |
"accepted": False, "verified": False, "state": None, "is_admin": False,
|
|
@@ -158,13 +155,21 @@ async def process_update(update: Update):
|
|
| 158 |
)
|
| 159 |
return
|
| 160 |
|
| 161 |
-
# 2. Handle /admin
|
| 162 |
-
if msg and msg.text and msg.text.
|
| 163 |
USER_DB[user_id]["state"] = WAITING_FOR_ADMIN_PASS
|
| 164 |
-
await bot.send_message(chat_id=user_id, text="🔐 <b>Admin Login</b>\nPlease enter the password:")
|
| 165 |
return
|
| 166 |
|
| 167 |
-
# 3. Handle /
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
if msg and msg.text and msg.text.startswith("/send"):
|
| 169 |
if not USER_DB[user_id]["accepted"] or not USER_DB[user_id]["verified"]:
|
| 170 |
await bot.send_message(chat_id=user_id, text="❌ You must /start and verify first.")
|
|
@@ -177,12 +182,12 @@ async def process_update(update: Update):
|
|
| 177 |
await bot.send_message(chat_id=user_id, text="📱 Enter the 10-digit target phone number:", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("❌ Cancel", callback_data="menu_main")]]))
|
| 178 |
return
|
| 179 |
|
| 180 |
-
#
|
| 181 |
if msg and msg.text and USER_DB[user_id].get("state") is not None:
|
| 182 |
state = USER_DB[user_id]["state"]
|
| 183 |
|
| 184 |
if state == WAITING_FOR_ADMIN_PASS:
|
| 185 |
-
if msg.text == ADMIN_PASSWORD:
|
| 186 |
USER_DB[user_id]["is_admin"] = True
|
| 187 |
USER_DB[user_id]["state"] = None
|
| 188 |
await bot.send_message(chat_id=user_id, text="✅ <b>Admin Mode Enabled!</b>\nUse /admin_panel to see options.", parse_mode="HTML")
|
|
@@ -228,7 +233,6 @@ async def process_update(update: Update):
|
|
| 228 |
data = resp.json()
|
| 229 |
if resp.status_code == 200 and data.get("ok"):
|
| 230 |
sent = data.get('sent', 0)
|
| 231 |
-
# Update Stats
|
| 232 |
USER_DB[user_id]["stats"]["requests"] += 1
|
| 233 |
USER_DB[user_id]["stats"]["sent"] += sent
|
| 234 |
|
|
@@ -249,12 +253,6 @@ async def process_update(update: Update):
|
|
| 249 |
USER_DB[user_id]["state"] = None
|
| 250 |
return
|
| 251 |
|
| 252 |
-
# 5. Handle /admin_panel command
|
| 253 |
-
if msg and msg.text and msg.text.startswith("/admin_panel"):
|
| 254 |
-
if USER_DB[user_id].get("is_admin"):
|
| 255 |
-
await bot.send_message(chat_id=user_id, text="👑 <b>Admin Dashboard</b>", parse_mode="HTML", reply_markup=get_admin_menu_keyboard())
|
| 256 |
-
return
|
| 257 |
-
|
| 258 |
# 6. Handle Callbacks (Menu & Inline Buttons)
|
| 259 |
if cb_query:
|
| 260 |
try:
|
|
@@ -264,7 +262,6 @@ async def process_update(update: Update):
|
|
| 264 |
|
| 265 |
data = cb_query.data
|
| 266 |
|
| 267 |
-
# --- Disclaimer & Join ---
|
| 268 |
if data == "check_join":
|
| 269 |
is_member = await check_channel_membership(user_id)
|
| 270 |
if is_member:
|
|
@@ -284,7 +281,6 @@ async def process_update(update: Update):
|
|
| 284 |
elif data == "decline_disclaimer":
|
| 285 |
await safe_edit_message(user_id, cb_query.message.message_id, "❌ Declined.")
|
| 286 |
|
| 287 |
-
# --- Main Menu ---
|
| 288 |
elif data == "menu_main":
|
| 289 |
await safe_edit_message(user_id, cb_query.message.message_id, "👋 <b>Main Menu</b>\nPlease select an option:", get_main_menu_keyboard())
|
| 290 |
|
|
@@ -325,7 +321,6 @@ async def process_update(update: Update):
|
|
| 325 |
)
|
| 326 |
await safe_edit_message(user_id, cb_query.message.message_id, text, get_main_menu_keyboard())
|
| 327 |
|
| 328 |
-
# --- Admin Menu ---
|
| 329 |
elif data == "admin_users":
|
| 330 |
if not USER_DB[user_id].get("is_admin"): return
|
| 331 |
total = len(USER_DB)
|
|
|
|
| 39 |
|
| 40 |
bot = Bot(token=BOT_TOKEN)
|
| 41 |
|
|
|
|
| 42 |
USER_DB = {}
|
| 43 |
seen_users = set()
|
| 44 |
MAINTENANCE_MODE = False
|
| 45 |
|
|
|
|
| 46 |
ASK_NUMBER, ASK_MESSAGE, ASK_COUNT = range(3)
|
| 47 |
WAITING_FOR_ADMIN_PASS = 99
|
| 48 |
|
|
|
|
| 68 |
return member.status not in ['left', 'kicked', 'restricted']
|
| 69 |
except Exception as e:
|
| 70 |
print(f"Channel check error: {e}")
|
| 71 |
+
return True
|
| 72 |
|
| 73 |
def get_disclaimer_keyboard():
|
| 74 |
return InlineKeyboardMarkup([
|
|
|
|
| 122 |
msg = update.message
|
| 123 |
cb_query = update.callback_query
|
| 124 |
|
|
|
|
| 125 |
if user_id not in USER_DB:
|
| 126 |
USER_DB[user_id] = {
|
| 127 |
"accepted": False, "verified": False, "state": None, "is_admin": False,
|
|
|
|
| 155 |
)
|
| 156 |
return
|
| 157 |
|
| 158 |
+
# 2. Handle /admin (Exact Match Only)
|
| 159 |
+
if msg and msg.text and msg.text.strip() == "/admin":
|
| 160 |
USER_DB[user_id]["state"] = WAITING_FOR_ADMIN_PASS
|
| 161 |
+
await bot.send_message(chat_id=user_id, text="🔐 <b>Admin Login</b>\nPlease enter the password:", parse_mode="HTML")
|
| 162 |
return
|
| 163 |
|
| 164 |
+
# 3. Handle /admin_panel (Exact Match Only)
|
| 165 |
+
if msg and msg.text and msg.text.strip() == "/admin_panel":
|
| 166 |
+
if USER_DB[user_id].get("is_admin"):
|
| 167 |
+
await bot.send_message(chat_id=user_id, text="👑 <b>Admin Dashboard</b>\nWelcome back, Admin.", parse_mode="HTML", reply_markup=get_admin_menu_keyboard())
|
| 168 |
+
else:
|
| 169 |
+
await bot.send_message(chat_id=user_id, text="⛔ You are not logged in. Type /admin to login.")
|
| 170 |
+
return
|
| 171 |
+
|
| 172 |
+
# 4. Handle /send (Shortcut)
|
| 173 |
if msg and msg.text and msg.text.startswith("/send"):
|
| 174 |
if not USER_DB[user_id]["accepted"] or not USER_DB[user_id]["verified"]:
|
| 175 |
await bot.send_message(chat_id=user_id, text="❌ You must /start and verify first.")
|
|
|
|
| 182 |
await bot.send_message(chat_id=user_id, text="📱 Enter the 10-digit target phone number:", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("❌ Cancel", callback_data="menu_main")]]))
|
| 183 |
return
|
| 184 |
|
| 185 |
+
# 5. Handle Text Inputs Based on State
|
| 186 |
if msg and msg.text and USER_DB[user_id].get("state") is not None:
|
| 187 |
state = USER_DB[user_id]["state"]
|
| 188 |
|
| 189 |
if state == WAITING_FOR_ADMIN_PASS:
|
| 190 |
+
if msg.text.strip() == ADMIN_PASSWORD:
|
| 191 |
USER_DB[user_id]["is_admin"] = True
|
| 192 |
USER_DB[user_id]["state"] = None
|
| 193 |
await bot.send_message(chat_id=user_id, text="✅ <b>Admin Mode Enabled!</b>\nUse /admin_panel to see options.", parse_mode="HTML")
|
|
|
|
| 233 |
data = resp.json()
|
| 234 |
if resp.status_code == 200 and data.get("ok"):
|
| 235 |
sent = data.get('sent', 0)
|
|
|
|
| 236 |
USER_DB[user_id]["stats"]["requests"] += 1
|
| 237 |
USER_DB[user_id]["stats"]["sent"] += sent
|
| 238 |
|
|
|
|
| 253 |
USER_DB[user_id]["state"] = None
|
| 254 |
return
|
| 255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
# 6. Handle Callbacks (Menu & Inline Buttons)
|
| 257 |
if cb_query:
|
| 258 |
try:
|
|
|
|
| 262 |
|
| 263 |
data = cb_query.data
|
| 264 |
|
|
|
|
| 265 |
if data == "check_join":
|
| 266 |
is_member = await check_channel_membership(user_id)
|
| 267 |
if is_member:
|
|
|
|
| 281 |
elif data == "decline_disclaimer":
|
| 282 |
await safe_edit_message(user_id, cb_query.message.message_id, "❌ Declined.")
|
| 283 |
|
|
|
|
| 284 |
elif data == "menu_main":
|
| 285 |
await safe_edit_message(user_id, cb_query.message.message_id, "👋 <b>Main Menu</b>\nPlease select an option:", get_main_menu_keyboard())
|
| 286 |
|
|
|
|
| 321 |
)
|
| 322 |
await safe_edit_message(user_id, cb_query.message.message_id, text, get_main_menu_keyboard())
|
| 323 |
|
|
|
|
| 324 |
elif data == "admin_users":
|
| 325 |
if not USER_DB[user_id].get("is_admin"): return
|
| 326 |
total = len(USER_DB)
|