Spaces:
Build error
Build error
File size: 5,330 Bytes
119d2aa 602c934 119d2aa f11261f 119d2aa f9b8847 f1f8e0e 119d2aa f1f8e0e 10b6ebf 8c80a61 db8a350 119d2aa f1f8e0e 119d2aa 44317b5 db8a350 f11261f db8a350 10b6ebf db8a350 10b6ebf db8a350 f9b8847 f1f8e0e f9b8847 f1f8e0e f9b8847 f1f8e0e f9b8847 f1f8e0e f9b8847 f1f8e0e f9b8847 44317b5 f9b8847 f1f8e0e f9b8847 f1f8e0e 44317b5 f11261f 10b6ebf 44317b5 f9b8847 f1f8e0e 44317b5 f9b8847 10b6ebf f9b8847 44317b5 f1f8e0e d8344cf 44317b5 f11261f f1f8e0e f11261f d8344cf 119d2aa f11261f | 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 | import telebot
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton, WebAppInfo
import os
from flask import Flask, jsonify, make_response, request
from supabase import create_client
import traceback
import time
# ডিটেইলস
BOT_TOKEN = "8628213901:AAFvfHBpZ6tok40ZQuhIDLAVIMrHeiheMNY"
SUPABASE_URL = "https://yctirvnryrzygoxbpvoy.supabase.co"
SUPABASE_KEY = "sb_publishable_aBcD-atruskWwoCiLr0lWw_inT8GLoN"
WEB_APP_URL = "https://rony90790.github.io/Forward-bot/index.html"
HF_SPACE_URL = "https://pmrony-forwardbot.hf.space"
bot = telebot.TeleBot(BOT_TOKEN)
# ক্লায়েন্ট ইনিশিয়ালাইজেশন
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
app = Flask(__name__)
admin_states = {}
@app.route(f'/{BOT_TOKEN}', methods=['POST'])
def webhook():
if request.headers.get('content-type') == 'application/json':
json_string = request.get_data().decode('utf-8')
update = telebot.types.Update.de_json(json_string)
bot.process_new_updates([update])
return "OK", 200
return "Forbidden", 403
@app.route('/set_webhook')
def set_webhook():
bot.remove_webhook()
success = bot.set_webhook(url=f"{HF_SPACE_URL}/{BOT_TOKEN}")
if success:
return "<h1>✅ Webhook Set Successfully!</h1>"
else:
return "<h1>❌ Webhook Set Failed!</h1>"
@app.route('/')
def index():
return "Bot is Running smoothly!"
# ================= HANDLERS =================
@bot.message_handler(commands=['start'])
def start(message):
user_id = message.from_user.id
print(f"[LOG] Start command from {user_id}")
try:
args = message.text.split()
referrer_id = int(args[1]) if len(args) > 1 and args[1].isdigit() else None
# ডাটাবেজ অপারেশন (Try-Except এর ভেতরে রাখা হয়েছে যাতে এরর হলে বট না থামে)
try:
user_check = supabase.table('referrals').select('*').eq('user_id', user_id).execute()
if not user_check.data:
supabase.table('referrals').insert({
'user_id': user_id,
'referral_count': 0,
'referrer_id': referrer_id if referrer_id != user_id else None
}).execute()
if referrer_id and referrer_id != user_id:
ref_data = supabase.table('referrals').select('referral_count').eq('user_id', referrer_id).execute()
if ref_data.data:
new_count = ref_data.data[0]['referral_count'] + 1
supabase.table('referrals').update({'referral_count': new_count}).eq('user_id', referrer_id).execute()
bot.send_message(referrer_id, "🎉 কেউ আপনার রেফারে জয়েন করেছে!")
except Exception as db_err:
print(f"[DB ERROR] {db_err}")
# ডাটাবেজে এরর হলেও আমরা বটকে রিপ্লাই দিতে দিব
markup = InlineKeyboardMarkup()
markup.add(InlineKeyboardButton("Play video 🔞", web_app=WebAppInfo(url=WEB_APP_URL)))
bot.reply_to(message, "ভাইরাল ভিডিও দেখতে নিচের বাটনে ক্লিক করো 👇", reply_markup=markup)
except Exception as e:
print(f"[CRITICAL ERROR] {e}")
traceback.print_exc()
@bot.message_handler(commands=['png'])
def add_png(message):
try:
parts = message.text.split(maxsplit=1)
if len(parts) > 1:
img_url = parts[1].strip()
admin_states[message.chat.id] = {"step": 1, "thumbnail_url": img_url}
bot.reply_to(message, "✅ ছবি সেট হয়েছে। এখন এই ছবির জন্য **Google Drive ভিডিও লিংক** দিন।")
else:
bot.reply_to(message, "সঠিক নিয়ম: `/png https://link-to-image.jpg`")
except Exception as e:
print(f"[ERROR] /png: {e}")
@bot.message_handler(func=lambda m: admin_states.get(m.chat.id, {}).get("step") == 1)
def add_video_step(message):
try:
video_url = message.text.strip()
thumbnail_url = admin_states[message.chat.id]["thumbnail_url"]
# ডাটাবেজে ভিডিও সেভ
supabase.table('videos').insert({
"video_url": video_url,
"thumbnail_url": thumbnail_url
}).execute()
bot.reply_to(message, "🎉 অভিনন্দন! ভিডিওটি সফলভাবে অ্যাপে অ্যাড হয়েছে।")
admin_states[message.chat.id] = {}
except Exception as e:
print(f"[DB ERROR] Video Insert: {e}")
bot.reply_to(message, "❌ ডাটাবেজে সেভ করতে সমস্যা হয়েছে। আবার চেষ্টা করুন।")
@app.route('/api/videos')
def api_videos():
try:
res = supabase.table('videos').select('*').order('id', desc=True).execute()
return jsonify(res.data)
except:
return jsonify([])
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860) |