Created
January 18, 2026 05:30
-
-
Save agbochi40-maker/08cee73286d1159eeba99a7869aab4af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import sqlite3 | |
| from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup | |
| from telegram.ext import ApplicationBuilder, CommandHandler, CallbackQueryHandler, ContextTypes | |
| BOT_TOKEN = os.getenv('TRIBE2BOT_TOKEN') # set this later | |
| # Database setup | |
| conn = sqlite3.connect('tribe2bot.db', check_same_thread=False) | |
| cursor = conn.cursor() | |
| cursor.execute('''CREATE TABLE IF NOT EXISTS users ( | |
| user_id INTEGER PRIMARY KEY, | |
| referrer INTEGER, | |
| is_vip INTEGER DEFAULT 0 | |
| )''') | |
| conn.commit() | |
| # /start command | |
| async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| user = update.effective_user | |
| uid = user.id | |
| referral = int(context.args[0]) if context.args else None | |
| if referral == uid: referral = None | |
| cursor.execute("SELECT user_id FROM users WHERE user_id=?", (uid,)) | |
| if not cursor.fetchone(): | |
| cursor.execute("INSERT INTO users (user_id, referrer) VALUES (?,?)", (uid, referral)) | |
| conn.commit() | |
| link = f"https://t.me/Tribe2Bot?start={uid}" | |
| kb = [ | |
| [InlineKeyboardButton("π Signal", callback_data="signal")], | |
| [InlineKeyboardButton("π₯ Referrals", callback_data="refs")], | |
| [InlineKeyboardButton("π VIP", callback_data="vip")], | |
| [InlineKeyboardButton("π History", callback_data="history")] | |
| ] | |
| await update.message.reply_text( | |
| f"π Welcome {user.first_name}\n\nπ *Tribe2Bot*\nReferral Link:\n{link}", | |
| reply_markup=InlineKeyboardMarkup(kb), | |
| parse_mode="Markdown" | |
| ) | |
| # Button handler | |
| async def buttons(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| q = update.callback_query | |
| await q.answer() | |
| uid = q.from_user.id | |
| if q.data == "signal": | |
| await q.edit_message_text("π Free Signal\nBTC/USDT LONG\nEntry 42100\nTP 43500\nSL 41200", parse_mode="Markdown") | |
| elif q.data == "refs": | |
| cursor.execute("SELECT COUNT(*) FROM users WHERE referrer=?", (uid,)) | |
| c = cursor.fetchone()[0] | |
| await q.edit_message_text(f"π₯ Referrals: {c}/5", parse_mode="Markdown") | |
| elif q.data == "vip": | |
| cursor.execute("SELECT is_vip FROM users WHERE user_id=?", (uid,)) | |
| v = cursor.fetchone()[0] | |
| await q.edit_message_text("π VIP ACTIVE" if v else "β Not VIP", parse_mode="Markdown") | |
| elif q.data == "history": | |
| cursor.execute("SELECT pair, type, entry FROM signals ORDER BY id DESC LIMIT 1") | |
| r = cursor.fetchone() | |
| await q.edit_message_text(f"Last Signal: {r}" if r else "No signals yet") | |
| def main(): | |
| app = ApplicationBuilder().token(BOT_TOKEN).build() | |
| app.add_handler(CommandHandler("start", start)) | |
| app.add_handler(CallbackQueryHandler(buttons)) | |
| print("π€ Tribe2Bot running...") | |
| app.run_polling() | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment