pmrony commited on
Commit
10b6ebf
·
verified ·
1 Parent(s): f11261f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -27
app.py CHANGED
@@ -4,21 +4,18 @@ import os
4
  from flask import Flask, jsonify, make_response, request
5
  from supabase import create_client
6
 
7
- # টোকে
8
- BOT_TOKEN = os.environ.get('BOT_TOKEN')
9
  SUPABASE_URL = "https://yctirvnryrzygoxbpvoy.supabase.co"
10
  SUPABASE_KEY = "sb_publishable_aBcD-atruskWwoCiLr0lWw_inT8GLoN"
11
  WEB_APP_URL = "https://rony90790.github.io/Forward-bot/index.html"
12
  HF_SPACE_URL = "https://pmrony-forwardbot.hf.space"
13
 
14
- if not BOT_TOKEN:
15
- print("Error: BOT_TOKEN not found in environment variables!")
16
-
17
  bot = telebot.TeleBot(BOT_TOKEN)
18
  supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
19
  app = Flask(__name__)
20
 
21
- # অ্যাডমিন স্েট
22
  admin_states = {}
23
 
24
  @app.route(f'/{BOT_TOKEN}', methods=['POST'])
@@ -32,20 +29,16 @@ def webhook():
32
 
33
  @app.route('/set_webhook')
34
  def set_webhook():
35
- try:
36
- bot.remove_webhook()
37
- webhook_url = f"{HF_SPACE_URL}/{BOT_TOKEN}"
38
- success = bot.set_webhook(url=webhook_url)
39
- if success:
40
- return f"<h1> Webhook Set Successfully!</h1><p>URL: {webhook_url}</p>"
41
- else:
42
- return "<h1>❌ Webhook Set Failed!</h1>"
43
- except Exception as e:
44
- return f"<h1>❌ Error:</h1><p>{str(e)}</p>"
45
 
46
  @app.route('/')
47
  def index():
48
- return "Bot is Running!"
49
 
50
  # ================= ADMIN LOGIC =================
51
 
@@ -54,32 +47,36 @@ def add_png(message):
54
  parts = message.text.split(maxsplit=1)
55
  if len(parts) > 1:
56
  img_url = parts[1].strip()
 
57
  admin_states[message.chat.id] = {"step": 1, "thumbnail_url": img_url}
58
- bot.reply_to(message, "✅ ছবি সেট হয়েছে। এখন িডিওর Google Drive লিংক দিন।")
59
  else:
60
- bot.reply_to(message, "সঠিক নিয়ম: `/png https://link-to-image.jpg`")
61
 
62
  @bot.message_handler(func=lambda m: admin_states.get(m.chat.id, {}).get("step") == 1)
63
- def add_video(message):
64
  video_url = message.text.strip()
65
  thumbnail_url = admin_states[message.chat.id]["thumbnail_url"]
66
 
67
  try:
 
68
  supabase.table('videos').insert({
69
  "video_url": video_url,
70
  "thumbnail_url": thumbnail_url
71
  }).execute()
72
- bot.reply_to(message, "🎉 সফলভাবে ভিডিও অ্যাড হয়েছে!")
73
  except Exception as e:
74
- bot.reply_to(message, f"❌ ভুল হয়েছে: {e}")
75
 
 
76
  admin_states[message.chat.id] = {}
77
 
78
- # ================= API =================
79
 
80
  @app.route('/api/videos')
81
  def api_videos():
82
  try:
 
83
  res = supabase.table('videos').select('*').order('id', desc=True).execute()
84
  return jsonify(res.data)
85
  except:
@@ -97,20 +94,22 @@ def start(message):
97
  user_check = supabase.table('referrals').select('*').eq('user_id', user_id).execute()
98
  if not user_check.data:
99
  supabase.table('referrals').insert({
100
- 'user_id': user_id, 'referral_count': 0,
 
101
  'referrer_id': referrer_id if referrer_id != user_id else None
102
  }).execute()
103
 
104
  if referrer_id and referrer_id != user_id:
105
  ref_data = supabase.table('referrals').select('referral_count').eq('user_id', referrer_id).execute()
106
  if ref_data.data:
107
- supabase.table('referrals').update({'referral_count': ref_data.data[0]['referral_count'] + 1}).eq('user_id', referrer_id).execute()
108
- bot.send_message(referrer_id, "🎁 কেউ আপনার ল���ঙ্কে জয়েন করেছে!")
 
109
  except: pass
110
 
111
  markup = InlineKeyboardMarkup()
112
  markup.add(InlineKeyboardButton("Play video 🔞", web_app=WebAppInfo(url=WEB_APP_URL)))
113
- bot.reply_to(message, "ভিডিও দেখতে নিচের বাটনে ক্লিক করুন 👇", reply_markup=markup)
114
 
115
  if __name__ == "__main__":
116
  app.run(host="0.0.0.0", port=7860)
 
4
  from flask import Flask, jsonify, make_response, request
5
  from supabase import create_client
6
 
7
+ # আপার ওয়া ডিটেইলস
8
+ BOT_TOKEN = "8628213901:AAFvfHBpZ6tok40ZQuhIDLAVIMrHeiheMNY"
9
  SUPABASE_URL = "https://yctirvnryrzygoxbpvoy.supabase.co"
10
  SUPABASE_KEY = "sb_publishable_aBcD-atruskWwoCiLr0lWw_inT8GLoN"
11
  WEB_APP_URL = "https://rony90790.github.io/Forward-bot/index.html"
12
  HF_SPACE_URL = "https://pmrony-forwardbot.hf.space"
13
 
 
 
 
14
  bot = telebot.TeleBot(BOT_TOKEN)
15
  supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
16
  app = Flask(__name__)
17
 
18
+ # অ্যাডমিন ডাা রাখার জন্য
19
  admin_states = {}
20
 
21
  @app.route(f'/{BOT_TOKEN}', methods=['POST'])
 
29
 
30
  @app.route('/set_webhook')
31
  def set_webhook():
32
+ bot.remove_webhook()
33
+ success = bot.set_webhook(url=f"{HF_SPACE_URL}/{BOT_TOKEN}")
34
+ if success:
35
+ return "<h1>✅ Webhook Set Successfully!</h1>"
36
+ else:
37
+ return "<h1> Webhook Set Failed!</h1>"
 
 
 
 
38
 
39
  @app.route('/')
40
  def index():
41
+ return "Bot is Running smoothly!"
42
 
43
  # ================= ADMIN LOGIC =================
44
 
 
47
  parts = message.text.split(maxsplit=1)
48
  if len(parts) > 1:
49
  img_url = parts[1].strip()
50
+ # ছবির লিংক সেভ করে রাখলাম এবং ভিডিওর লিংক চাইলাম
51
  admin_states[message.chat.id] = {"step": 1, "thumbnail_url": img_url}
52
+ bot.reply_to(message, "✅ ছবি সেট হয়েছে। এখন এই ছবির জন্য **Google Drive ভিডিও লিংক** দিন।")
53
  else:
54
+ bot.reply_to(message, "সঠিক নিয়ম: `/png https://i.postimg.cc/image.jpg` (ছবির ডিরেক্ট লিংক দিবেন)")
55
 
56
  @bot.message_handler(func=lambda m: admin_states.get(m.chat.id, {}).get("step") == 1)
57
+ def add_video_step(message):
58
  video_url = message.text.strip()
59
  thumbnail_url = admin_states[message.chat.id]["thumbnail_url"]
60
 
61
  try:
62
+ # Supabase 'videos' টেবিলে ডাটা সেভ
63
  supabase.table('videos').insert({
64
  "video_url": video_url,
65
  "thumbnail_url": thumbnail_url
66
  }).execute()
67
+ bot.reply_to(message, "🎉 অভিনন্দন! ভিডিওটি সফলভাবে অ্যাপে অ্যাড হয়েছে")
68
  except Exception as e:
69
+ bot.reply_to(message, f"❌ সেকরতে সমস্যা হয়েছে: {e}")
70
 
71
+ # স্টেট ক্লিয়ার
72
  admin_states[message.chat.id] = {}
73
 
74
+ # ================= API FOR MINI APP =================
75
 
76
  @app.route('/api/videos')
77
  def api_videos():
78
  try:
79
+ # ডাটাবেজ থেকে সব ভিডিও আনা হচ্ছে
80
  res = supabase.table('videos').select('*').order('id', desc=True).execute()
81
  return jsonify(res.data)
82
  except:
 
94
  user_check = supabase.table('referrals').select('*').eq('user_id', user_id).execute()
95
  if not user_check.data:
96
  supabase.table('referrals').insert({
97
+ 'user_id': user_id,
98
+ 'referral_count': 0,
99
  'referrer_id': referrer_id if referrer_id != user_id else None
100
  }).execute()
101
 
102
  if referrer_id and referrer_id != user_id:
103
  ref_data = supabase.table('referrals').select('referral_count').eq('user_id', referrer_id).execute()
104
  if ref_data.data:
105
+ new_count = ref_data.data[0]['referral_count'] + 1
106
+ supabase.table('referrals').update({'referral_count': new_count}).eq('user_id', referrer_id).execute()
107
+ bot.send_message(referrer_id, "🎉 কেউ আপনার রেফারে জয়েন করেছে! আপনার রেফারেল কাউন্ট বেড়েছে।")
108
  except: pass
109
 
110
  markup = InlineKeyboardMarkup()
111
  markup.add(InlineKeyboardButton("Play video 🔞", web_app=WebAppInfo(url=WEB_APP_URL)))
112
+ bot.reply_to(message, "ভাইরাল ভিডিও দেখতে নিচের বাটনে ক্লিক কর 👇", reply_markup=markup)
113
 
114
  if __name__ == "__main__":
115
  app.run(host="0.0.0.0", port=7860)