File size: 10,989 Bytes
fdd3af8 c0768e6 fdd3af8 c0768e6 fdd3af8 c0768e6 fdd3af8 c0768e6 fdd3af8 c0768e6 fdd3af8 c0768e6 fdd3af8 c0768e6 fdd3af8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | 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 "<h1>Bot Ad Server is running perfectly! ✅</h1>"
@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 "<h1>Error: Bot Not Found or Deactivated!</h1>"
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"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Unlock Your File</title>
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<style>
:root {{
--bg-color: var(--tg-theme-secondary-bg-color, #f4f4f5);
--card-bg: var(--tg-theme-bg-color, #ffffff);
--text-main: var(--tg-theme-text-color, #222222);
--text-muted: var(--tg-theme-hint-color, #888888);
--accent-color: var(--tg-theme-button-color, #3390ec);
--accent-text: var(--tg-theme-button-text-color, #ffffff);
--success-color: #34c759;
}}
body {{
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
background-color: var(--bg-color);
color: var(--text-main);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
padding: 20px;
box-sizing: border-box;
}}
.card {{
background-color: var(--card-bg);
width: 100%;
max-width: 400px;
border-radius: 20px;
padding: 40px 25px;
box-sizing: border-box;
box-shadow: 0 10px 30px rgba(0,0,0,0.05);
text-align: center;
animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}}
@keyframes slideUp {{
from {{ transform: translateY(20px); opacity: 0; }}
to {{ transform: translateY(0); opacity: 1; }}
}}
.icon-container {{
width: 70px;
height: 70px;
background: rgba(51, 144, 236, 0.1);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 20px;
color: var(--accent-color);
font-size: 32px;
}}
h2 {{ margin: 0 0 10px; font-size: 24px; font-weight: 700; }}
p.desc {{ color: var(--text-muted); font-size: 15px; line-height: 1.5; margin-bottom: 30px; }}
.btn {{
background-color: var(--accent-color);
color: var(--accent-text);
border: none;
padding: 16px 20px;
border-radius: 14px;
font-size: 17px;
font-weight: 600;
width: 100%;
box-sizing: border-box;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
text-decoration: none;
margin: 0 auto;
box-shadow: 0 4px 15px rgba(51, 144, 236, 0.3);
}}
.loading-state {{ display: none; animation: fadeIn 0.4s ease; }}
@keyframes fadeIn {{ from {{ opacity: 0; }} to {{ opacity: 1; }} }}
.progress-bg {{ background: rgba(51, 144, 236, 0.1); height: 10px; border-radius: 10px; overflow: hidden; margin: 20px 0 10px; }}
.progress-fill {{ background: var(--accent-color); height: 100%; width: 0%; border-radius: 10px; transition: width 1s linear; }}
.timer-text {{ font-size: 16px; font-weight: 600; color: var(--text-main); margin-bottom: 5px; }}
.sub-info {{ font-size: 13px; color: var(--text-muted); }}
.success-state {{ display: none; animation: fadeIn 0.4s ease; }}
.success-icon {{ background: rgba(52, 199, 89, 0.1); color: var(--success-color); }}
.success-text {{ color: var(--success-color); font-weight: 600; font-size: 18px; margin: 10px 0 20px; }}
.btn-success {{ background-color: var(--success-color); box-shadow: 0 4px 15px rgba(52, 199, 89, 0.3); }}
</style>
</head>
<body>
<div class="card" id="mainCard">
<div id="step1">
<div class="icon-container"><i class="fa-solid fa-lock"></i></div>
<h2>File Locked</h2>
<p class="desc">Please tap the button below to view a quick sponsor ad. Your file will unlock automatically in 15 seconds.</p>
<button class="btn" onclick="openAdAndStartTimer()">
<i class="fa-solid fa-play"></i> Watch Ad Now
</button>
</div>
<div id="step2" class="loading-state">
<div class="icon-container" style="animation: pulse 2s infinite;"><i class="fa-solid fa-hourglass-half"></i></div>
<h2 class="timer-text">Unlocking in <span id="countdown">15</span>s</h2>
<div class="progress-bg">
<div class="progress-fill" id="progressBar"></div>
</div>
<p class="sub-info">Ad opened in browser. Please wait here.</p>
</div>
<div id="step3" class="success-state">
<div class="icon-container success-icon"><i class="fa-solid fa-check"></i></div>
<h2>Unlocked!</h2>
<p class="success-text">Your file is ready.</p>
<p class="sub-info" style="margin-bottom: 20px;">If not redirected, tap below.</p>
<a href="#" id="fallbackBtn" class="btn btn-success" onclick="forceCloseAndRedirect()">
<i class="fa-brands fa-telegram"></i> Get My File
</a>
</div>
</div>
<style>
@keyframes pulse {{
0% {{ transform: scale(1); }}
50% {{ transform: scale(1.05); opacity: 0.8; }}
100% {{ transform: scale(1); }}
}}
</style>
<script>
const tg = window.Telegram.WebApp;
tg.expand();
tg.ready();
const botUrl = "https://t.me/{bot_username}?start={payload}";
function openAdAndStartTimer() {{
tg.openLink("{ad_link}");
document.getElementById("step1").style.display = "none";
document.getElementById("step2").style.display = "block";
let timeLeft = 15;
const totalTime = 15;
const progressBar = document.getElementById("progressBar");
const countdownText = document.getElementById("countdown");
let timerInterval = setInterval(function() {{
timeLeft--;
countdownText.innerText = timeLeft;
let percentage = ((totalTime - timeLeft) / totalTime) * 100;
progressBar.style.width = percentage + "%";
if (timeLeft <= 0) {{
clearInterval(timerInterval);
verifyAndSend();
}}
}}, 1000);
}}
function forceCloseAndRedirect() {{
window.location.href = botUrl;
setTimeout(() => {{ tg.close(); }}, 200);
}}
function verifyAndSend() {{
fetch('/api/verify', {{
method: 'POST',
headers: {{ 'Content-Type': 'application/json' }},
body: JSON.stringify({{ bot_id: {bot_id}, user_id: {user_id} }})
}})
.then(res => res.json())
.then(data => {{
if (data.success) {{
document.getElementById("step2").style.display = "none";
document.getElementById("step3").style.display = "block";
document.getElementById("fallbackBtn").href = botUrl;
setTimeout(() => {{
window.location.href = botUrl;
setTimeout(() => {{ tg.close(); }}, 500);
}}, 1500);
}} else {{
alert("Verification failed. Please try again.");
window.location.reload();
}}
}})
.catch(err => {{
alert("Network error. Please make sure you are connected to the internet.");
window.location.reload();
}});
}}
</script>
</body>
</html>
"""
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)
|