Seraph19 commited on
Commit
7cd8e78
1 Parent(s): 5bcf2a3

Create bot.py

Browse files
Files changed (1) hide show
  1. bot.py +47 -0
bot.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import telegram
2
+ from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
3
+ import data # Import your data handling functions from `data.py`
4
+ BOT_TOKEN = "7728880427:AAFOnNdOpFw9imBxkwtVnZKET-cbcjJVYIM"
5
+ def start(update, context):
6
+ user_id = update.message.from_user.id
7
+ user_data = data.load_data()
8
+
9
+ if user_id not in user_data:
10
+ user_data[user_id] = {"points": 0, "referrals": []}
11
+ data.save_data(user_data)
12
+ update.message.reply_text(
13
+ "Welcome! Start earning points by completing tasks."
14
+ )
15
+ else:
16
+ update.message.reply_text("Welcome back!")
17
+ def complete_task(update, context):
18
+ user_id = update.message.from_user.id
19
+ user_data = data.load_data()
20
+
21
+ if user_id in user_data:
22
+ user_data[user_id]["points"] += 10 # Award points for completing a task
23
+ data.save_data(user_data)
24
+ update.message.reply_text("Task completed! +10 points.")
25
+ else:
26
+ update.message.reply_text("Start by using /start.")
27
+ def refer(update, context):
28
+ user_id = update.message.from_user.id
29
+ user_data = data.load_data()
30
+
31
+ if user_id in user_data:
32
+ referral_link = f"https://t.me/your_bot_username?start=ref_{user_id}" # Your bot's username
33
+ update.message.reply_text(
34
+ f"Share this link to refer your friends: {referral_link}"
35
+ )
36
+ else:
37
+ update.message.reply_text("Start by using /start.")
38
+ updater = Updater(BOT_TOKEN, use_context=True)
39
+ dispatcher = updater.dispatcher
40
+
41
+ dispatcher.add_handler(CommandHandler("start", start))
42
+ dispatcher.add_handler(CommandHandler("task", complete_task))
43
+ dispatcher.add_handler(CommandHandler("refer", refer))
44
+ dispatcher.add_handler(MessageHandler(Filters.regex("^ref_[0-9]+$"), handle_referral))
45
+
46
+ updater.start_polling()
47
+ updater.idle()