Spaces:
Build error
Build error
| 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 = {} | |
| 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 | |
| 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>" | |
| def index(): | |
| return "Bot is Running smoothly!" | |
| # ================= HANDLERS ================= | |
| 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() | |
| 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}") | |
| 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, "❌ ডাটাবেজে সেভ করতে সমস্যা হয়েছে। আবার চেষ্টা করুন।") | |
| 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) |