├── requirements.txt ├── users.json ├── README.md └── main.py /requirements.txt: -------------------------------------------------------------------------------- 1 | pyTelegramBotAPI 2 | -------------------------------------------------------------------------------- /users.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkin": { 3 | }, 4 | "withd": { 5 | }, 6 | "DailyQuiz": { 7 | }, 8 | "id": { 9 | }, 10 | "total": 0, 11 | "referred": { 12 | }, 13 | "referby": { 14 | }, 15 | "balance": { 16 | }, 17 | "wallet": { 18 | }, 19 | "refer": { 20 | }, 21 | "totalwith": 0 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🔗 Refer and Earn Telegram Bot 2 | 3 | [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Armanidrisi/python-bot/blob/main/LICENSE) 4 | ![GitHub repo size](https://img.shields.io/github/repo-size/Armanidrisi/python-bot) 5 | ![GitHub contributors](https://img.shields.io/github/contributors/Armanidrisi/python-bot) 6 | ![GitHub last commit](https://img.shields.io/github/last-commit/Armanidrisi/python-bot) 7 | ![GitHub forks](https://img.shields.io/github/forks/Armanidrisi/python-bot) 8 | ![GitHub issues](https://img.shields.io/github/issues-raw/Armanidrisi/python-bot) 9 | ![GitHub pull requests](https://img.shields.io/github/issues-pr/Armanidrisi/python-bot) 10 | ![GitHub stars](https://img.shields.io/github/stars/Armanidrisi/python-bot) 11 | 12 | ### ↳ Stargazers 13 | [![Stargazers repo roster for @Armanidrisi/python-bot](https://reporoster.com/stars/Armanidrisi/python-bot)](https://github.com/Armanidrisi/python-bot/stargazers) 14 | 15 | ### ↳ Forkers 16 | [![Forkers repo roster for @Armanidrisi/python-bot](https://reporoster.com/forks/Armanidrisi/python-bot)](https://github.com/Armanidrisi/python-bot/network/members) 17 | 18 | This is a Telegram bot created using Python and PyTelegramBotAPI that allows users to refer their friends to the bot and earn rewards in return. The bot is designed to keep track of user referrals and assign rewards based on the number of successful referrals made. 19 | 20 | ## 🚀 How to Use 21 | 22 | 1. Clone the repository to your local machine 23 | 2. Install the dependencies using `pip install -r requirements.txt` 24 | 3. Create a Telegram bot using [BotFather](https://core.telegram.org/bots#6-botfather) and get your bot token 25 | 4. Update the `main.py` file with your bot token 26 | 5. Run the bot using `python main.py` 27 | 28 | Once the bot is running, users can interact with it by messaging it on Telegram. They can use the `/start` command to begin the referral process and receive their referral link. They can then share this link with their friends, who can use it to join the bot. The bot will automatically keep track of successful referrals and assign rewards accordingly. 29 | 30 | ## 🛠️ Language/Framework Used 31 | 32 | ![Python version](https://img.shields.io/badge/python-3.9-blue) 33 | ![PyTelegramBotAPI version](https://img.shields.io/badge/PyTelegramBotAPI-3.8.2-green) 34 | 35 | ## 🎥 Video Tutorial 36 | 37 | [![Watch the video](https://img.youtube.com/vi/z1UY8UjQpKw/0.jpg)](https://www.youtube.com/watch?v=z1UY8UjQpKw) 38 | 39 | ## 👨‍💻 Author 40 | 41 | This project was created by [Arman Idrisi](https://github.com/Armanidrisi). 42 | 43 | ## 📝 License 44 | 45 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 46 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import time 2 | import json 3 | import telebot 4 | 5 | ##TOKEN DETAILS 6 | TOKEN = "TRON" 7 | 8 | BOT_TOKEN = "5710284858:AAHcIDYAtWAC01p8BsHRl4cIwhcKpBqNlTQ" 9 | PAYMENT_CHANNEL = "@testpostchnl" #add payment channel here including the '@' sign 10 | OWNER_ID = 5151868182 #write owner's user id here.. get it from @MissRose_Bot by /id 11 | CHANNELS = ["@testpostchnl"] #add channels to be checked here in the format - ["Channel 1", "Channel 2"] 12 | #you can add as many channels here and also add the '@' sign before channel username 13 | Daily_bonus = 1 #Put daily bonus amount here! 14 | Mini_Withdraw = 0.5 #remove 0 and add the minimum withdraw u want to set 15 | Per_Refer = 0.0001 #add per refer bonus here 16 | 17 | bot = telebot.TeleBot(BOT_TOKEN) 18 | 19 | def check(id): 20 | for i in CHANNELS: 21 | check = bot.get_chat_member(i, id) 22 | if check.status != 'left': 23 | pass 24 | else: 25 | return False 26 | return True 27 | bonus = {} 28 | 29 | def menu(id): 30 | keyboard = telebot.types.ReplyKeyboardMarkup(True) 31 | keyboard.row('🆔 Account') 32 | keyboard.row('🙌🏻 Referrals', '🎁 Bonus', '💸 Withdraw') 33 | keyboard.row('⚙️ Set Wallet', '📊Statistics') 34 | bot.send_message(id, "*🏡 Home*", parse_mode="Markdown", 35 | reply_markup=keyboard) 36 | 37 | @bot.message_handler(commands=['start']) 38 | def start(message): 39 | try: 40 | user = message.chat.id 41 | msg = message.text 42 | if msg == '/start': 43 | user = str(user) 44 | data = json.load(open('users.json', 'r')) 45 | if user not in data['referred']: 46 | data['referred'][user] = 0 47 | data['total'] = data['total'] + 1 48 | if user not in data['referby']: 49 | data['referby'][user] = user 50 | if user not in data['checkin']: 51 | data['checkin'][user] = 0 52 | if user not in data['DailyQuiz']: 53 | data['DailyQuiz'][user] = "0" 54 | if user not in data['balance']: 55 | data['balance'][user] = 0 56 | if user not in data['wallet']: 57 | data['wallet'][user] = "none" 58 | if user not in data['withd']: 59 | data['withd'][user] = 0 60 | if user not in data['id']: 61 | data['id'][user] = data['total']+1 62 | json.dump(data, open('users.json', 'w')) 63 | print(data) 64 | markup = telebot.types.InlineKeyboardMarkup() 65 | markup.add(telebot.types.InlineKeyboardButton( 66 | text='🤼‍♂️ Joined', callback_data='check')) 67 | msg_start = "*🍔 To Use This Bot You Need To Join This Channel - " 68 | for i in CHANNELS: 69 | msg_start += f"\n➡️ {i}\n" 70 | msg_start += "*" 71 | bot.send_message(user, msg_start, 72 | parse_mode="Markdown", reply_markup=markup) 73 | else: 74 | 75 | data = json.load(open('users.json', 'r')) 76 | user = message.chat.id 77 | user = str(user) 78 | refid = message.text.split()[1] 79 | if user not in data['referred']: 80 | data['referred'][user] = 0 81 | data['total'] = data['total'] + 1 82 | if user not in data['referby']: 83 | data['referby'][user] = refid 84 | if user not in data['checkin']: 85 | data['checkin'][user] = 0 86 | if user not in data['DailyQuiz']: 87 | data['DailyQuiz'][user] = 0 88 | if user not in data['balance']: 89 | data['balance'][user] = 0 90 | if user not in data['wallet']: 91 | data['wallet'][user] = "none" 92 | if user not in data['withd']: 93 | data['withd'][user] = 0 94 | if user not in data['id']: 95 | data['id'][user] = data['total']+1 96 | json.dump(data, open('users.json', 'w')) 97 | print(data) 98 | markups = telebot.types.InlineKeyboardMarkup() 99 | markups.add(telebot.types.InlineKeyboardButton( 100 | text='🤼‍♂️ Joined', callback_data='check')) 101 | msg_start = "*🍔 To Use This Bot You Need To Join This Channel - \n➡️ @ Fill your channels at line: 101 and 157*" 102 | bot.send_message(user, msg_start, 103 | parse_mode="Markdown", reply_markup=markups) 104 | except: 105 | bot.send_message(message.chat.id, "This command having error pls wait for ficing the glitch by admin") 106 | bot.send_message(OWNER_ID, "Your bot got an error fix it fast!\n Error on command: "+message.text) 107 | return 108 | 109 | @bot.callback_query_handler(func=lambda call: True) 110 | def query_handler(call): 111 | try: 112 | ch = check(call.message.chat.id) 113 | if call.data == 'check': 114 | if ch == True: 115 | data = json.load(open('users.json', 'r')) 116 | user_id = call.message.chat.id 117 | user = str(user_id) 118 | bot.answer_callback_query( 119 | callback_query_id=call.id, text='✅ You joined Now yu can earn money') 120 | bot.delete_message(call.message.chat.id, call.message.message_id) 121 | if user not in data['refer']: 122 | data['refer'][user] = True 123 | 124 | if user not in data['referby']: 125 | data['referby'][user] = user 126 | json.dump(data, open('users.json', 'w')) 127 | if int(data['referby'][user]) != user_id: 128 | ref_id = data['referby'][user] 129 | ref = str(ref_id) 130 | if ref not in data['balance']: 131 | data['balance'][ref] = 0 132 | if ref not in data['referred']: 133 | data['referred'][ref] = 0 134 | json.dump(data, open('users.json', 'w')) 135 | data['balance'][ref] += Per_Refer 136 | data['referred'][ref] += 1 137 | bot.send_message( 138 | ref_id, f"*🏧 New Referral on Level 1, You Got : +{Per_Refer} {TOKEN}*", parse_mode="Markdown") 139 | json.dump(data, open('users.json', 'w')) 140 | return menu(call.message.chat.id) 141 | 142 | else: 143 | json.dump(data, open('users.json', 'w')) 144 | return menu(call.message.chat.id) 145 | 146 | else: 147 | json.dump(data, open('users.json', 'w')) 148 | menu(call.message.chat.id) 149 | 150 | else: 151 | bot.answer_callback_query( 152 | callback_query_id=call.id, text='❌ You not Joined') 153 | bot.delete_message(call.message.chat.id, call.message.message_id) 154 | markup = telebot.types.InlineKeyboardMarkup() 155 | markup.add(telebot.types.InlineKeyboardButton( 156 | text='🤼‍♂️ Joined', callback_data='check')) 157 | msg_start = "*🍔 To Use This Bot You Need To Join This Channel - \n➡️ @ Fill your channels at line: 101 and 157*" 158 | bot.send_message(call.message.chat.id, msg_start, 159 | parse_mode="Markdown", reply_markup=markup) 160 | except: 161 | bot.send_message(call.message.chat.id, "This command having error pls wait for ficing the glitch by admin") 162 | bot.send_message(OWNER_ID, "Your bot got an error fix it fast!\n Error on command: "+call.data) 163 | return 164 | 165 | @bot.message_handler(content_types=['text']) 166 | def send_text(message): 167 | try: 168 | if message.text == '🆔 Account': 169 | data = json.load(open('users.json', 'r')) 170 | accmsg = '*👮 User : {}\n\n⚙️ Wallet : *`{}`*\n\n💸 Balance : *`{}`* {}*' 171 | user_id = message.chat.id 172 | user = str(user_id) 173 | 174 | if user not in data['balance']: 175 | data['balance'][user] = 0 176 | if user not in data['wallet']: 177 | data['wallet'][user] = "none" 178 | 179 | json.dump(data, open('users.json', 'w')) 180 | 181 | balance = data['balance'][user] 182 | wallet = data['wallet'][user] 183 | msg = accmsg.format(message.from_user.first_name, 184 | wallet, balance, TOKEN) 185 | bot.send_message(message.chat.id, msg, parse_mode="Markdown") 186 | if message.text == '🙌🏻 Referrals': 187 | data = json.load(open('users.json', 'r')) 188 | ref_msg = "*⏯️ Total Invites : {} Users\n\n👥 Refferrals System\n\n1 Level:\n🥇 Level°1 - {} {}\n\n🔗 Referral Link ⬇️\n{}*" 189 | 190 | bot_name = bot.get_me().username 191 | user_id = message.chat.id 192 | user = str(user_id) 193 | 194 | if user not in data['referred']: 195 | data['referred'][user] = 0 196 | json.dump(data, open('users.json', 'w')) 197 | 198 | ref_count = data['referred'][user] 199 | ref_link = 'https://telegram.me/{}?start={}'.format( 200 | bot_name, message.chat.id) 201 | msg = ref_msg.format(ref_count, Per_Refer, TOKEN, ref_link) 202 | bot.send_message(message.chat.id, msg, parse_mode="Markdown") 203 | if message.text == "⚙️ Set Wallet": 204 | user_id = message.chat.id 205 | user = str(user_id) 206 | 207 | keyboard = telebot.types.ReplyKeyboardMarkup(True) 208 | keyboard.row('🚫 Cancel') 209 | send = bot.send_message(message.chat.id, "_⚠️Send your TRX Wallet Address._", 210 | parse_mode="Markdown", reply_markup=keyboard) 211 | # Next message will call the name_handler function 212 | bot.register_next_step_handler(message, trx_address) 213 | if message.text == "🎁 Bonus": 214 | user_id = message.chat.id 215 | user = str(user_id) 216 | cur_time = int((time.time())) 217 | data = json.load(open('users.json', 'r')) 218 | #bot.send_message(user_id, "*🎁 Bonus Button is Under Maintainance*", parse_mode="Markdown") 219 | if (user_id not in bonus.keys()) or (cur_time - bonus[user_id] > 60*60*24): 220 | data['balance'][(user)] += Daily_bonus 221 | bot.send_message( 222 | user_id, f"Congrats you just received {Daily_bonus} {TOKEN}") 223 | bonus[user_id] = cur_time 224 | json.dump(data, open('users.json', 'w')) 225 | else: 226 | bot.send_message( 227 | message.chat.id, "❌*You can only take bonus once every 24 hours!*",parse_mode="markdown") 228 | return 229 | 230 | if message.text == "📊Statistics": 231 | user_id = message.chat.id 232 | user = str(user_id) 233 | data = json.load(open('users.json', 'r')) 234 | msg = "*📊 Total members : {} Users\n\n🥊 Total successful Withdraw : {} {}*" 235 | msg = msg.format(data['total'], data['totalwith'], TOKEN) 236 | bot.send_message(user_id, msg, parse_mode="Markdown") 237 | return 238 | 239 | if message.text == "💸 Withdraw": 240 | user_id = message.chat.id 241 | user = str(user_id) 242 | 243 | data = json.load(open('users.json', 'r')) 244 | if user not in data['balance']: 245 | data['balance'][user] = 0 246 | if user not in data['wallet']: 247 | data['wallet'][user] = "none" 248 | json.dump(data, open('users.json', 'w')) 249 | 250 | bal = data['balance'][user] 251 | wall = data['wallet'][user] 252 | if wall == "none": 253 | bot.send_message(user_id, "_❌ wallet Not set_", 254 | parse_mode="Markdown") 255 | return 256 | if bal >= Mini_Withdraw: 257 | bot.send_message(user_id, "_Enter Your Amount_", 258 | parse_mode="Markdown") 259 | bot.register_next_step_handler(message, amo_with) 260 | else: 261 | bot.send_message( 262 | user_id, f"_❌Your balance low you should have at least {Mini_Withdraw} {TOKEN} to Withdraw_", parse_mode="Markdown") 263 | return 264 | except: 265 | bot.send_message(message.chat.id, "This command having error pls wait for ficing the glitch by admin") 266 | bot.send_message(OWNER_ID, "Your bot got an error fix it fast!\n Error on command: "+message.text) 267 | return 268 | 269 | def trx_address(message): 270 | try: 271 | if message.text == "🚫 Cancel": 272 | return menu(message.chat.id) 273 | if len(message.text) == 34: 274 | user_id = message.chat.id 275 | user = str(user_id) 276 | data = json.load(open('users.json', 'r')) 277 | data['wallet'][user] = message.text 278 | 279 | bot.send_message(message.chat.id, "*💹Your Trx wallet set to " + 280 | data['wallet'][user]+"*", parse_mode="Markdown") 281 | json.dump(data, open('users.json', 'w')) 282 | return menu(message.chat.id) 283 | else: 284 | bot.send_message( 285 | message.chat.id, "*⚠️ It's Not a Valid Trx Address!*", parse_mode="Markdown") 286 | return menu(message.chat.id) 287 | except: 288 | bot.send_message(message.chat.id, "This command having error pls wait for ficing the glitch by admin") 289 | bot.send_message(OWNER_ID, "Your bot got an error fix it fast!\n Error on command: "+message.text) 290 | return 291 | 292 | def amo_with(message): 293 | try: 294 | user_id = message.chat.id 295 | amo = message.text 296 | user = str(user_id) 297 | data = json.load(open('users.json', 'r')) 298 | if user not in data['balance']: 299 | data['balance'][user] = 0 300 | if user not in data['wallet']: 301 | data['wallet'][user] = "none" 302 | json.dump(data, open('users.json', 'w')) 303 | 304 | bal = data['balance'][user] 305 | wall = data['wallet'][user] 306 | msg = message.text 307 | if msg.isdigit() == False: 308 | bot.send_message( 309 | user_id, "_📛 Invaild value. Enter only numeric value. Try again_", parse_mode="Markdown") 310 | return 311 | if int(message.text) < Mini_Withdraw: 312 | bot.send_message( 313 | user_id, f"_❌ Minimum withdraw {Mini_Withdraw} {TOKEN}_", parse_mode="Markdown") 314 | return 315 | if int(message.text) > bal: 316 | bot.send_message( 317 | user_id, "_❌ You Can't withdraw More than Your Balance_", parse_mode="Markdown") 318 | return 319 | amo = int(amo) 320 | data['balance'][user] -= int(amo) 321 | data['totalwith'] += int(amo) 322 | bot_name = bot.get_me().username 323 | json.dump(data, open('users.json', 'w')) 324 | bot.send_message(user_id, "✅* Withdraw is request to our owner automatically\n\n💹 Payment Channel :- "+PAYMENT_CHANNEL +"*", parse_mode="Markdown") 325 | 326 | markupp = telebot.types.InlineKeyboardMarkup() 327 | markupp.add(telebot.types.InlineKeyboardButton(text='🍀 BOT LINK', url=f'https://telegram.me/{bot_name}?start={OWNER_ID}')) 328 | 329 | send = bot.send_message(PAYMENT_CHANNEL, "✅* New Withdraw\n\n⭐ Amount - "+str(amo)+f" {TOKEN}\n🦁 User - @"+message.from_user.username+"\n💠 Wallet* - `"+data['wallet'][user]+"`\n☎️ *User Referrals = "+str( 330 | data['referred'][user])+"\n\n🏖 Bot Link - @"+bot_name+"\n⏩ Please wait our owner will confrim it*", parse_mode="Markdown", disable_web_page_preview=True, reply_markup=markupp) 331 | except: 332 | bot.send_message(message.chat.id, "This command having error pls wait for ficing the glitch by admin") 333 | bot.send_message(OWNER_ID, "Your bot got an error fix it fast!\n Error on command: "+message.text) 334 | return 335 | 336 | if __name__ == '__main__': 337 | bot.polling(none_stop=True) 338 | --------------------------------------------------------------------------------