import telebot from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton, WebAppInfo import os import threading from flask import Flask, jsonify, make_response from supabase import create_client import urllib.request import re BOT_TOKEN = os.environ.get('BOT_TOKEN') SUPABASE_URL = "https://yctirvnryrzygoxbpvoy.supabase.co" SUPABASE_KEY = "sb_publishable_aBcD-atruskWwoCiLr0lWw_inT8GLoN" WEB_APP_URL = "https://rony90790.github.io/Forward-bot/index.html" # ========= আপনার ম্যাজিক সেটিং (এখানেই সব কন্ট্রোল) ========= CHANNEL_USERNAME = "xmlcpg" # আপনার চ্যানেলের ইউজারনেম দিন (t.me/ ছাড়া) START_MESSAGE_ID = 1 # কতো নাম্বার মেসেজ থেকে ভিডিও দেখানো শুরু করবে? (আপনি ১ বলেছেন, তাই ১ দিলাম) TOTAL_VIDEOS = 10 # একসাথে কয়টি ভিডিও অ্যাপে দেখাবে? (যেমন: ১০টি ভিডিও দেখাবে) # ========================================================= bot = telebot.TeleBot(BOT_TOKEN) supabase = create_client(SUPABASE_URL, SUPABASE_KEY) app = Flask(__name__) # টেলিগ্রাম থেকে অটোমেটিক আসল ছবি (thumbnail) বের করার ফাংশন def get_telegram_thumbnail(channel, msg_id): try: url = f"https://t.me/{channel}/{msg_id}?embed=1" req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'}) html = urllib.request.urlopen(req, timeout=3).read().decode('utf-8') match = re.search(r'', html) if match: img_url = match.group(1) # যদি আসল ছবি থাকে তবেই সেটি নেবে if "telegram_logo" not in img_url: return img_url except Exception as e: pass # ছবি না পেলে বা ডিলিট হয়ে গেলে একটি ডেমো ছবি দেখাবে return f"https://via.placeholder.com/150/222222/FF9900?text=Video+{msg_id}" @app.route('/') def index(): return "Bot is Running!" # অ্যাপের জন্য অটোমেটিক ভিডিওর ডেটা পাঠানোর API (১ থেকে শুরু করে লুপ চলবে) @app.route('/api/videos') def api_videos(): videos_data = [] # START_MESSAGE_ID (১) থেকে শুরু করে TOTAL_VIDEOS (১০) পর্যন্ত নিজে নিজে খুঁজবে for msg_id in range(START_MESSAGE_ID, START_MESSAGE_ID + TOTAL_VIDEOS): thumb = get_telegram_thumbnail(CHANNEL_USERNAME, msg_id) videos_data.append({ "video_url": f"https://t.me/{CHANNEL_USERNAME}/{msg_id}", "thumbnail_url": thumb }) response = make_response(jsonify(videos_data)) response.headers['Access-Control-Allow-Origin'] = '*' return response # রেফারেল লজিক (আগের মতোই থাকবে) @bot.message_handler(commands=['start']) def start(message): user_id = message.from_user.id text = message.text.split() referrer_id = None if len(text) > 1: referrer_id = text[1] try: user_check = supabase.table('referrals').select('*').eq('user_id', user_id).execute() if len(user_check.data) == 0: supabase.table('referrals').insert({ 'user_id': user_id, 'referral_count': 0, 'referrer_id': referrer_id if referrer_id != str(user_id) else None }).execute() if referrer_id and referrer_id != str(user_id): referrer_data = supabase.table('referrals').select('referral_count').eq('user_id', referrer_id).execute() if len(referrer_data.data) > 0: new_count = referrer_data.data[0]['referral_count'] + 1 supabase.table('referrals').update({'referral_count': new_count}).eq('user_id', referrer_id).execute() try: bot.send_message(referrer_id, "🎉 একজন আপনার লিংকে জয়েন করেছে! আপনার রেফারেল কাউন্ট বাড়লো।") except Exception as e: print("Message Error:", e) except Exception as e: print("Database Error:", e) markup = InlineKeyboardMarkup() markup.add(InlineKeyboardButton("Play video 🔞", web_app=WebAppInfo(url=WEB_APP_URL))) bot.reply_to(message, "ভাইরাল ভিডিও দেখতে নিচের বাটনে ক্লিক করো 👇", reply_markup=markup) def run_bot(): bot.infinity_polling() if __name__ == "__main__": threading.Thread(target=run_bot).start() app.run(host="0.0.0.0", port=7860)