Fourstore commited on
Commit
ad878b2
·
verified ·
1 Parent(s): 36e491f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -116
app.py CHANGED
@@ -13,13 +13,6 @@ import uuid
13
  import sys
14
  from pymongo import MongoClient
15
  from pymongo.errors import ConnectionFailure
16
- import logging
17
- from telegram import Update
18
- from telegram.ext import Updater, CommandHandler, CallbackContext
19
-
20
- # Setup logging
21
- logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
22
- logger = logging.getLogger(__name__)
23
 
24
  MONGODB_URI = os.environ.get("MONGODB_URI")
25
  DB_NAME = "otp_bot"
@@ -165,11 +158,11 @@ def get_search_date():
165
  wib = get_wib_time()
166
  return (wib - timedelta(days=1)).strftime("%Y-%m-%d") if wib.hour < 7 else wib.strftime("%Y-%m-%d")
167
 
168
- def login_account(account_id, username, password, bot_token, chat_id, owner_id):
169
  try:
170
  masked = mask_email(username)
171
  print(f"\n{'='*60}")
172
- print(f"🔐 PROSES LOGIN UNTUK: {masked} (ID: {account_id}) (Owner: {owner_id})")
173
  print(f"{'='*60}")
174
 
175
  session = httpx.Client(follow_redirects=True, timeout=30.0)
@@ -198,7 +191,6 @@ def login_account(account_id, username, password, bot_token, chat_id, owner_id):
198
  accounts[account_id]["password"] = password
199
  accounts[account_id]["bot_token"] = bot_token
200
  accounts[account_id]["chat_id"] = chat_id
201
- accounts[account_id]["owner_id"] = owner_id
202
  accounts[account_id]["last_login"] = time.time()
203
 
204
  if mongo_client:
@@ -562,7 +554,6 @@ def home():
562
  <input type="password" name="password" placeholder="Password" class="form-input" required>
563
  <input type="text" name="bot_token" placeholder="Bot Token (opsional)" class="form-input">
564
  <input type="text" name="chat_id" placeholder="Chat ID (opsional)" class="form-input">
565
- <input type="text" name="owner_id" placeholder="Owner ID (opsional)" class="form-input">
566
  <button type="submit" class="btn">Tambah & Login Otomatis</button>
567
  </form>
568
  </div>
@@ -695,13 +686,9 @@ def add_account_route():
695
  password = request.form['password']
696
  bot_token = request.form.get('bot_token', '')
697
  chat_id = request.form.get('chat_id', '')
698
- owner_id = request.form.get('owner_id', '')
699
-
700
- if not owner_id:
701
- owner_id = "default"
702
 
703
  masked = mask_email(username)
704
- print(f"\n➕ TAMBAH AKUN BARU: {masked} (ID: {account_id}) (Owner: {owner_id})")
705
 
706
  accounts[account_id] = {
707
  "id": account_id,
@@ -709,7 +696,6 @@ def add_account_route():
709
  "password": password,
710
  "bot_token": bot_token,
711
  "chat_id": chat_id,
712
- "owner_id": owner_id,
713
  "session": None,
714
  "csrf": None,
715
  "status": False,
@@ -734,8 +720,7 @@ def add_account_route():
734
  username,
735
  password,
736
  bot_token,
737
- chat_id,
738
- owner_id
739
  )
740
 
741
  if success:
@@ -761,95 +746,6 @@ def stream():
761
  sse_clients.remove(q)
762
  return Response(generate(), mimetype="text/event-stream")
763
 
764
- # ========== BOT TELEGRAM ==========
765
- def start_command(update: Update, context: CallbackContext):
766
- try:
767
- chat_id = str(update.effective_chat.id)
768
- user = update.effective_user
769
- print(f"📩 /start dari {user.first_name} (Chat ID: {chat_id})")
770
-
771
- user_accounts = []
772
- for acc_id, acc in accounts.items():
773
- if acc.get("owner_id") == chat_id:
774
- user_accounts.append(acc)
775
-
776
- text = f"👋 Halo {user.first_name}!\n\n📌 Chat ID kamu: `{chat_id}`\n\n"
777
-
778
- if user_accounts:
779
- text += f"✅ Kamu punya {len(user_accounts)} akun terdaftar.\n"
780
- text += "/accounts - Lihat daftar akun"
781
- else:
782
- text += "❌ Belum punya akun.\nGunakan Chat ID sebagai Owner ID di web."
783
-
784
- update.message.reply_text(text, parse_mode='Markdown')
785
- print(f"✅ Pesan terkirim ke {chat_id}")
786
- except Exception as e:
787
- print(f"❌ Error di start_command: {e}")
788
-
789
- def accounts_command(update: Update, context: CallbackContext):
790
- try:
791
- chat_id = str(update.effective_chat.id)
792
- print(f"📩 /accounts dari Chat ID: {chat_id}")
793
-
794
- user_accounts = []
795
- for acc_id, acc in accounts.items():
796
- if acc.get("owner_id") == chat_id:
797
- user_accounts.append((acc_id, acc))
798
-
799
- if not user_accounts:
800
- update.message.reply_text("❌ Kamu belum punya akun.")
801
- return
802
-
803
- text = "📋 *Daftar Akun:*\n\n"
804
- for acc_id, acc in user_accounts:
805
- status = "🟢 ON" if acc.get("status") else "🔴 OFF"
806
- masked = mask_email(acc['username'])
807
- text += f"• `{masked}`\n ID: `{acc_id}` | {status} | OTP: {len(acc.get('sent_cache', []))}\n\n"
808
-
809
- update.message.reply_text(text, parse_mode='Markdown')
810
- print(f"✅ Accounts terkirim ke {chat_id}")
811
- except Exception as e:
812
- print(f"❌ Error di accounts_command: {e}")
813
-
814
- def error_handler(update: Update, context: CallbackContext):
815
- print(f"❌ Telegram Error: {context.error}")
816
-
817
- def run_telegram_bot():
818
- try:
819
- print("🤖 Starting Telegram Bot...")
820
-
821
- # Kumpulkan semua token unik
822
- tokens = set()
823
- for acc_id, acc in accounts.items():
824
- if acc.get("bot_token"):
825
- tokens.add(acc['bot_token'])
826
-
827
- if not tokens:
828
- print("⚠️ Tidak ada bot token ditemukan di database!")
829
- return
830
-
831
- print(f"📊 Menemukan {len(tokens)} bot token")
832
-
833
- # Jalankan bot untuk setiap token
834
- for token in tokens:
835
- try:
836
- updater = Updater(token, use_context=True)
837
- dp = updater.dispatcher
838
-
839
- dp.add_handler(CommandHandler("start", start_command))
840
- dp.add_handler(CommandHandler("accounts", accounts_command))
841
- dp.add_error_handler(error_handler)
842
-
843
- updater.start_polling()
844
- print(f"✅ Bot dengan token {token[:10]}... berjalan")
845
- except Exception as e:
846
- print(f"❌ Gagal start bot dengan token {token[:10]}: {e}")
847
-
848
- print("🤖 Semua bot Telegram aktif!")
849
-
850
- except Exception as e:
851
- print(f"❌ Fatal error di run_telegram_bot: {e}")
852
-
853
  def run_account_scraper(account_id):
854
  account = accounts.get(account_id)
855
  if not account:
@@ -942,9 +838,8 @@ def run_account_scraper(account_id):
942
  def run_server():
943
  app.run(host='0.0.0.0', port=7860, debug=False, threaded=True)
944
 
945
- # Jalankan semua thread
946
  Thread(target=run_server, daemon=True).start()
947
- Thread(target=run_telegram_bot, daemon=True).start()
948
 
949
  def main():
950
  print("\n" + "="*60)
@@ -958,8 +853,7 @@ def main():
958
  print(" 📋 LOGGING: FULL DETAIL")
959
  print(" 🔒 EMAIL SENSOR: AKTIF")
960
  print(" 🤖 AUTO LOGIN: AKTIF")
961
- print(" 👑 OWNER ID: Input manual di form")
962
- print(" 🤖 TELEGRAM BOT: AKTIF (Multi-Token)")
963
  print("="*60 + "\n")
964
 
965
  # Auto login untuk akun yang sudah login sebelumnya
@@ -972,8 +866,7 @@ def main():
972
  acc['username'],
973
  acc['password'],
974
  acc.get('bot_token', ''),
975
- acc.get('chat_id', ''),
976
- acc.get('owner_id', 'default')
977
  )
978
  if success:
979
  thread = Thread(target=run_account_scraper, args=(acc_id,), daemon=True)
@@ -988,8 +881,6 @@ def main():
988
  save_accounts_to_file(accounts)
989
 
990
  print("\n✅ BOT SIAP! Dashboard: https://fourstore-otp.hf.space")
991
- print("📝 Owner ID bisa diisi manual saat tambah akun")
992
- print("🤖 Bot Telegram siap menerima perintah")
993
 
994
  while True:
995
  time.sleep(60)
 
13
  import sys
14
  from pymongo import MongoClient
15
  from pymongo.errors import ConnectionFailure
 
 
 
 
 
 
 
16
 
17
  MONGODB_URI = os.environ.get("MONGODB_URI")
18
  DB_NAME = "otp_bot"
 
158
  wib = get_wib_time()
159
  return (wib - timedelta(days=1)).strftime("%Y-%m-%d") if wib.hour < 7 else wib.strftime("%Y-%m-%d")
160
 
161
+ def login_account(account_id, username, password, bot_token, chat_id):
162
  try:
163
  masked = mask_email(username)
164
  print(f"\n{'='*60}")
165
+ print(f"🔐 PROSES LOGIN UNTUK: {masked} (ID: {account_id})")
166
  print(f"{'='*60}")
167
 
168
  session = httpx.Client(follow_redirects=True, timeout=30.0)
 
191
  accounts[account_id]["password"] = password
192
  accounts[account_id]["bot_token"] = bot_token
193
  accounts[account_id]["chat_id"] = chat_id
 
194
  accounts[account_id]["last_login"] = time.time()
195
 
196
  if mongo_client:
 
554
  <input type="password" name="password" placeholder="Password" class="form-input" required>
555
  <input type="text" name="bot_token" placeholder="Bot Token (opsional)" class="form-input">
556
  <input type="text" name="chat_id" placeholder="Chat ID (opsional)" class="form-input">
 
557
  <button type="submit" class="btn">Tambah & Login Otomatis</button>
558
  </form>
559
  </div>
 
686
  password = request.form['password']
687
  bot_token = request.form.get('bot_token', '')
688
  chat_id = request.form.get('chat_id', '')
 
 
 
 
689
 
690
  masked = mask_email(username)
691
+ print(f"\n➕ TAMBAH AKUN BARU: {masked} (ID: {account_id})")
692
 
693
  accounts[account_id] = {
694
  "id": account_id,
 
696
  "password": password,
697
  "bot_token": bot_token,
698
  "chat_id": chat_id,
 
699
  "session": None,
700
  "csrf": None,
701
  "status": False,
 
720
  username,
721
  password,
722
  bot_token,
723
+ chat_id
 
724
  )
725
 
726
  if success:
 
746
  sse_clients.remove(q)
747
  return Response(generate(), mimetype="text/event-stream")
748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
749
  def run_account_scraper(account_id):
750
  account = accounts.get(account_id)
751
  if not account:
 
838
  def run_server():
839
  app.run(host='0.0.0.0', port=7860, debug=False, threaded=True)
840
 
841
+ # Jalankan server Flask
842
  Thread(target=run_server, daemon=True).start()
 
843
 
844
  def main():
845
  print("\n" + "="*60)
 
853
  print(" 📋 LOGGING: FULL DETAIL")
854
  print(" 🔒 EMAIL SENSOR: AKTIF")
855
  print(" 🤖 AUTO LOGIN: AKTIF")
856
+ print(" 📱 TELEGRAM: HANYA KIRIM OTP (TANPA MENU)")
 
857
  print("="*60 + "\n")
858
 
859
  # Auto login untuk akun yang sudah login sebelumnya
 
866
  acc['username'],
867
  acc['password'],
868
  acc.get('bot_token', ''),
869
+ acc.get('chat_id', '')
 
870
  )
871
  if success:
872
  thread = Thread(target=run_account_scraper, args=(acc_id,), daemon=True)
 
881
  save_accounts_to_file(accounts)
882
 
883
  print("\n✅ BOT SIAP! Dashboard: https://fourstore-otp.hf.space")
 
 
884
 
885
  while True:
886
  time.sleep(60)