Spaces:
Sleeping
Sleeping
File size: 4,609 Bytes
a91735c 17ca108 216ad4d a91735c bcc7a75 a91735c 17ca108 a91735c cfc4860 216ad4d 17ca108 216ad4d 17ca108 216ad4d bcc7a75 216ad4d bcc7a75 216ad4d 17ca108 bcc7a75 216ad4d bcc7a75 cfc4860 bcc7a75 cfc4860 a91735c 216ad4d 17ca108 bcc7a75 17ca108 bcc7a75 216ad4d 17ca108 216ad4d bcc7a75 17ca108 a91735c 216ad4d a91735c | 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 | import asyncio
import sqlite3
import uvicorn
from fastapi import FastAPI
from aiogram import Bot, Dispatcher, types, F
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, WebAppInfo
from datetime import datetime
app = FastAPI()
# --- 1. إعدادات المربع الذهبي (The Golden Square Config) ---
BOTS_CONFIG = [
{"name": "DooVoo 1", "token": "8628327909:AAETtkAFrUYUMwBhpv3BWsTWH09-fErd8WM", "block_id": "26019"},
{"name": "DooVoo 2", "token": "8560559090:AAE_3s0huP67ciyYFtZj8DZfXrrYNXpp89Q", "block_id": "26019"},
{"name": "DooVoo 3", "token": "8645395608:AAHqU7rNc4WhGDixx8ueL9bdylLw6u57vpg", "block_id": "26019"},
{"name": "DooVoo 4", "token": "8675940898:AAH_6LtNk1ZABExeV7XxXl4xM2DLFxA4Tcc", "block_id": "26019"}
]
# --- 2. قاعدة البيانات المركزية (Unified Database) ---
def init_db():
conn = sqlite3.connect('doovoo_network.db')
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS users
(user_id TEXT PRIMARY KEY, username TEXT, ad_views INTEGER DEFAULT 0, joined_at TEXT)''')
conn.commit()
conn.close()
init_db()
# --- 3. وظيفة تشغيل البوتات (Bot Engine) ---
async def start_single_bot(config):
bot = Bot(token=config['token'])
dp = Dispatcher()
# أ) الأمر /start
@dp.message(F.text == "/start")
async def handle_start(message: types.Message):
user_id = str(message.from_user.id)
username = message.from_user.username or "User"
conn = sqlite3.connect('doovoo_network.db')
c = conn.cursor()
c.execute("INSERT OR IGNORE INTO users (user_id, username, joined_at) VALUES (?, ?, ?)",
(user_id, username, datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
conn.commit()
conn.close()
url = f"https://render.adsgram.ai/show?blockId={config['block_id']}&userId={user_id}"
kb = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text="💰 Watch Ad & Earn", web_app=WebAppInfo(url=url))],
[InlineKeyboardButton(text="📊 My Stats", callback_data="check_stats")]
])
await message.answer(
f"🚀 مرحباً بك في {config['name']}!\n\n"
f"كليكي على الزر باش تتفرج وتربح. "
f"نقاطك غتبان هنا بمجرد ما تبدا المشاهدة!",
reply_markup=kb
)
# ب) معالجة زر "My Stats" (اللي قلتي ماخداماش)
@dp.callback_query(F.data == "check_stats")
async def process_stats(callback_query: types.CallbackQuery):
user_id = str(callback_query.from_user.id)
conn = sqlite3.connect('doovoo_network.db')
c = conn.cursor()
c.execute("SELECT ad_views FROM users WHERE user_id = ?", (user_id,))
result = c.fetchone()
conn.close()
views = result[0] if result else 0
await callback_query.answer() # تحييد حالة الانتظار في التليغرام
await callback_query.message.answer(
f"📊 إحصائياتك في DooVoo Network:\n\n"
f"📺 عدد المشاهدات: {views}\n"
f"⏳ حالة الحساب: في انتظار تفعيل الإعلانات..."
)
print(f"✅ Bot {config['name']} is LIVE!")
try:
await dp.start_polling(bot)
except Exception as e:
print(f"❌ Error in {config['name']}: {e}")
# --- 4. الـ Reward API (الرابط اللي كيعلمنا أن الإعلان تشاف) ---
@app.get("/reward")
async def reward_user(userId: str):
conn = sqlite3.connect('doovoo_network.db')
c = conn.cursor()
c.execute("UPDATE users SET ad_views = ad_views + 1 WHERE user_id = ?", (userId,))
conn.commit()
conn.close()
return {"status": "success", "msg": "Reward added!"}
# --- 5. لوحة التحكم المركزية (Admin Dashboard) ---
@app.get("/admin/network")
async def get_network_stats():
conn = sqlite3.connect('doovoo_network.db')
c = conn.cursor()
c.execute("SELECT COUNT(*), SUM(ad_views) FROM users")
total_users, total_views = c.fetchone()
conn.close()
return {
"active_bots": len(BOTS_CONFIG),
"total_users": total_users,
"total_views": total_views or 0
}
@app.on_event("startup")
async def on_startup():
for config in BOTS_CONFIG:
asyncio.create_task(start_single_bot(config))
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=7860) |