Skip to content

Teligram bot #4268

Description

@lamanarayan970-droid

import logging
from datetime import datetime, timedelta

from telegram import (
Update,
InlineKeyboardButton,
InlineKeyboardMarkup,
)
from telegram.ext import (
Application,
CommandHandler,
CallbackQueryHandler,
ContextTypes,
MessageHandler,
filters,
)
Your token was replaced with a new one. You can use this token to access HTTP API:
8878213533:AAEEhWalMVuCvMNLArIz58I5TA3U2UM3MMI
TOKEN = "YOUR_BOT_TOKEN"

logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.INFO,
)

logger = logging.getLogger(name)

Temporary storage

users = {}

REFERRAL_REWARD = 10
DAILY_BONUS = 5
MIN_WITHDRAW = 50

def get_user(user_id):
if user_id not in users:
users[user_id] = {
"balance": 0,
"referred": [],
"last_bonus": None,
"referrer": None,
}
return users[user_id]

def menu():
keyboard = [
[InlineKeyboardButton("💰 Balance", callback_data="balance")],
[InlineKeyboardButton("👥 Referral Link", callback_data="referral")],
[InlineKeyboardButton("🎁 Daily Bonus", callback_data="bonus")],
[InlineKeyboardButton("💸 Withdraw", callback_data="withdraw")],
[InlineKeyboardButton("📖 How to Earn", callback_data="earn")],
]
return InlineKeyboardMarkup(keyboard)

async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
user = update.effective_user
data = get_user(user.id)

if context.args:
    try:
        referrer = int(context.args[0])

        if (
            referrer != user.id
            and data["referrer"] is None
            and referrer in users
        ):
            data["referrer"] = referrer

            users[referrer]["balance"] += REFERRAL_REWARD
            users[referrer]["referred"].append(user.id)

            try:
                await context.bot.send_message(
                    chat_id=referrer,
                    text=f"🎉 You earned ₹{REFERRAL_REWARD} from a successful referral!"
                )
            except Exception:
                pass

    except ValueError:
        pass

text = f"""

👋 Welcome {user.first_name}!

Earn money by inviting friends.

Referral Reward: ₹10
Minimum Withdrawal: ₹50

Choose an option below.
"""

await update.message.reply_text(text, reply_markup=menu())

async def buttons(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
await query.answer()

user = get_user(query.from_user.id)

if query.data == "balance":
    await query.edit_message_text(
        f"💰 Your Balance: ₹{user['balance']}",
        reply_markup=menu(),
    )

elif query.data == "referral":
    me = await context.bot.get_me()

    link = f"https://t.me/{me.username}?start={query.from_user.id}"

    await query.edit_message_text(
        f"Invite friends using:\n\n{link}\n\nReward: ₹10 per successful referral.",
        reply_markup=menu(),
    )

elif query.data == "bonus":

    now = datetime.now()

    if (
        user["last_bonus"] is None
        or now - user["last_bonus"] >= timedelta(days=1)
    ):
        user["balance"] += DAILY_BONUS
        user["last_bonus"] = now

        msg = f"🎁 Daily bonus added!\n₹{DAILY_BONUS} credited."

    else:
        msg = "❌ Daily bonus already claimed today."

    await query.edit_message_text(msg, reply_markup=menu())

elif query.data == "withdraw":

    if user["balance"] >= MIN_WITHDRAW":
        user["balance"] = 0
        msg = "✅ Withdrawal request submitted."
    else:
        msg = f"❌ Minimum withdrawal is ₹{MIN_WITHDRAW}."

    await query.edit_message_text(msg, reply_markup=menu())

elif query.data == "earn":
    await query.edit_message_text(
        f"""

💸 Ways to Earn

• Invite a friend = ₹10
• Daily Bonus = ₹{DAILY_BONUS}

Minimum Withdrawal = ₹{MIN_WITHDRAW}
""",
reply_markup=menu(),
)

async def new_member(update: Update, context: ContextTypes.DEFAULT_TYPE):
for member in update.message.new_chat_members:
await update.message.reply_text(
f"👋 Welcome {member.first_name}!\n"
"Type /start to begin earning."
)

def main():
app = Application.builder().token(TOKEN).build()

app.add_handler(CommandHandler("start", start))
app.add_handler(CallbackQueryHandler(buttons))
app.add_handler(
    MessageHandler(filters.StatusUpdate.NEW_CHAT_MEMBERS, new_member)
)

logger.info("Bot started...")
app.run_polling()

if name == "main":
main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions