File size: 1,819 Bytes
7cd8e78 |
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 |
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() |