from flask import Flask, request, jsonify import asyncio import time import os from motor.motor_asyncio import AsyncIOMotorClient app = Flask(__name__) # Hugging Face Secrets se securely URI fetch karega MONGO_URI = os.environ.get("MONGO_URI") @app.route('/') def home(): return "

Bot Ad Server is running perfectly! ✅

" @app.route('/watch') def watch_ad_page(): bot_id = request.args.get('bot_id', type=int) user_id = request.args.get('user_id', type=int) payload = request.args.get('payload', type=str) async def get_clone_data(): client = AsyncIOMotorClient(MONGO_URI) db = client['FileStoreBot'] clone_data = await db['clones'].find_one({"bot_id": bot_id}) client.close() return clone_data clone = asyncio.run(get_clone_data()) if not clone: return "

Error: Bot Not Found or Deactivated!

" settings = clone.get("settings", {}) ad_data = settings.get("watch_ad", {}) ad_link = ad_data.get("ad_link", "#") bot_username = clone.get("username", "") html_content = f""" Unlock Your File

File Locked

Please tap the button below to view a quick sponsor ad. Your file will unlock automatically in 15 seconds.

Unlocking in 15s

Ad opened in browser. Please wait here.

Unlocked!

Your file is ready.

If not redirected, tap below.

Get My File
""" return html_content @app.route('/api/verify', methods=['POST']) def api_verify(): try: data = request.json bot_id = int(data.get('bot_id')) user_id = int(data.get('user_id')) async def verify_user(): client = AsyncIOMotorClient(MONGO_URI) db = client['FileStoreBot'] await db['clone_users'].update_one( {"bot_id": bot_id, "user_id": user_id}, {"$set": {"last_ad_watched": time.time()}}, upsert=True ) client.close() asyncio.run(verify_user()) return jsonify({"success": True}) except Exception as e: print(f"Verify API Error: {e}") return jsonify({"success": False, "error": str(e)}) if __name__ == "__main__": app.run(host="0.0.0.0", port=7860)