Spaces:
Sleeping
Sleeping
Update bot.py
Browse files
bot.py
CHANGED
|
@@ -178,10 +178,30 @@ async def unban(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
| 178 |
try: user_id=int(context.args[0]); await bans_col.delete_one({"user_id":user_id}); await update.message.reply_text(f"Unbanned {user_id}")
|
| 179 |
except: await update.message.reply_text("Provide user ID")
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
# --- Main ---
|
| 182 |
async def main():
|
| 183 |
await init_stats()
|
| 184 |
app = Application.builder().token(BOT_TOKEN).build()
|
|
|
|
|
|
|
| 185 |
app.add_handler(CommandHandler("start", start))
|
| 186 |
app.add_handler(CommandHandler("encode", encode))
|
| 187 |
app.add_handler(MessageHandler(filters.Document.ALL, handle_document))
|
|
@@ -191,11 +211,14 @@ async def main():
|
|
| 191 |
app.add_handler(CommandHandler("ban", ban))
|
| 192 |
app.add_handler(CommandHandler("unban", unban))
|
| 193 |
|
| 194 |
-
#
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
| 197 |
await app.run_polling()
|
| 198 |
|
|
|
|
| 199 |
# --- Run Bot ---
|
| 200 |
if __name__ == "__main__":
|
| 201 |
import asyncio
|
|
|
|
| 178 |
try: user_id=int(context.args[0]); await bans_col.delete_one({"user_id":user_id}); await update.message.reply_text(f"Unbanned {user_id}")
|
| 179 |
except: await update.message.reply_text("Provide user ID")
|
| 180 |
|
| 181 |
+
async def notify_admin(bot):
|
| 182 |
+
"""Send bot_started message safely with retries."""
|
| 183 |
+
import asyncio
|
| 184 |
+
import httpx
|
| 185 |
+
max_retries = 5
|
| 186 |
+
delay = 5 # seconds
|
| 187 |
+
for i in range(max_retries):
|
| 188 |
+
try:
|
| 189 |
+
await bot.send_message(chat_id=ADMIN_ID, text='{"status":"bot_started"}')
|
| 190 |
+
print("✅ Bot started message sent to admin")
|
| 191 |
+
break
|
| 192 |
+
except httpx.ConnectError as e:
|
| 193 |
+
print(f"⚠ Network error on attempt {i+1}: {e}. Retrying in {delay}s...")
|
| 194 |
+
await asyncio.sleep(delay)
|
| 195 |
+
except Exception as e:
|
| 196 |
+
print(f"⚠ Failed to send bot_started message: {e}")
|
| 197 |
+
break
|
| 198 |
+
|
| 199 |
# --- Main ---
|
| 200 |
async def main():
|
| 201 |
await init_stats()
|
| 202 |
app = Application.builder().token(BOT_TOKEN).build()
|
| 203 |
+
|
| 204 |
+
# --- Handlers ---
|
| 205 |
app.add_handler(CommandHandler("start", start))
|
| 206 |
app.add_handler(CommandHandler("encode", encode))
|
| 207 |
app.add_handler(MessageHandler(filters.Document.ALL, handle_document))
|
|
|
|
| 211 |
app.add_handler(CommandHandler("ban", ban))
|
| 212 |
app.add_handler(CommandHandler("unban", unban))
|
| 213 |
|
| 214 |
+
# --- Send bot_started safely ---
|
| 215 |
+
import asyncio
|
| 216 |
+
asyncio.create_task(notify_admin(app.bot))
|
| 217 |
+
|
| 218 |
+
# --- Start polling ---
|
| 219 |
await app.run_polling()
|
| 220 |
|
| 221 |
+
|
| 222 |
# --- Run Bot ---
|
| 223 |
if __name__ == "__main__":
|
| 224 |
import asyncio
|