Mukera / bot.py
Seraph19's picture
Create bot.py
7cd8e78 verified
import telegram
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import data # Import your data handling functions from `data.py`
BOT_TOKEN = "7728880427:AAFOnNdOpFw9imBxkwtVnZKET-cbcjJVYIM"
def start(update, context):
user_id = update.message.from_user.id
user_data = data.load_data()
if user_id not in user_data:
user_data[user_id] = {"points": 0, "referrals": []}
data.save_data(user_data)
update.message.reply_text(
"Welcome! Start earning points by completing tasks."
)
else:
update.message.reply_text("Welcome back!")
def complete_task(update, context):
user_id = update.message.from_user.id
user_data = data.load_data()
if user_id in user_data:
user_data[user_id]["points"] += 10 # Award points for completing a task
data.save_data(user_data)
update.message.reply_text("Task completed! +10 points.")
else:
update.message.reply_text("Start by using /start.")
def refer(update, context):
user_id = update.message.from_user.id
user_data = data.load_data()
if user_id in user_data:
referral_link = f"https://t.me/your_bot_username?start=ref_{user_id}" # Your bot's username
update.message.reply_text(
f"Share this link to refer your friends: {referral_link}"
)
else:
update.message.reply_text("Start by using /start.")
updater = Updater(BOT_TOKEN, use_context=True)
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(CommandHandler("task", complete_task))
dispatcher.add_handler(CommandHandler("refer", refer))
dispatcher.add_handler(MessageHandler(Filters.regex("^ref_[0-9]+$"), handle_referral))
updater.start_polling()
updater.idle()