-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEthBot.py
More file actions
1371 lines (1321 loc) · 71.6 KB
/
EthBot.py
File metadata and controls
1371 lines (1321 loc) · 71.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# main.py — Tapify Main Bot for Telegram
# Requirements:
# pip install python-telegram-bot==20.7 psycopg[binary] python-dotenv flask pydub
#
# Environment (.env):
# BOT_TOKEN=your_bot_token
# ADMIN_ID=your_admin_id
# GROUP_LINK=your_group_link
# SITE_LINK=your_site_link
# AI_BOOST_LINK=your_ai_boost_link
# DAILY_TASK_LINK=your_daily_task_link
# DATABASE_URL=postgres://user:pass@host:port/dbname
#
# Start:
# python main.py
import logging
import psycopg
import re
import time
import datetime
import os
import secrets
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, ReplyKeyboardMarkup, KeyboardButton, WebAppInfo
from telegram.ext import (
Application,
CommandHandler,
CallbackQueryHandler,
MessageHandler,
filters,
ContextTypes,
)
#from pydub import AudioSegment
from flask import Flask
from threading import Thread
# Flask setup for Render keep-alive
app = Flask('')
@app.route('/')
def home():
return "Tapify is alive!"
def run():
app.run(host='0.0.0.0', port=8080)
def keep_alive():
t = Thread(target=run)
t.start()
# Bot credentials
BOT_TOKEN = os.getenv("BOT_TOKEN")
ADMIN_ID = int(os.getenv("ADMIN_ID", "0") or "0")
GROUP_LINK = os.getenv("GROUP_LINK", "")
SITE_LINK = os.getenv("SITE_LINK", "")
AI_BOOST_LINK = os.getenv("AI_BOOST_LINK", "")
DAILY_TASK_LINK = os.getenv("DAILY_TASK_LINK", "")
WEBAPP_URL = os.getenv("WEBAPP_URL", "https://tapify.onrender.com/app")
# Validate environment variables
if not BOT_TOKEN:
logging.error("BOT_TOKEN is required in environment (.env)")
raise ValueError("BOT_TOKEN is required")
if not ADMIN_ID:
logging.error("ADMIN_ID is required in environment (.env)")
raise ValueError("ADMIN_ID is required")
# Predefined payment accounts
PAYMENT_ACCOUNTS = {
"Nigeria (Opay)": "🇳🇬 Account: 6110749592\nBank: Opay\nName: Chike Eluem Olanrewaju",
"Nigeria (Zenith)": "🇳🇬 Account: 2267515466\nBank: Zenith Bank\nName: Chike Eluem Olanrewaju",
"Nigeria (Kuda)": "🇳🇬 Account: 2036035854\nBank: Kuda Bank\nName: Eluem, Chike Olanrewaju",
}
# Predefined coupon payment accounts
COUPON_PAYMENT_ACCOUNTS = {
"Coupon Acct 1 (Opay)": "🇳🇬 Account: 6110749592\nBank: Opay\nName: Chike Eluem Olanrewaju",
"Coupon Acct 2 (Zenith)": "🇳🇬 Account: 2267515466\nBank: Zenith Bank\nName: Chike Eluem Olanrewaju",
"Coupon Acct 3 (Kuda)": "🇳🇬 Account: 2036035854\nBank: Kuda Bank\nName: Eluem, Chike Olanrewaju"
}
# Predefined FAQs
FAQS = {
"what_is_ethereal": {
"question": "What is Tapify?",
"answer": "Tapify is a platform where you earn money by completing tasks like taking a walk, reading posts, playing games, sending Snapchat streaks, and inviting friends."
},
"payment_methods": {
"question": "What payment methods are available?",
"answer": "Payments can be made via bank transfer, mobile money, PayPal or Zelle for foreign accounts. Check the 'How to Pay' guide in the Help menu."
},
"task_rewards": {
"question": "How are task rewards calculated?",
"answer": "Rewards vary by task type. For example, reading posts earns $2.5 per 10 words, Candy Crush tasks earn $5 daily, and Snapchat streaks can earn up to $20."
}
}
# Help topics
HELP_TOPICS = {
"how_to_pay": {"label": "How to Pay", "type": "video", "url": "https://youtu.be/ (will be available soon)"},
"register": {"label": "Registration Process", "type": "text", "text": (
"1. /start → choose package\n"
"2. Pay via your selected account → upload screenshot\n"
"3. Provide your details (name, email, phone, Telegram username)\n"
"4. Wait for admin approval\n"
"5. Join the group and start earning! 🎉"
)},
"daily_tasks": {"label": "Daily Tasks", "type": "video", "url": "https://youtu.be/ (will be available soon)"},
"reminder": {"label": "Toggle Reminder", "type": "toggle"},
"faq": {"label": "FAQs", "type": "faq"},
"apply_coach": {"label": "Apply to become Coach", "type": "text", "text": (
"Please contact the Admin @bigscottmedia to discuss your application process"
)},
"password_recovery": {"label": "Password Recovery", "type": "input", "text": "Please provide your registered email to request password recovery:"},
}
# Convert mp3 to ogg (Opus)
#try:
# sound = AudioSegment.from_mp3("voice.mp3")
# sound.export("voice.ogg", format="ogg", codec="libopus")
#except FileNotFoundError:
# logging.warning("voice.mp3 not found; voice note feature may fail")
# Database setup with PostgreSQL
try:
import urllib.parse as urlparse
url = os.getenv("DATABASE_URL")
if not url:
raise ValueError("DATABASE_URL must be set for PostgreSQL")
if "sslmode=" not in url:
if "?" in url:
url += "&sslmode=require"
else:
url += "?sslmode=require"
conn = psycopg.connect(url, row_factory=psycopg.rows.dict_row)
conn.autocommit = True
cursor = conn.cursor()
# Users table
cursor.execute("""
CREATE TABLE IF NOT EXISTS users (
chat_id BIGINT PRIMARY KEY,
package TEXT,
payment_status TEXT DEFAULT 'new',
name TEXT,
username TEXT,
email TEXT,
phone TEXT,
password TEXT,
join_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
alarm_setting INTEGER DEFAULT 0,
streaks INTEGER DEFAULT 0,
invites INTEGER DEFAULT 0,
balance REAL DEFAULT 0,
screenshot_uploaded_at TIMESTAMP,
approved_at TIMESTAMP,
registration_date TIMESTAMP,
referral_code TEXT,
referred_by BIGINT
)
""")
# Payments table
cursor.execute("""
CREATE TABLE IF NOT EXISTS payments (
id SERIAL PRIMARY KEY,
chat_id BIGINT,
type TEXT,
package TEXT,
quantity INTEGER,
total_amount INTEGER,
payment_account TEXT,
status TEXT DEFAULT 'pending_payment',
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
approved_at TIMESTAMP
)
""")
# Coupons table
cursor.execute("""
CREATE TABLE IF NOT EXISTS coupons (
id SERIAL PRIMARY KEY,
payment_id INTEGER,
code TEXT,
FOREIGN KEY (payment_id) REFERENCES payments(id)
)
""")
# Interactions table
cursor.execute("""
CREATE TABLE IF NOT EXISTS interactions (
id SERIAL PRIMARY KEY,
chat_id BIGINT,
action TEXT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
""")
# Tasks table
cursor.execute("""
CREATE TABLE IF NOT EXISTS tasks (
id SERIAL PRIMARY KEY,
type TEXT,
link TEXT,
reward REAL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
expires_at TIMESTAMP
)
""")
# User_tasks table
cursor.execute("""
CREATE TABLE IF NOT EXISTS user_tasks (
user_id BIGINT,
task_id INTEGER,
completed_at TIMESTAMP,
PRIMARY KEY (user_id, task_id),
FOREIGN KEY (user_id) REFERENCES users(chat_id),
FOREIGN KEY (task_id) REFERENCES tasks(id)
)
""")
except psycopg.Error as e:
logging.error(f"Database error: {e}")
raise
# In-memory storage
user_state = {}
start_time = time.time()
# Logging
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO)
logger = logging.getLogger(__name__)
# Helper functions
def get_status(chat_id):
try:
cursor.execute("SELECT payment_status FROM users WHERE chat_id=%s", (chat_id,))
row = cursor.fetchone()
return row["payment_status"] if row else None
except psycopg.Error as e:
logger.error(f"Database error in get_status: {e}")
return None
def is_registered(chat_id):
try:
cursor.execute("SELECT payment_status FROM users WHERE chat_id=%s", (chat_id,))
row = cursor.fetchone()
return row and row["payment_status"] == 'registered'
except psycopg.Error as e:
logger.error(f"Database error in is_registered {chat_id}: {e}")
return False
def log_interaction(chat_id, action):
try:
cursor.execute("INSERT INTO interactions (chat_id, action) VALUES (%s, %s)", (chat_id, action))
except psycopg.Error as e:
logger.error(f"Database error in log_interaction: {e}")
def generate_referral_code():
return secrets.token_urlsafe(6)
# Command handlers
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat_id = update.effective_chat.id
referral_code = generate_referral_code()
args = context.args
referred_by = None
if args and args[0].startswith("ref_"):
try:
referred_by = int(args[0].split("_")[1])
except (IndexError, ValueError):
pass
log_interaction(chat_id, "start")
try:
cursor.execute("SELECT payment_status FROM users WHERE chat_id=%s", (chat_id,))
if not cursor.fetchone():
cursor.execute(
"INSERT INTO users (chat_id, username, referral_code, referred_by) VALUES (%s, %s, %s, %s)",
(chat_id, update.effective_user.username or "Unknown", referral_code, referred_by)
)
if referred_by:
cursor.execute("UPDATE users SET invites = invites + 1, balance = balance + 0.1 WHERE chat_id=%s", (referred_by,))
conn.commit()
keyboard = [[InlineKeyboardButton("🚀 Get Started", callback_data="menu")]]
await update.message.reply_text(
"Welcome to Tapify!\n\nGet paid for using your phone and doing what you love most.\n"
"• Read posts ➜ earn $2.5/10 words\n• Take a Walk ➜ earn $5\n"
"• Send Snapchat streaks ➜ earn up to $20\n• Invite friends and more!\n\n"
"Choose your package and start earning today.\nClick below to get started.",
reply_markup=InlineKeyboardMarkup(keyboard),
)
reply_keyboard = [["/menu(🔙)"]]
if is_registered(chat_id):
reply_keyboard.append([KeyboardButton(text="Play Tapify", web_app=WebAppInfo(url=f"{WEBAPP_URL}/?chat_id={chat_id}"))])
# await update.message.reply_text(
# "Use the button's below to access the main menu and Tapify Games:",
# reply_markup=ReplyKeyboardMarkup(reply_keyboard, resize_keyboard=True)
#)
except psycopg.Error as e:
logger.error(f"Database error in start: {e}")
await update.message.reply_text("An error occurred while accessing the database. Please try again later.")
except Exception as e:
logger.error(f"Unexpected error in start: {e}")
await update.message.reply_text("An unexpected error occurred. Please try again or contact @bigscottmedia.")
async def cmd_game(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat_id = update.effective_user.id
if not is_registered(chat_id):
await update.message.reply_text("Please complete registration to play the game.")
return
kb = [[KeyboardButton(
text="Play Tapify",
web_app=WebAppInfo(
url=f"{WEBAPP_URL}/?chat_id={chat_id}&username={update.effective_user.username or 'guest'}"
)
)]]
await update.message.reply_text(
"Tap to earn coins!",
reply_markup=ReplyKeyboardMarkup(kb, resize_keyboard=True)
)
async def support(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat_id = update.effective_chat.id
user_state[chat_id] = {'expecting': 'support_message'}
await update.message.reply_text("Please describe your issue or question:")
log_interaction(chat_id, "support_initiated")
async def stats(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat_id = update.effective_chat.id
log_interaction(chat_id, "stats")
try:
cursor.execute("SELECT payment_status, streaks, invites, package, balance FROM users WHERE chat_id=%s", (chat_id,))
user = cursor.fetchone()
if not user:
if update.callback_query:
await update.callback_query.answer("No user data found. Please start with /start.")
else:
await update.message.reply_text("No user data found. Please start with /start.")
return
payment_status, streaks, invites, package, balance = user.values()
text = (
"📊 Your Platform Stats:\n\n"
f"• Package: {package or 'Not selected'}\n"
f"• Payment Status: {payment_status.capitalize()}\n"
f"• Streaks: {streaks}\n"
f"• Invites: {invites}\n"
f"• Balance: ${balance:.2f}"
)
if balance >= 30:
keyboard = [[InlineKeyboardButton("💸 Withdraw", callback_data="withdraw")]]
else:
keyboard = []
if update.callback_query:
await update.callback_query.edit_message_text(text, reply_markup=InlineKeyboardMarkup(keyboard))
else:
await update.message.reply_text(text, reply_markup=InlineKeyboardMarkup(keyboard))
except psycopg.Error as e:
logger.error(f"Database error in stats: {e}")
await update.message.reply_text("An error occurred. Please try again.")
async def reset_state(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat_id = update.effective_chat.id
if chat_id in user_state:
del user_state[chat_id]
await update.message.reply_text("State reset. Try the flow again.")
log_interaction(chat_id, "reset_state")
async def add_task(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat_id = update.effective_chat.id
if chat_id != ADMIN_ID:
await update.message.reply_text("This command is restricted to the admin.")
return
args = context.args
if len(args) != 3:
await update.message.reply_text("Usage: /add_task <type> <link> <reward>")
return
task_type, link, reward = args
try:
reward = float(reward)
except ValueError:
await update.message.reply_text("Reward must be a number.")
return
created_at = datetime.datetime.now()
expires_at = created_at + datetime.timedelta(days=1)
try:
cursor.execute(
"INSERT INTO tasks (type, link, reward, created_at, expires_at) VALUES (%s, %s, %s, %s, %s)",
(task_type, link, reward, created_at, expires_at)
)
conn.commit()
await update.message.reply_text("Task added successfully.")
log_interaction(chat_id, "add_task")
except psycopg.Error as e:
logger.error(f"Database error in add_task: {e}")
await update.message.reply_text("An error occurred. Please try again.")
async def broadcast(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat_id = update.effective_chat.id
if chat_id != ADMIN_ID:
await update.message.reply_text("This command is restricted to the admin.")
return
user_state[chat_id] = {'expecting': 'broadcast_message'}
await update.message.reply_text("Please enter the broadcast message to send to all registered users:")
log_interaction(chat_id, "broadcast_initiated")
# Callback handlers
async def button_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
data = query.data
chat_id = query.from_user.id
logger.info(f"Received callback data: {data} from chat_id: {chat_id}")
await query.answer()
log_interaction(chat_id, f"button_{data}")
try:
if data == "menu":
if chat_id in user_state:
del user_state[chat_id]
await show_main_menu(update, context)
elif data == "stats":
await stats(update, context)
elif data == "refer_friend":
cursor.execute("SELECT referral_code FROM users WHERE chat_id=%s", (chat_id,))
referral_code = cursor.fetchone()["referral_code"]
referral_link = f"https://t.me/{context.bot.username}?start=ref_{chat_id}"
text = (
"👥 Refer a Friend and Earn Rewards!\n\n"
"Share your referral link with friends. For each friend who joins using your link, you earn $0.1. "
"If they register, you earn an additional $0.4 for Standard or $0.9 for X package.\n\n"
f"Your referral link: {referral_link}"
)
await query.edit_message_text(text, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Help Menu", callback_data="help")]]))
elif data == "withdraw":
cursor.execute("SELECT balance FROM users WHERE chat_id=%s", (chat_id,))
balance = cursor.fetchone()["balance"]
if balance < 30:
await query.answer("Your balance is less than $30.")
return
await context.bot.send_message(
ADMIN_ID,
f"Withdrawal request from @{update.effective_user.username or 'Unknown'} (chat_id: {chat_id})\n"
f"Amount: ${balance}"
)
await query.edit_message_text(
"Your withdrawal request has been sent to the admin. Please wait for processing.",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]])
)
elif data == "how_it_works":
keyboard = [
[InlineKeyboardButton("💎TAP MEEE!!!!", callback_data="package_selector")],
[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]
]
await query.edit_message_text(
"🟡 HOW TAPIFY💥 WORKS\n"
"Tapify rewards you for your everyday online actions — walking, gaming, sending snaps, joining forums, and social engagement.\n"
"— — —\n"
"📍 TAPIFY STANDARD PACKAGE — ₦10,000\n"
"• 🎉 Starter Reward: ₦8,000 Newbie Bonus\n"
"• 🛜 Free Data: 5GB on your preferred network\n"
"• 🪙 Tap Coins: Instant $10 reward\n"
"• 💰 Revenue Share: ₦9,000 per direct recruit\n"
"• 🔁 Indirect Earnings: ₦250 (1st level) – ₦100 (2nd level)\n"
"• 🧾 Forum Earnings: ₦200 per 10 words\n"
"• 🎥 Snapchat/TikTok Streaks: $10 per streak\n"
"• 🚶♂ Steps: ₦10 per 100 steps\n"
"• 🏍 Rider Earnings: ₦20 per delivery\n"
"• 📖 Reading Tasks: ₦0.2 per novel read\n\n"
"• 🎙 Recording Tasks: ₦0.2 per audio\n"
"• 📤 Approved Topics & Social Links: ₦5 each\n"
"• 🎮 Tapify Games: ₦20 per session\n"
"• 🧑🤝🧑 Unlimited Team Earnings: Passive income from your team\n"
"• 🏦 Student Loans: No collateral required\n"
"• 💳 Automated Withdrawals: Weekly payouts\n"
"• Up to ₦5,000 daily from Candy Crush\n"
"• Earn up to $50 sending Snapchat streaks\n"
"• Daily passive income from your team + your earnings (₦10,000 daily)\n"
"• 📺 Subscription Bonuses: Free access to GOtv, DStv & Netflix\n"
"— — —\n\n"
" Ensure to listen to the Voice Note below to understand more about our features...",
reply_markup=InlineKeyboardMarkup(keyboard)
)
voice_keyboard = [
[InlineKeyboardButton("✅ I've listened...", callback_data="close_voice")]
]
voice_markup = InlineKeyboardMarkup(voice_keyboard)
try:
with open("voice.ogg", "rb") as voice:
await context.bot.send_voice(
chat_id=query.message.chat_id,
voice=voice,
caption="Tapify Explained 🎧",
reply_markup=voice_markup
)
except FileNotFoundError:
logger.error("Voice file 'voice.ogg' not found")
await context.bot.send_message(
chat_id=query.message.chat_id,
text="Error: Voice note file not found. Please contact support.",
reply_markup=voice_markup
)
except Exception as e:
logger.error(f"Error sending voice note: {e}")
await context.bot.send_message(
chat_id=query.message.chat_id,
text="An error occurred while sending the voice note. Please try again.",
reply_markup=voice_markup
)
elif data == "close_voice":
await query.message.delete()
elif data == "coupon":
user_state[chat_id] = {'expecting': 'coupon_quantity'}
keyboard = [[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]]
await query.edit_message_text(
"How many coupons do you want to purchase?",
reply_markup=InlineKeyboardMarkup(keyboard)
)
elif data == "coupon_standard":
package = "Standard"
price = 10000
quantity = user_state[chat_id]['coupon_quantity']
total = quantity * price
user_state[chat_id].update({'coupon_package': package, 'coupon_total': total})
await context.bot.send_message(
ADMIN_ID,
f"User @{update.effective_user.username or 'Unknown'} (chat_id: {chat_id}) "
f"wants to purchase {quantity} {package} coupons for ₦{total}."
)
keyboard = [[InlineKeyboardButton(a, callback_data=f"coupon_account_{a}")] for a in COUPON_PAYMENT_ACCOUNTS.keys()]
keyboard.append([InlineKeyboardButton("Other country option", callback_data="coupon_other")])
keyboard.append([InlineKeyboardButton("🔙 Main Menu", callback_data="menu")])
await query.edit_message_text(
f"You are purchasing {quantity} {package} coupons.\nTotal amount: ₦{total}\n\nSelect the account to pay to:",
reply_markup=InlineKeyboardMarkup(keyboard)
)
elif data.startswith("coupon_account_"):
account = data[len("coupon_account_"):]
payment_details = COUPON_PAYMENT_ACCOUNTS.get(account)
if not payment_details:
await context.bot.send_message(chat_id, "Error: Invalid account. Contact @bigscottmedia.", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]]))
return
user_state[chat_id]['selected_account'] = account
user_state[chat_id]['expecting'] = 'coupon_screenshot'
package = user_state[chat_id]['coupon_package']
quantity = user_state[chat_id]['coupon_quantity']
total = user_state[chat_id]['coupon_total']
cursor.execute(
"INSERT INTO payments (chat_id, type, package, quantity, total_amount, payment_account, status) VALUES (%s, %s, %s, %s, %s, %s, %s) RETURNING id",
(chat_id, 'coupon', package, quantity, total, account, 'pending_payment')
)
payment_id = cursor.fetchone()["id"]
conn.commit()
user_state[chat_id]['waiting_approval'] = {'type': 'coupon', 'payment_id': payment_id}
keyboard = [
[InlineKeyboardButton("Change Account", callback_data="show_coupon_account_selection")],
[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]
]
await context.bot.send_message(
chat_id,
f"Payment details:\n\n{payment_details}\n\nPlease make the payment and send the screenshot.",
reply_markup=InlineKeyboardMarkup(keyboard)
)
elif data == "show_coupon_account_selection":
keyboard = [[InlineKeyboardButton(a, callback_data=f"coupon_account_{a}")] for a in COUPON_PAYMENT_ACCOUNTS.keys()]
keyboard.append([InlineKeyboardButton("Other country option", callback_data="coupon_other")])
keyboard.append([InlineKeyboardButton("🔙 Main Menu", callback_data="menu")])
await query.edit_message_text("Select an account to pay to:", reply_markup=InlineKeyboardMarkup(keyboard))
elif data == "coupon_other":
await context.bot.send_message(
chat_id,
"Please contact @bigscottmedia to complete your payment for other region coupon purchase.",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]])
)
elif data == "package_selector":
status = get_status(chat_id)
if status == 'registered':
await context.bot.send_message(chat_id, "You are already registered.")
return
keyboard = [
[InlineKeyboardButton("✈️Standard (₦10,000)", callback_data="reg_standard")],
[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")],
]
await query.edit_message_text("Choose your package:", reply_markup=InlineKeyboardMarkup(keyboard))
elif data in ["reg_standard", "reg_x"]:
package = "Standard" if data == "reg_standard" else "X"
user_state[chat_id] = {'package': package}
try:
cursor.execute("UPDATE users SET package=%s, payment_status='pending_payment' WHERE chat_id=%s", (package, chat_id))
if cursor.rowcount == 0:
cursor.execute("INSERT INTO users (chat_id, package, payment_status, username) VALUES (%s, %s, 'pending_payment', %s)", (chat_id, package, update.effective_user.username or "Unknown"))
conn.commit()
keyboard = [[InlineKeyboardButton(a, callback_data=f"reg_account_{a}")] for a in PAYMENT_ACCOUNTS.keys()]
keyboard.append([InlineKeyboardButton("Other country option", callback_data="reg_other")])
keyboard.append([InlineKeyboardButton("🔙 Main Menu", callback_data="menu")])
await query.edit_message_text("Select an account to pay to:", reply_markup=InlineKeyboardMarkup(keyboard))
except psycopg.Error as e:
logger.error(f"Database error in package_selector: {e}")
await query.edit_message_text("An error occurred. Please try again.")
return
elif data.startswith("reg_account_"):
account = data[len("reg_account_"):]
payment_details = PAYMENT_ACCOUNTS.get(account)
if not payment_details:
await context.bot.send_message(chat_id, "Error: Invalid account. Contact @bigscottmedia.", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]]))
return
user_state[chat_id]['selected_account'] = account
user_state[chat_id]['expecting'] = 'reg_screenshot'
keyboard = [
[InlineKeyboardButton("Change Account", callback_data="show_account_selection")],
[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]
]
await context.bot.send_message(
chat_id,
f"Payment details:\n\n{payment_details}\n\nPlease make the payment and send the screenshot.",
reply_markup=InlineKeyboardMarkup(keyboard)
)
elif data == "show_account_selection":
package = user_state[chat_id].get('package', '')
if not package:
await query.edit_message_text("Please select a package first.", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]]))
return
keyboard = [[InlineKeyboardButton(a, callback_data=f"reg_account_{a}")] for a in PAYMENT_ACCOUNTS.keys()]
keyboard.append([InlineKeyboardButton("Other country option", callback_data="reg_other")])
keyboard.append([InlineKeyboardButton("🔙 Main Menu", callback_data="menu")])
await query.edit_message_text("Select an account to pay to:", reply_markup=InlineKeyboardMarkup(keyboard))
elif data == "reg_other":
await context.bot.send_message(
chat_id,
"Please contact @bigscottmedia to complete your payment for other region registration.",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]])
)
elif data.startswith("approve_"):
parts = data.split("_")
if parts[1] == "reg":
user_chat_id = int(parts[2])
try:
cursor.execute("UPDATE users SET payment_status='pending_details', approved_at=%s WHERE chat_id=%s", (datetime.datetime.now(), user_chat_id))
conn.commit()
user_state[user_chat_id] = {'expecting': 'name'}
await context.bot.send_message(
user_chat_id,
"✅ Your payment is approved!\n\nPlease provide your full name:"
)
await query.edit_message_text("Payment approved. Waiting for user details.")
except psycopg.Error as e:
logger.error(f"Database error in approve_reg: {e}")
await query.edit_message_text("An error occurred. Please try again.")
elif parts[1] == "coupon":
payment_id = int(parts[2])
try:
cursor.execute("UPDATE payments SET status='approved', approved_at=%s WHERE id=%s", (datetime.datetime.now(), payment_id))
conn.commit()
user_state[ADMIN_ID] = {'expecting': {'type': 'coupon_codes', 'payment_id': payment_id}}
await context.bot.send_message(ADMIN_ID, f"Payment {payment_id} approved. Please send the coupon codes (one per line).")
await query.edit_message_text("Payment approved. Waiting for coupon codes.")
except psycopg.Error as e:
logger.error(f"Database error in approve_coupon: {e}")
await query.edit_message_text("An error occurred. Please try again.")
elif parts[1] == "task":
task_id = int(parts[2])
user_chat_id = int(parts[3])
try:
cursor.execute("INSERT INTO user_tasks (user_id, task_id, completed_at) VALUES (%s, %s, %s)", (user_chat_id, task_id, datetime.datetime.now()))
cursor.execute("SELECT reward FROM tasks WHERE id=%s", (task_id,))
reward = cursor.fetchone()["reward"]
cursor.execute("UPDATE users SET balance = balance + %s WHERE chat_id=%s", (reward, user_chat_id))
conn.commit()
await context.bot.send_message(user_chat_id, f"Task approved! You earned ${reward}.")
await query.edit_message_text("Task approved and reward awarded.")
except psycopg.Error as e:
logger.error(f"Database error in approve_task: {e}")
await query.edit_message_text("An error occurred. Please try again.")
elif data.startswith("finalize_reg_"):
user_chat_id = int(data.split("_")[2])
user_state[ADMIN_ID] = {'expecting': 'user_credentials', 'for_user': user_chat_id}
await context.bot.send_message(
ADMIN_ID,
f"Please send the username and password for user {user_chat_id} in the format:\nusername\npassword"
)
await query.edit_message_text("Waiting for user credentials.")
elif data.startswith("reject_task_"):
parts = data.split("_")
task_id = int(parts[2])
user_chat_id = int(parts[3])
try:
cursor.execute("SELECT balance FROM users WHERE chat_id=%s", (user_chat_id,))
balance = cursor.fetchone()["balance"]
cursor.execute("SELECT reward FROM tasks WHERE id=%s", (task_id,))
reward = cursor.fetchone()["reward"]
if balance >= reward:
cursor.execute("UPDATE users SET balance = balance - %s WHERE chat_id=%s", (reward, user_chat_id))
cursor.execute("DELETE FROM user_tasks WHERE user_id=%s AND task_id=%s", (user_chat_id, task_id))
conn.commit()
await context.bot.send_message(user_chat_id, "Task verification rejected. Reward revoked.")
await query.edit_message_text("Task rejected and reward removed.")
else:
await query.edit_message_text("Task rejected, but balance insufficient to revoke reward.")
except psycopg.Error as e:
logger.error(f"Database error in reject_task: {e}")
await query.edit_message_text("An error occurred. Please try again.")
elif data.startswith("pending_"):
parts = data.split("_")
if parts[1] == "reg":
await context.bot.send_message(int(parts[2]), "Your payment is still being reviewed. Please check back later.")
elif parts[1] == "coupon":
payment_id = int(parts[2])
try:
cursor.execute("SELECT chat_id FROM payments WHERE id=%s", (payment_id,))
user_chat_id = cursor.fetchone()["chat_id"]
await context.bot.send_message(user_chat_id, "Your coupon payment is still being reviewed.")
except psycopg.Error as e:
logger.error(f"Database error in pending_coupon: {e}")
await query.edit_message_text("An error occurred. Please try again.")
elif data == "check_approval":
if 'waiting_approval' not in user_state.get(chat_id, {}):
await context.bot.send_message(chat_id, "You have no pending payments.")
return
approval = user_state[chat_id]['waiting_approval']
if approval['type'] == 'registration':
status = get_status(chat_id)
if status == 'pending_details':
user_state[chat_id] = {'expecting': 'name'}
await context.bot.send_message(chat_id, "Payment approved. Please provide your full name:")
elif status == 'registered':
await context.bot.send_message(chat_id, "Your registration is complete.")
else:
await context.bot.send_message(chat_id, "Your payment is being reviewed.")
elif approval['type'] == 'coupon':
payment_id = approval['payment_id']
try:
cursor.execute("SELECT status FROM payments WHERE id=%s", (payment_id,))
status = cursor.fetchone()["status"]
if status == 'approved':
await context.bot.send_message(chat_id, "Coupon payment approved. Check your coupons above.")
else:
await context.bot.send_message(chat_id, "Your coupon payment is being reviewed.")
except psycopg.Error as e:
logger.error(f"Database error in check_approval: {e}")
await context.bot.send_message(chat_id, "An error occurred. Please try again.")
elif data == "toggle_reminder":
try:
cursor.execute("SELECT alarm_setting FROM users WHERE chat_id=%s", (chat_id,))
current_setting = cursor.fetchone()["alarm_setting"]
new_setting = 1 if current_setting == 0 else 0
cursor.execute("UPDATE users SET alarm_setting=%s WHERE chat_id=%s", (new_setting, chat_id))
conn.commit()
status = "enabled" if new_setting == 1 else "disabled"
await query.edit_message_text(f"Daily reminder {status}.", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Help Menu", callback_data="help")]]))
except psycopg.Error as e:
logger.error(f"Database error in toggle_reminder: {e}")
await query.edit_message_text("An error occurred. Please try again.")
elif data == "boost_ai":
await query.edit_message_text(
f"🚀 Boost with AI\n\nAccess Advanced AI-powered features to maximize your earnings: {AI_BOOST_LINK}",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]])
)
elif data == "user_registered":
try:
cursor.execute("SELECT username, email, password, package FROM users WHERE chat_id=%s", (chat_id,))
user = cursor.fetchone()
if user:
username, email, password, package = user.values()
await query.edit_message_text(
f"🎉 Registration Complete!\n\n"
f"• Site: {SITE_LINK}\n"
f"• Username: {username}\n"
f"• Email: {email}\n"
f"• Password: {password}\n\n"
"Keep your credentials safe. Use 'Password Recovery' in the Help menu if needed.",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]])
)
else:
await query.edit_message_text("No registration data found.", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]]))
except psycopg.Error as e:
logger.error(f"Database error in user_registered: {e}")
await query.edit_message_text("An error occurred. Please try again.")
elif data == "daily_tasks":
try:
cursor.execute("SELECT package FROM users WHERE chat_id=%s", (chat_id,))
package = cursor.fetchone()["package"]
msg = f"Follow this link to perform your daily tasks and earn: {DAILY_TASK_LINK}"
if package == "X":
msg = f"🌟 X Users: Maximize your earnings with this special daily task link: {DAILY_TASK_LINK}"
await query.edit_message_text(msg, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]]))
except psycopg.Error as e:
logger.error(f"Database error in daily_tasks: {e}")
await query.edit_message_text("An error occurred. Please try again.")
elif data == "earn_extra":
now = datetime.datetime.now()
try:
cursor.execute("""
SELECT t.id, t.type, t.link, t.reward
FROM tasks t
WHERE t.expires_at > %s
AND t.id NOT IN (SELECT ut.task_id FROM user_tasks ut WHERE ut.user_id = %s)
""", (now, chat_id))
tasks = cursor.fetchall()
if not tasks:
await query.edit_message_text(
"No extra tasks available right now. Please check back later.",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]])
)
return
keyboard = []
for task in tasks:
task_id, task_type, link, reward = task.values()
join_button = InlineKeyboardButton(f"Join {task_type} (${reward})", url=link)
verify_button = InlineKeyboardButton("Verify", callback_data=f"verify_task_{task_id}")
keyboard.append([join_button, verify_button])
keyboard.append([InlineKeyboardButton("🔙 Main Menu", callback_data="menu")])
await query.edit_message_text("Available extra tasks for today:", reply_markup=InlineKeyboardMarkup(keyboard))
except psycopg.Error as e:
logger.error(f"Database error in earn_extra: {e}")
await query.edit_message_text("An error occurred. Please try again.")
elif data.startswith("verify_task_"):
task_id = int(data[len("verify_task_"):])
try:
cursor.execute("SELECT type, link FROM tasks WHERE id=%s", (task_id,))
task = cursor.fetchone()
if not task:
await query.answer("Task not found.")
return
task_type, link = task.values()
regel = re.compile(r'(@[A-Za-z0-9]+)|(?:https?://)?(?:www\.)?(?:t\.me|telegram\.(?:me|dog))/([A-Za-z0-9\+]+)')
chat_username = regel.search(link).group()
if chat_username.startswith("http"):
chat_username = chat_username.split("/")[-1]
if task_type in ["join_group", "join_channel"]:
try:
member = await context.bot.get_chat_member(chat_username, chat_id)
if member.status in ["member", "administrator", "creator"]:
cursor.execute("INSERT INTO user_tasks (user_id, task_id, completed_at) VALUES (%s, %s, %s)", (chat_id, task_id, datetime.datetime.now()))
cursor.execute("SELECT reward FROM tasks WHERE id=%s", (task_id,))
reward = cursor.fetchone()["reward"]
cursor.execute("UPDATE users SET balance = balance + %s WHERE chat_id=%s", (reward, chat_id))
conn.commit()
await query.answer(f"Task completed! You earned ${reward}.")
else:
await query.answer("You are not in the group/channel yet.")
except Exception as e:
logger.error(f"Error verifying task: {e}")
await query.answer("Error verifying task. Try again later.")
elif task_type == "external_task":
user_state[chat_id] = {'expecting': 'task_screenshot', 'task_id': task_id}
await context.bot.send_message(chat_id, f"Please send the screenshot for task #{task_id} verification.")
except psycopg.Error as e:
logger.error(f"Database error in verify_task: {e}")
await query.answer("An error occurred. Please try again.")
elif data == "faq":
keyboard = [[InlineKeyboardButton(faq["question"], callback_data=f"faq_{key}")] for key, faq in FAQS.items()]
keyboard.append([InlineKeyboardButton("Ask Another Question", callback_data="faq_custom")])
keyboard.append([InlineKeyboardButton("🔙 Help Menu", callback_data="help")])
await query.edit_message_text("Select a question or ask your own:", reply_markup=InlineKeyboardMarkup(keyboard))
elif data.startswith("faq_"):
faq_key = data[len("faq_"):]
if faq_key == "custom":
user_state[chat_id]['expecting'] = 'faq'
await query.edit_message_text("Please type your question:", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Help Menu", callback_data="help")]]))
else:
faq = FAQS.get(faq_key)
if faq:
await query.edit_message_text(
f"❓ {faq['question']}\n\n{faq['answer']}",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 FAQ Menu", callback_data="faq"), InlineKeyboardButton("🔙 Help Menu", callback_data="help")]])
)
else:
await query.edit_message_text("FAQ not found.", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Help Menu", callback_data="help")]]))
elif data in HELP_TOPICS:
topic = HELP_TOPICS[data]
keyboard = [[InlineKeyboardButton("🔙 Help Menu", callback_data="help")]]
if topic["type"] == "input":
user_state[chat_id]['expecting'] = data
await query.edit_message_text(topic["text"], reply_markup=InlineKeyboardMarkup(keyboard))
elif topic["type"] == "toggle":
keyboard = [
[InlineKeyboardButton("Toggle Reminder On/Off", callback_data="toggle_reminder")],
[InlineKeyboardButton("🔙 Help Menu", callback_data="help")]
]
await query.edit_message_text("Toggle your daily reminder:", reply_markup=InlineKeyboardMarkup(keyboard))
elif topic["type"] == "faq":
await button_handler(update, context) # Redirect to FAQ handler
else:
content = topic["text"] if topic["type"] == "text" else f"Watch here: {topic['url']}"
await query.edit_message_text(content, reply_markup=InlineKeyboardMarkup(keyboard))
elif data == "help":
await help_menu(update, context)
elif data == "enable_reminders":
try:
cursor.execute("UPDATE users SET alarm_setting=1 WHERE chat_id=%s", (chat_id,))
conn.commit()
await query.edit_message_text(
"✅ Daily reminders enabled!",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]])
)
except psycopg.Error as e:
logger.error(f"Database error in enable_reminders: {e}")
await query.edit_message_text("An error occurred. Please try again.")
elif data == "disable_reminders":
try:
cursor.execute("UPDATE users SET alarm_setting=0 WHERE chat_id=%s", (chat_id,))
conn.commit()
await query.edit_message_text(
"❌ Okay, daily reminders not set.",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔙 Main Menu", callback_data="menu")]])
)
except psycopg.Error as e:
logger.error(f"Database error in disable_reminders: {e}")
await query.edit_message_text("An error occurred. Please try again.")
else:
logger.warning(f"Unknown callback data: {data}")
await query.edit_message_text("Unknown action. Please try again or contact @bigscottmedia.")
except Exception as e:
logger.error(f"Error in button_handler: {e}")
await query.edit_message_text("An error occurred. Please try again or contact @bigscottmedia.")
# Message handlers
async def handle_photo(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat_id = update.message.chat_id
if 'expecting' not in user_state.get(chat_id, {}):
return
expecting = user_state[chat_id]['expecting']
file_id = update.message.photo[-1].file_id
logger.info(f"Processing photo for {expecting}")
try:
if expecting == 'reg_screenshot':
cursor.execute("UPDATE users SET screenshot_uploaded_at=%s WHERE chat_id=%s", (datetime.datetime.now(), chat_id))
conn.commit()
keyboard = [
[InlineKeyboardButton("Approve", callback_data=f"approve_reg_{chat_id}")],
[InlineKeyboardButton("Pending", callback_data=f"pending_reg_{chat_id}")],
]
await context.bot.send_photo(
ADMIN_ID,
file_id,
caption=f"📸 Registration Payment from @{update.effective_user.username or 'Unknown'} (chat_id: {chat_id})",
reply_markup=InlineKeyboardMarkup(keyboard)
)
await update.message.reply_text("✅ Screenshot received! Awaiting admin approval.")
user_state[chat_id]['waiting_approval'] = {'type': 'registration'}
context.job_queue.run_once(check_registration_payment, 3600, data={'chat_id': chat_id})
elif expecting == 'coupon_screenshot':
payment_id = user_state[chat_id]['waiting_approval']['payment_id']
keyboard = [
[InlineKeyboardButton("Approve", callback_data=f"approve_coupon_{payment_id}")],
[InlineKeyboardButton("Pending", callback_data=f"pending_coupon_{payment_id}")],
]
await context.bot.send_photo(
ADMIN_ID,
file_id,
caption=f"📸 Coupon Payment from @{update.effective_user.username or 'Unknown'} (chat_id: {chat_id})",
reply_markup=InlineKeyboardMarkup(keyboard)
)
await update.message.reply_text("✅ Screenshot received! Awaiting admin approval.")
context.job_queue.run_once(check_coupon_payment, 3600, data={'payment_id': payment_id})
elif expecting == 'task_screenshot':
task_id = user_state[chat_id]['task_id']
await context.bot.send_photo(
ADMIN_ID,
file_id,
caption=f"Task #{task_id} verification from @{update.effective_user.username or 'Unknown'} (chat_id: {chat_id})",
reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton("Approve", callback_data=f"approve_task_{task_id}_{chat_id}")],
[InlineKeyboardButton("Reject", callback_data=f"reject_task_{task_id}_{chat_id}")]
])
)
await update.message.reply_text("Screenshot received. Awaiting admin approval.")
del user_state[chat_id]['expecting']
log_interaction(chat_id, "photo_upload")
except Exception as e:
logger.error(f"Error in handle_photo: {e}")
await update.message.reply_text("An error occurred. Please try again or contact @bigscottmedia.")
async def handle_document(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat_id = update.message.chat_id
if 'expecting' not in user_state.get(chat_id, {}):
return
expecting = user_state[chat_id]['expecting']
file_id = update.message.document.file_id
mime_type = update.message.document.mime_type
if not mime_type.startswith('image/'):
await update.message.reply_text("Please send an image file (e.g., PNG, JPG).")
return
logger.info(f"Processing document for {expecting}")
try:
if expecting == 'reg_screenshot':
cursor.execute("UPDATE users SET screenshot_uploaded_at=%s WHERE chat_id=%s", (datetime.datetime.now(), chat_id))
conn.commit()
keyboard = [
[InlineKeyboardButton("Approve", callback_data=f"approve_reg_{chat_id}")],
[InlineKeyboardButton("Pending", callback_data=f"pending_reg_{chat_id}")],
]
await context.bot.send_document(
ADMIN_ID,
file_id,
caption=f"📸 Registration Payment from @{update.effective_user.username or 'Unknown'} (chat_id: {chat_id})",