forked from mujadmani/Easy-Telegram-Airdrop-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
615 lines (516 loc) Β· 22.3 KB
/
bot.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
# %% Dependencies
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, Update, InlineKeyboardMarkup
from bson.json_util import dumps
from multicolorcaptcha import CaptchaGenerator
from jokes import getJoke
from telegram.ext import (
Updater,
CommandHandler,
MessageHandler,
Filters,
ConversationHandler,
CallbackContext,
PicklePersistence,
)
from telegram.utils import helpers
import telegram
import pymongo
import logging
import os
import pickle
# from dotenv import load_dotenv
# load_dotenv()
USERINFO = {} # holds user information
CAPTCHA_DATA = {}
# %% ENV VARIABLES
COIN_SYMBOL = os.environ["COIN_SYMBOL"]
COIN_NAME = os.environ["COIN_NAME"]
AIRDROP_AMOUNT = os.environ["AIRDROP_AMOUNT"]
AIRDROP_AMOUNT = "{:,.2f}".format(float(AIRDROP_AMOUNT))
AIRDROP_DATE = os.environ["AIRDROP_DATE"]
BOT_TOKEN = os.environ["BOT_TOKEN"]
AIRDROP_NETWORK = os.environ["AIRDROP_NETWORK"]
REFERRAL_REWARD = float(os.environ["REFERRAL_REWARD"])
COIN_PRICE = os.environ["COIN_PRICE"]
WEBSITE_URL = os.environ["WEBSITE_URL"]
DB_URI = os.environ["DB_URI"]
EXPLORER_URL = os.environ["EXPLORER_URL"]
ADMIN_USERNAME = os.environ["ADMIN_USERNAME"]
TWITTER_LINKS = os.environ["TWITTER_LINKS"]
TELEGRAM_LINKS = os.environ["TELEGRAM_LINKS"]
DISCORD_LINKS = os.environ["DISCORD_LINKS"]
MAX_USERS = int(os.environ["MAX_USERS"])
MAX_REFS = int(os.environ["MAX_REFS"])
CAPTCHA_ENABLED = os.environ["CAPTCHA_ENABLED"]
TWITTER_LINKS = TWITTER_LINKS.split(",")
TELEGRAM_LINKS = TELEGRAM_LINKS.split(",")
DISCORD_LINKS = DISCORD_LINKS.split(",")
TWITTER_LINKS = "\n".join(TWITTER_LINKS)
TELEGRAM_LINKS = "\n".join(TELEGRAM_LINKS)
DISCORD_LINKS = "\n".join(DISCORD_LINKS)
STATUS_PATH = "./conversationbot/botconfig.p"
if os.path.exists(STATUS_PATH):
BOT_STATUS = {}
pickle.load(open(STATUS_PATH, "rb"))
else:
BOT_STATUS = {"status": "ON"}
# %% MONGODB CONNECTION
CONNECTION_STRING = os.environ.get("DB_URI")
myclient = pymongo.MongoClient(CONNECTION_STRING)
mydb = myclient["airdrop"]
users = mydb["users"]
users.create_index([('ref', pymongo.TEXT)], name='search_index', default_language='english')
users.create_index("userId")
# %% Setting up things
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
print(BOT_TOKEN)
persistence = PicklePersistence(filename='conversationbot/conversationbot')
updater = Updater(token=BOT_TOKEN, use_context=True, persistence=persistence)
dispatcher = updater.dispatcher
# %% Message Strings
if(COIN_PRICE == "0"):
SYMBOL = ""
else:
SYMBOL = f"\nβοΈ 1 {COIN_SYMBOL} = {COIN_PRICE}"
if(EXPLORER_URL != ""):
EXPLORER_URL = f"\nContract: {EXPLORER_URL}"
if(WEBSITE_URL != ""):
WEBSITE_URL = f"\nWebsite: {WEBSITE_URL}"
WELCOME_MESSAGE = f"""
Hello, NAME! I am your friendly {COIN_NAME} Airdrop bot
{SYMBOL}
βοΈ For Joining - Get {AIRDROP_AMOUNT} {COIN_SYMBOL}
βοΈ For each referral - Get {"{:,.2f}".format(REFERRAL_REWARD)} {COIN_SYMBOL}
πBy Participating you are agreeing to the {COIN_NAME} (Airdrop) Program Terms and Conditions. Please see pinned post for more information.
Click "π Join Airdrop" to proceed"""
tasks = ""
PROCEED_MESSAGE = f"""
πΉ Airdrop Reward = *{AIRDROP_AMOUNT} {COIN_SYMBOL}*
πΉ Extra reward per referral = *{"{:,.2f}".format(REFERRAL_REWARD)} {COIN_SYMBOL}* (max {MAX_REFS}){SYMBOL}
π’ Airdrop Rules
βοΈ Mandatory Tasks:
- Join our Telegram group(s)
- Follow our Twitter page(s)
- Join our Discord server(s)
NOTE: Users found cheating would be disqualified & banned immediately.
Airdrop Date: *{AIRDROP_DATE}*{EXPLORER_URL}
{WEBSITE_URL}
"""
MAKE_SURE_TELEGRAM = f"""
πΉ Do not forget to join our Telegram group(s)
{TELEGRAM_LINKS}
"""
FOLLOW_TWITTER_TEXT = f"""
πΉ Follow our Twitter page(s)
{TWITTER_LINKS}
"""
JOIN_DISCORD_TEXT = f'''
πΉ Join our Discord server(s)
{DISCORD_LINKS}
'''
SUBMIT_BEP20_TEXT = f"""
Type in *your Wallet Address*
Please make sure your wallet supports the *{AIRDROP_NETWORK}*
Example:
0xdEAD000000000000000042069420694206942069
_Incorrect Details? Use_ /restart _command to start over._
"""
JOINED = f"""
Thank you!
Rewards would be sent out automatically to your {AIRDROP_NETWORK} address on the {AIRDROP_DATE}
Don't forget to:
πΈ Stay in the telegram channels
πΈ Follow all the social media channels for the updates
Your personal referral link (+{"{:,.2f}".format(REFERRAL_REWARD)} {COIN_SYMBOL} for each referral)
REPLACEME
"""
WITHDRAWAL_TEXT = f"""
Withdrawals would be sent out automatically to your {AIRDROP_NETWORK} address on the {AIRDROP_DATE}
NOTE: Users found cheating would be disqualified & banned immediately."""
BALANCE_TEXT = f"""
{COIN_NAME} Airdrop Balance: *IARTBALANCE*
Referral Balance: *REFERRALBALANCE*
"""
# %% Functions
def setBotStatus(status):
BOT_STATUS["status"] = status
pickle.dump(BOT_STATUS, open(STATUS_PATH, "wb"))
def getUserInfo(id):
user = ""
for x in users.find({"userId": id}):
user = x
refs = users.find({"ref": str(id)})
user["refCount"] = refs.count()
# if "refCount" not in user:
# user["refCount"] = 0
# user["refList"] = []
return user
def maxNumberReached(update, context):
update.message.reply_text("Hey! Thanks for your interest but it seems like the maximum amount of users has been reached.")
return ConversationHandler.END
def botStopped(update, context):
update.message.reply_text("The airdrop has been completed. Thanks for you interest.")
return ConversationHandler.END
def botPaused(update, context):
update.message.reply_text("The airdrop has been temporarily paused, please try again later", reply_markup=ReplyKeyboardMarkup([["/start"]]))
return ConversationHandler.END
def checkCaptcha(update, context):
user = update.message.from_user
text = update.message.text
if CAPTCHA_DATA[user.id] != text:
update.message.reply_text("Invalid captcha!")
return generateCaptcha(update, context)
else:
NAME = getName(user)
update.message.reply_text(text="Correct!",
parse_mode=telegram.ParseMode.MARKDOWN)
update.message.reply_text(text=WELCOME_MESSAGE.replace("NAME", NAME),
reply_markup=ReplyKeyboardMarkup([['π Join Airdrop']]), parse_mode=telegram.ParseMode.MARKDOWN)
CAPTCHA_DATA[user.id] = True
return PROCEED
def start(update, context):
update.message.reply_text(text="Starting bot",reply_markup=ReplyKeyboardMarkup([["/start"]]))
user = update.message.from_user
CAPTCHA_DATA[user.id] = False
if not user.id in USERINFO:
USERINFO[user.id] = {}
refferal = update.message.text.replace("/start", "").strip()
if refferal != "" and refferal != user.id and "ref" not in USERINFO[user.id]:
USERINFO[user.id]["ref"] = refferal
print("Using refferal")
else:
USERINFO[user.id]["ref"] = False
NAME = getName(user)
if(getUserInfo(user.id) != ""):
update.message.reply_text(text="It seems like you have already joined!", reply_markup=ReplyKeyboardMarkup(reply_keyboard))
return LOOP
count = users.count()
if(count >= MAX_USERS):
return maxNumberReached(update, context)
if(BOT_STATUS["status"] == "STOPPED"):
return botStopped(update, context)
if(BOT_STATUS["status"] == "PAUSED"):
return botPaused(update, context)
if(CAPTCHA_ENABLED == "YES" and CAPTCHA_DATA[user.id] != True):
return generateCaptcha(update, context)
else:
update.message.reply_text(text=WELCOME_MESSAGE.replace("NAME", NAME),
reply_markup=ReplyKeyboardMarkup([['π Join Airdrop']]), parse_mode=telegram.ParseMode.MARKDOWN)
return PROCEED
def generateCaptcha(update, context):
user = update.message.from_user
CAPCTHA_SIZE_NUM = 2
generator = CaptchaGenerator(CAPCTHA_SIZE_NUM)
captcha = generator.gen_captcha_image(difficult_level=3)
image = captcha["image"]
characters = captcha["characters"]
CAPTCHA_DATA[user.id] = characters
filename = f"{user.id}.png"
image.save(filename, "png")
photo = open(filename, "rb")
update.message.reply_photo(photo)
update.message.reply_text("Please type in the numbers on the image",reply_markup=ReplyKeyboardRemove())
return CAPTCHASTATE
def submit_details(update, context):
update.message.reply_text(text=PROCEED_MESSAGE, parse_mode=telegram.ParseMode.MARKDOWN)
update.message.reply_text(text="Please click on \"Submit Details\" to proceed", parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardMarkup(
[["Submit Details"], ["Cancel"]]
))
return FOLLOW_TELEGRAM
def follow_telegram(update, context):
update.message.reply_text(text=MAKE_SURE_TELEGRAM)
update.message.reply_text(text="Please click on \"Done\" to proceed", parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardMarkup(
[["Done"], ["Cancel"]]
))
return FOLLOW_TWITTER
def check_joined_channel(user):
try:
for link in TELEGRAM_LINKS.split("\n"):
link ="@"+link.split("/")[-1]
reply = telegram.bot.Bot(BOT_TOKEN).get_chat_member(link,user)
if reply.status in ('left','kicked'):
return False
except:
return False
return True
def follow_twitter(update, context):
if not check_joined_channel(user = update.message.from_user.id):
update.message.reply_text(text=f'You have not joined\n {TELEGRAM_LINKS}\nPlease join first and click on "Done" to proceed', reply_markup=ReplyKeyboardMarkup(
[["Done"], ["Cancel"],["/restart"]]
))
return FOLLOW_TWITTER
update.message.reply_text(text=FOLLOW_TWITTER_TEXT, parse_mode=telegram.ParseMode.MARKDOWN)
update.message.reply_text(text="Type in the link to *your Twitter profile* to proceed.\n\nExample: \nhttps://twitter.com/example", parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardMarkup(
[["Cancel"]]
))
return JOIN_DISCORD
def submit_address(update, context):
user = update.message.from_user
if not user.id in USERINFO:
return startAgain(update, context)
if users.find({"twitter_username": update.message.text.strip()}).count() != 0:
update.message.reply_text(text="Twitter Link Already Exists. Try again!\n\nExample: \nhttps://twitter.com/example", parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardMarkup(
[["Cancel"]]
))
return JOIN_DISCORD
USERINFO[user.id].update({"twitter_username": update.message.text.strip()})
update.message.reply_text(text=JOIN_DISCORD_TEXT, parse_mode=telegram.ParseMode.MARKDOWN)
update.message.reply_text(text="Type in *your Discord username* to proceed.\n\nExample: \nExample#1234 \n\n_Incorrect Details? Use_ /restart _command to start over._", parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardMarkup(
[["Cancel"],["/restart"]]
))
return SUBMIT_ADDRESS
def submit_discord(update, context):
user = update.message.from_user
if not user.id in USERINFO:
return startAgain(update, context)
if users.find({"discord_username": update.message.text.strip()}).count() != 0:
update.message.reply_text(text="Discord Username Already Exists. Try again!\n\nExample: \nExample#1234", parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardMarkup(
[["Cancel"],["/restart"]]
))
return SUBMIT_ADDRESS
USERINFO[user.id].update({"discord_username": update.message.text.strip()})
update.message.reply_text(text=SUBMIT_BEP20_TEXT, parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardMarkup(
[["Cancel"],["/restart"]]
))
return END_CONVERSATION
def getName(user):
first = user["first_name"]
last = user["last_name"]
if(last == None):
last = ""
if(first == None):
first = ""
return str(first + " " + last).strip()
def end_conversation(update, context):
user = update.message.from_user
if not user.id in USERINFO:
return startAgain(update, context)
if users.find({"bep20": update.message.text}).count() != 0:
update.message.reply_text(text="Wallet Address Already Exists. Try again!\n\nExample: \n0xdEAD000000000000000042069420694206942069", parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardMarkup(
[["Cancel"],["/restart"]]
))
return END_CONVERSATION
USERINFO[user.id].update({"bep20": update.message.text})
USERINFO[user.id].update({"userId": user.id})
USERINFO[user.id].update({"chatId": update.effective_chat.id})
USERINFO[user.id].update({"name": getName(user)})
USERINFO[user.id].update({"username": user.username})
print(USERINFO[user.id])
users.insert_one(USERINFO[user.id])
url = f"https://t.me/{context.bot.username}?start={user.id}"
# check refferal
# if USERINFO[user.id]["ref"] != False:
# refferal = USERINFO[user.id]["ref"]
# info = getUserInfo(int(refferal))
# print("Referall step 1")
# print(refferal)
# print(info)
# if info != "":
# if str(user.id) in info["refList"]:
# info["refCount"] += 1
# info["refList"].append(str(user.id))
# users.update({"userId": refferal}, info)
# print("Updated refferal")
update.message.reply_text(JOINED.replace("REPLACEME", url), reply_markup=ReplyKeyboardMarkup(reply_keyboard))
return LOOP
def getRandomJoke():
return getJoke()
def sureWantTo(update, context):
user = update.message.from_user
message = update.message.text
print(message)
if(message == "YES"):
update.message.reply_text(
'Goodbye!', reply_markup=ReplyKeyboardMarkup([['/start']])
)
users.delete_one({"userId": user.id})
return ConversationHandler.END
if(message == "NO"):
update.message.reply_text(
'Oh thanks god, I thought I lost you', reply_markup=ReplyKeyboardMarkup(reply_keyboard)
)
return LOOP
def cancel(update: Update, context: CallbackContext) -> int:
"""Cancels and ends the conversation."""
user = update.message.from_user
update.message.reply_text(
'Goodbye!', reply_markup=ReplyKeyboardMarkup([['/start']])
)
return ConversationHandler.END
def startAgain(update: Update, context: CallbackContext) -> int:
"""Cancels and ends the conversation."""
user = update.message.from_user
update.message.reply_text(
'An error occured, please start the bot again.', reply_markup=ReplyKeyboardMarkup([['/start']])
)
return ConversationHandler.END
def loopAnswer(update, context):
user = update.message.from_user
info = getUserInfo(user.id)
print(info)
message = update.message.text
reply = ""
if(message == "π° Balance"):
refbal = "{:,.2f}".format(info["refCount"]*REFERRAL_REWARD)
if(refbal == ""):
refbal = "0"
reply = BALANCE_TEXT.replace("IARTBALANCE", AIRDROP_AMOUNT).replace("REFERRALBALANCE", refbal)
if(message == "βΉοΈ Airdrop Info"):
reply = PROCEED_MESSAGE
if(message == "πΈ Withdrawal"):
reply = WITHDRAWAL_TEXT
if(message == "π Ref Link"):
reply = f"""
Here is *your referral link*
[https://t.me/{context.bot.username}?start={user.id}](https://t.me/{context.bot.username}?start={user.id})
"""
if(message == "β Quit Airdrop"):
update.message.reply_text("Are you sure want to quit the Airdrop? All your data will be deleted", reply_markup=ReplyKeyboardMarkup([['YES'], ['NO']]))
return SUREWANTTO
if(message == "πΎ My Data"):
name = str(info["name"])
refbal = "{:,.2f}".format(info["refCount"]*REFERRAL_REWARD)
balance = BALANCE_TEXT.replace("IARTBALANCE", AIRDROP_AMOUNT).replace("REFERRALBALANCE", refbal)
refferals = str(info["refCount"])
bep20Address = str(info["bep20"])
twitterUsername = str(info["twitter_username"])
discordUsername = str(info.get("discord_username",""))
reply = f"""
Name: {name}
Referrals: {refferals}
{AIRDROP_NETWORK} address: {bep20Address}
Twitter Username: {twitterUsername}
Discord Username: {discordUsername}
_Incorrect Details? Use_ /restart _command to start over._
Don't worry, your referrals are safe.
"""
if(reply == ""):
joke = getRandomJoke()
joke = joke.split(" -")
reply = f"""
I'm not sure what you meant, but here is a joke for you!
> {joke[0]}
- {joke[1]}
"""
update.message.reply_text(reply, reply_markup=ReplyKeyboardMarkup(reply_keyboard), parse_mode=telegram.ParseMode.MARKDOWN)
return LOOP
def error_airdrop(update, context):
update.message.reply_text("Please click \"π Join Airdrop\" to proceed",reply_markup=ReplyKeyboardMarkup([['π Join Airdrop']]),)
return PROCEED
def error_submitdetails(update, context):
update.message.reply_text("Please click on \"Submit Details\" to proceed, or \"Cancel\" to cancel the Airdrop",reply_markup=ReplyKeyboardMarkup(
[["Submit Details"], ["Cancel"]]
))
return FOLLOW_TELEGRAM
def error_telegram(update,context):
update.message.reply_text('Please click on "Done" to proceed, or "Cancel" to cancel the Airdrop',reply_markup=ReplyKeyboardMarkup(
[["Done"], ["Cancel"]]
))
return FOLLOW_TWITTER
def error_twitter(update,context):
update.message.reply_text(text="Invalid Twitter Link. Try again! \n\nExample: \nhttps://twitter.com/example", parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardMarkup(
[["Cancel"]]
))
return JOIN_DISCORD
def error_discord(update,context):
update.message.reply_text(text="Invalid Discord Username. Try again!\n\nExample: \nExample#1234", parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardMarkup(
[["Cancel"],["/restart"]]
))
return SUBMIT_ADDRESS
def error_bsc(update,context):
update.message.reply_text(text="Invalid Wallet Address. Try again!\n\nExample: \n0xdEAD000000000000000042069420694206942069", parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardMarkup(
[["Cancel"],["/restart"]]
))
return END_CONVERSATION
def restart(update,context):
try:
users.delete_one({"userId": update.message.from_user.id})
except:
pass
return start(update,context)
# %% Start bot
reply_keyboard = [
["π° Balance", "βΉοΈ Airdrop Info"],
["πΈ Withdrawal", "π Ref Link"],
["πΎ My Data", "β Quit Airdrop"]
]
PROCEED, FOLLOW_TELEGRAM, FOLLOW_TWITTER, SUBMIT_ADDRESS, JOIN_DISCORD,END_CONVERSATION, LOOP, SUREWANTTO, CAPTCHASTATE = range(9)
cancelHandler = MessageHandler(Filters.regex('^Cancel$'), cancel)
reset_handler = CommandHandler('restart',restart)
states = {
PROCEED: [MessageHandler(Filters.regex('^π Join Airdrop$'), submit_details), cancelHandler,reset_handler, MessageHandler(Filters.regex(".*"),error_airdrop)],
FOLLOW_TELEGRAM: [MessageHandler(Filters.regex('^Submit Details$'), follow_telegram), cancelHandler,reset_handler, MessageHandler(Filters.regex(".*"),error_submitdetails)],
FOLLOW_TWITTER: [MessageHandler(Filters.regex('^Done$'), follow_twitter), cancelHandler,reset_handler, MessageHandler(Filters.regex(".*"),error_telegram)],
JOIN_DISCORD : [cancelHandler,MessageHandler(Filters.regex('^https://twitter.com/.*'), submit_address),reset_handler,MessageHandler(Filters.regex(".*"),error_twitter)],
SUBMIT_ADDRESS: [cancelHandler, MessageHandler(Filters.regex('^.*#[0-9]{4}$'), submit_discord),reset_handler,MessageHandler(Filters.regex(".*"),error_discord)],
END_CONVERSATION: [cancelHandler, MessageHandler(Filters.regex('^0x[a-fA-F0-9]{40}$'), end_conversation),reset_handler,MessageHandler(Filters.regex(".*"),error_bsc)],
LOOP: [reset_handler,MessageHandler(
Filters.text, loopAnswer
)],
SUREWANTTO: [MessageHandler(Filters.regex('^(YES|NO)$'), sureWantTo)],
CAPTCHASTATE: [MessageHandler(Filters.text, checkCaptcha)]
}
def error_start(update,context):
update.message.reply_text(text="Use /start command to start the Airdrop bot",parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=ReplyKeyboardMarkup(
[["/start"]]
))
conv_handler = ConversationHandler(
entry_points=[CommandHandler('start', start),MessageHandler(Filters.text,error_start)],
states=states,
fallbacks=[],
name="main",
persistent=True,
)
# %% Admin commands
def get_refcount_balance(userid):
info = getUserInfo(userid)
return info["refCount"],float(info["refCount"])*float(REFERRAL_REWARD) + float(AIRDROP_AMOUNT.replace(",",""))
def getList(update, context):
user = update.message.from_user
if(user.username != ADMIN_USERNAME):
return
list = users.find({})
with open("users.json", "w") as file:
file.write("[")
for document in list:
document["refcount"],document["balance"] = get_refcount_balance(document["userId"])
file.write(dumps(document))
file.write(",")
file.write("]")
with open("users.json", "r") as file:
update.message.reply_document(document=file, filename="list.json")
def getStats(update, context):
user = update.message.from_user
if(user.username != ADMIN_USERNAME):
return
list = users.find({})
refes = users.find({"ref": {"$ne": False}}).count()
reply = f"""
Currently there are *{list.count()} users* joined the airdrop!
Currently there are *{refes} users* joined by referrals
A total of *{"{:,.2f}".format(float(AIRDROP_AMOUNT.replace(",",""))*list.count())} {COIN_SYMBOL}* will be distributed as participation rewards
A total of *{"{:,.2f}".format(REFERRAL_REWARD*refes)} {COIN_SYMBOL}* referral rewards will be distributed
"""
update.message.reply_text(reply, parse_mode=telegram.ParseMode.MARKDOWN)
def setStatus(update, context):
user = update.message.from_user
if(user.username != ADMIN_USERNAME):
return
arg = context.args[0]
if(arg == "stop"):
setBotStatus("STOPPED")
update.message.reply_text("Airdrop stopped")
if(arg == "pause"):
setBotStatus("PAUSED")
update.message.reply_text("Airdrop paused")
if(arg == "start"):
setBotStatus("ON")
update.message.reply_text("Airdrop started")
dispatcher.add_handler(CommandHandler("list", getList))
dispatcher.add_handler(CommandHandler("stats", getStats))
dispatcher.add_handler(CommandHandler("bot", setStatus))
dispatcher.add_handler(conv_handler)
# %% start the bot
updater.start_polling()
updater.idle()