Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,9 @@ import os
|
|
| 4 |
from flask import Flask, jsonify, make_response, request
|
| 5 |
from supabase import create_client
|
| 6 |
import traceback
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
BOT_TOKEN = "8628213901:AAFvfHBpZ6tok40ZQuhIDLAVIMrHeiheMNY"
|
| 10 |
SUPABASE_URL = "https://yctirvnryrzygoxbpvoy.supabase.co"
|
| 11 |
SUPABASE_KEY = "sb_publishable_aBcD-atruskWwoCiLr0lWw_inT8GLoN"
|
|
@@ -13,6 +14,7 @@ WEB_APP_URL = "https://rony90790.github.io/Forward-bot/index.html"
|
|
| 13 |
HF_SPACE_URL = "https://pmrony-forwardbot.hf.space"
|
| 14 |
|
| 15 |
bot = telebot.TeleBot(BOT_TOKEN)
|
|
|
|
| 16 |
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 17 |
app = Flask(__name__)
|
| 18 |
|
|
@@ -23,8 +25,6 @@ def webhook():
|
|
| 23 |
if request.headers.get('content-type') == 'application/json':
|
| 24 |
json_string = request.get_data().decode('utf-8')
|
| 25 |
update = telebot.types.Update.de_json(json_string)
|
| 26 |
-
# লগ প্রিন্ট হবে যাতে বোঝা যায় মেসেজ এসেছে
|
| 27 |
-
print(f"[LOG] New Update Received: {update.update_id}")
|
| 28 |
bot.process_new_updates([update])
|
| 29 |
return "OK", 200
|
| 30 |
return "Forbidden", 403
|
|
@@ -46,39 +46,43 @@ def index():
|
|
| 46 |
|
| 47 |
@bot.message_handler(commands=['start'])
|
| 48 |
def start(message):
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
try:
|
| 51 |
-
user_id = message.from_user.id
|
| 52 |
args = message.text.split()
|
| 53 |
referrer_id = int(args[1]) if len(args) > 1 and args[1].isdigit() else None
|
| 54 |
|
| 55 |
-
# ডাটাবেজ
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
'
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
markup = InlineKeyboardMarkup()
|
| 72 |
markup.add(InlineKeyboardButton("Play video 🔞", web_app=WebAppInfo(url=WEB_APP_URL)))
|
| 73 |
bot.reply_to(message, "ভাইরাল ভিডিও দেখতে নিচের বাটনে ক্লিক করো 👇", reply_markup=markup)
|
| 74 |
-
|
| 75 |
except Exception as e:
|
| 76 |
-
print(f"[ERROR]
|
| 77 |
traceback.print_exc()
|
| 78 |
|
| 79 |
@bot.message_handler(commands=['png'])
|
| 80 |
def add_png(message):
|
| 81 |
-
print(f"[LOG] /png command received: {message.text}")
|
| 82 |
try:
|
| 83 |
parts = message.text.split(maxsplit=1)
|
| 84 |
if len(parts) > 1:
|
|
@@ -86,17 +90,17 @@ def add_png(message):
|
|
| 86 |
admin_states[message.chat.id] = {"step": 1, "thumbnail_url": img_url}
|
| 87 |
bot.reply_to(message, "✅ ছবি সেট হয়েছে। এখন এই ছবির জন্য **Google Drive ভিডিও লিংক** দিন।")
|
| 88 |
else:
|
| 89 |
-
bot.reply_to(message, "সঠিক নিয়ম: `/png https://
|
| 90 |
except Exception as e:
|
| 91 |
-
print(f"[ERROR]
|
| 92 |
|
| 93 |
@bot.message_handler(func=lambda m: admin_states.get(m.chat.id, {}).get("step") == 1)
|
| 94 |
def add_video_step(message):
|
| 95 |
-
print(f"[LOG] Video link received: {message.text}")
|
| 96 |
try:
|
| 97 |
video_url = message.text.strip()
|
| 98 |
thumbnail_url = admin_states[message.chat.id]["thumbnail_url"]
|
| 99 |
|
|
|
|
| 100 |
supabase.table('videos').insert({
|
| 101 |
"video_url": video_url,
|
| 102 |
"thumbnail_url": thumbnail_url
|
|
@@ -105,16 +109,15 @@ def add_video_step(message):
|
|
| 105 |
bot.reply_to(message, "🎉 অভিনন্দন! ভিডিওটি সফলভাবে অ্যাপে অ্যাড হয়েছে।")
|
| 106 |
admin_states[message.chat.id] = {}
|
| 107 |
except Exception as e:
|
| 108 |
-
print(f"[ERROR]
|
| 109 |
-
bot.reply_to(message, "❌ সেভ করতে সমস্যা হয়েছে।")
|
| 110 |
|
| 111 |
@app.route('/api/videos')
|
| 112 |
def api_videos():
|
| 113 |
try:
|
| 114 |
res = supabase.table('videos').select('*').order('id', desc=True).execute()
|
| 115 |
return jsonify(res.data)
|
| 116 |
-
except
|
| 117 |
-
print(f"[ERROR] API: {e}")
|
| 118 |
return jsonify([])
|
| 119 |
|
| 120 |
if __name__ == "__main__":
|
|
|
|
| 4 |
from flask import Flask, jsonify, make_response, request
|
| 5 |
from supabase import create_client
|
| 6 |
import traceback
|
| 7 |
+
import time
|
| 8 |
|
| 9 |
+
# ডিটেইলস
|
| 10 |
BOT_TOKEN = "8628213901:AAFvfHBpZ6tok40ZQuhIDLAVIMrHeiheMNY"
|
| 11 |
SUPABASE_URL = "https://yctirvnryrzygoxbpvoy.supabase.co"
|
| 12 |
SUPABASE_KEY = "sb_publishable_aBcD-atruskWwoCiLr0lWw_inT8GLoN"
|
|
|
|
| 14 |
HF_SPACE_URL = "https://pmrony-forwardbot.hf.space"
|
| 15 |
|
| 16 |
bot = telebot.TeleBot(BOT_TOKEN)
|
| 17 |
+
# ক্লায়েন্ট ইনিশিয়ালাইজেশন
|
| 18 |
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 19 |
app = Flask(__name__)
|
| 20 |
|
|
|
|
| 25 |
if request.headers.get('content-type') == 'application/json':
|
| 26 |
json_string = request.get_data().decode('utf-8')
|
| 27 |
update = telebot.types.Update.de_json(json_string)
|
|
|
|
|
|
|
| 28 |
bot.process_new_updates([update])
|
| 29 |
return "OK", 200
|
| 30 |
return "Forbidden", 403
|
|
|
|
| 46 |
|
| 47 |
@bot.message_handler(commands=['start'])
|
| 48 |
def start(message):
|
| 49 |
+
user_id = message.from_user.id
|
| 50 |
+
print(f"[LOG] Start command from {user_id}")
|
| 51 |
+
|
| 52 |
try:
|
|
|
|
| 53 |
args = message.text.split()
|
| 54 |
referrer_id = int(args[1]) if len(args) > 1 and args[1].isdigit() else None
|
| 55 |
|
| 56 |
+
# ডাটাবেজ অপারেশন (Try-Except এর ভেতরে রাখা হয়েছে যাতে এরর হলে বট না থামে)
|
| 57 |
+
try:
|
| 58 |
+
user_check = supabase.table('referrals').select('*').eq('user_id', user_id).execute()
|
| 59 |
+
if not user_check.data:
|
| 60 |
+
supabase.table('referrals').insert({
|
| 61 |
+
'user_id': user_id,
|
| 62 |
+
'referral_count': 0,
|
| 63 |
+
'referrer_id': referrer_id if referrer_id != user_id else None
|
| 64 |
+
}).execute()
|
| 65 |
|
| 66 |
+
if referrer_id and referrer_id != user_id:
|
| 67 |
+
ref_data = supabase.table('referrals').select('referral_count').eq('user_id', referrer_id).execute()
|
| 68 |
+
if ref_data.data:
|
| 69 |
+
new_count = ref_data.data[0]['referral_count'] + 1
|
| 70 |
+
supabase.table('referrals').update({'referral_count': new_count}).eq('user_id', referrer_id).execute()
|
| 71 |
+
bot.send_message(referrer_id, "🎉 কেউ আপনার রেফারে জয়েন করেছে!")
|
| 72 |
+
except Exception as db_err:
|
| 73 |
+
print(f"[DB ERROR] {db_err}")
|
| 74 |
+
# ডাটাবেজে এরর হলেও আমরা বটকে রিপ্লাই দিতে দিব
|
| 75 |
|
| 76 |
markup = InlineKeyboardMarkup()
|
| 77 |
markup.add(InlineKeyboardButton("Play video 🔞", web_app=WebAppInfo(url=WEB_APP_URL)))
|
| 78 |
bot.reply_to(message, "ভাইরাল ভিডিও দেখতে নিচের বাটনে ক্লিক করো 👇", reply_markup=markup)
|
| 79 |
+
|
| 80 |
except Exception as e:
|
| 81 |
+
print(f"[CRITICAL ERROR] {e}")
|
| 82 |
traceback.print_exc()
|
| 83 |
|
| 84 |
@bot.message_handler(commands=['png'])
|
| 85 |
def add_png(message):
|
|
|
|
| 86 |
try:
|
| 87 |
parts = message.text.split(maxsplit=1)
|
| 88 |
if len(parts) > 1:
|
|
|
|
| 90 |
admin_states[message.chat.id] = {"step": 1, "thumbnail_url": img_url}
|
| 91 |
bot.reply_to(message, "✅ ছবি সেট হয়েছে। এখন এই ছবির জন্য **Google Drive ভিডিও লিংক** দিন।")
|
| 92 |
else:
|
| 93 |
+
bot.reply_to(message, "সঠিক নিয়ম: `/png https://link-to-image.jpg`")
|
| 94 |
except Exception as e:
|
| 95 |
+
print(f"[ERROR] /png: {e}")
|
| 96 |
|
| 97 |
@bot.message_handler(func=lambda m: admin_states.get(m.chat.id, {}).get("step") == 1)
|
| 98 |
def add_video_step(message):
|
|
|
|
| 99 |
try:
|
| 100 |
video_url = message.text.strip()
|
| 101 |
thumbnail_url = admin_states[message.chat.id]["thumbnail_url"]
|
| 102 |
|
| 103 |
+
# ডাটাবেজে ভিডিও সেভ
|
| 104 |
supabase.table('videos').insert({
|
| 105 |
"video_url": video_url,
|
| 106 |
"thumbnail_url": thumbnail_url
|
|
|
|
| 109 |
bot.reply_to(message, "🎉 অভিনন্দন! ভিডিওটি সফলভাবে অ্যাপে অ্যাড হয়েছে।")
|
| 110 |
admin_states[message.chat.id] = {}
|
| 111 |
except Exception as e:
|
| 112 |
+
print(f"[DB ERROR] Video Insert: {e}")
|
| 113 |
+
bot.reply_to(message, "❌ ডাটাবেজে সেভ করতে সমস্যা হয়েছে। আবার চেষ্টা করুন।")
|
| 114 |
|
| 115 |
@app.route('/api/videos')
|
| 116 |
def api_videos():
|
| 117 |
try:
|
| 118 |
res = supabase.table('videos').select('*').order('id', desc=True).execute()
|
| 119 |
return jsonify(res.data)
|
| 120 |
+
except:
|
|
|
|
| 121 |
return jsonify([])
|
| 122 |
|
| 123 |
if __name__ == "__main__":
|