-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
680 lines (495 loc) · 30.7 KB
/
main.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
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
from logging import exception
import discord
import os
from discord.message import Message
from discord.utils import find
import asyncio
import http.client, json, sys
from utils import *
import mysql.connector
from apscheduler.schedulers.blocking import BlockingScheduler
import moment
from dotenv import load_dotenv
load_dotenv()
client = discord.Client()
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
PASSWORD = os.getenv("PASSWORD")
db = mysql.connector.connect(
host="localhost",
user="root",
password= PASSWORD,
database="CowinBot"
)
cursor = db.cursor()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_guild_join(guild):
general = find(lambda x: x.name == 'general', guild.text_channels)
if general and general.permissions_for(guild.me).send_messages:
await general.send('Hey\nType **help** to know the bot')
@client.event
async def on_message(message):
if message.author == client.user:
return
async def fetch_next_7Days():
dates = []
today = moment.now()
for i in range(0,7):
date_string = today.now().format("DD-MM-YYYY")
dates.append(date_string)
today.add(1,'day')
return dates
async def checkAvailability(district,age,userid):
date_array = await fetch_next_7Days()
for i in date_array:
conn = http.client.HTTPSConnection("cdn-api.co-vin.in")
url = f'https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByDistrict?district_id=" + {district} + "&date=" + {i}'
conn = http.client.HTTPSConnection("cdn-api.co-vin.in")
conn.request("GET",url)
res = conn.getresponse()
print(res)
if res.status == 200:
d = res.read()
data = json.loads(d)
session = data.get('sessions')
validate_slots = filter(lambda x: x.get('min_age_limit') <= age and x.get('available_capacity') > 0, session)
if len(validate_slots) > 0:
data = json.dumps(validate_slots, separators=(None, '\t'))
sessions = json.loads(str(data))
s_str = ''
s_len = len(sessions)
abc = []
for i in range(0,s_len):
s_str = " :hospital:" + "\n" + "**Center Id: ** " + str(sessions[i].get('center_id')) + "\n" +"**Center Name: ** " + str(sessions[i].get('name')) + "\n" + "**Block: **" + str(sessions[i].get('block_name')) + " \n" +"**PIN: **" + str(sessions[i].get('pincode')) + "\n" +"**Fees: **" + str(sessions[i].get('fee_type')) + " \n" + "**Slot Avaliable For Dose 1: **" + str(sessions[i].get('available_capacity_dose1')) + " \n"+ "**Slot Avaliable For Dose 2: **" + str(sessions[i].get('available_capacity_dose2')) + " \n" + "**Slot Avaliable- **" + str(sessions[i].get('available_capacity')) + " \n"+ "**Age: **" + str(sessions[i].get('min_age_limit')) + "+" + " \n" + ":syringe:**Vaccine: **" + str(sessions[i].get('vaccine')) + " \n" +":stopwatch:**Session Timings**:stopwatch:" + "\n" + str(sessions[i].get('slots')) + "\n" + "\n"
abc.push(s_str)
user = await client.fetch_user(userid)
embedVar = discord.Embed(title="Vaccine Avaliable Slots", description=s_str, color=15462131)
embedVar.set_footer(text="Get Vaccinated",icon_url='https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae')
await user.send(embed=embedVar)
else:
user = await client.fetch_user(userid)
await user.send("No Vaccine Avaliable Slots")
def job():
sql = ("SELECT district,age,user_id FROM notify where status = 0")
cursor.execute(sql)
res = cursor.fetchall()
print("cbvh")
for i in range(0,len(res)):
checkAvailability(res[i].district, res[i].age, res[i].userid)
def app():
try:
scheduler = BlockingScheduler()
scheduler.add_job(job, 'interval', hours=1)
scheduler.start()
except Exception as e:
print(e)
if message.content.startswith('hello'):
await message.channel.send('Hello!')
app()
def check(m):
return m.author == message.author
if message.content.startswith('help'):
embedVar = discord.Embed(title="Type the following to perform the steps", description="Thanks For Choosing ME", color=0xFFFFFF,
url='https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae',
)
embedVar.add_field(name="**myInfo**", value="To know your registration details", inline=False)
embedVar.add_field(name="**vaccine**", value="To know available centers", inline=True)
embedVar.add_field(name="**register**", value="For registration", inline=True)
embedVar.add_field(name="**notify**", value="To get notification of the slots", inline=True)
embedVar.add_field(name="**deleteMyInfo**", value="To delete your info", inline=True)
embedVar.add_field(name="**stopNotify**", value="To stop the notification", inline=True)
embedVar.set_author(name='Cowin Bot', icon_url='https://images.vexels.com/media/users/3/140503/isolated/lists/24882e71e8111a13f3f1055c1ad53cf3-hand-with-injection.png', url='https://discordpy.readthedocs.io/en/stable/index.html')
embedVar.set_thumbnail(url='https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae')
embedVar.set_image(url='https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/photo6147825254626602018.jpg?alt=media&token=38ca1f38-ad75-4ad0-b0fe-5ac4fce18d56')
embedVar.set_footer(text='Get Vaccinated', icon_url='https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae')
await message.channel.send(embed=embedVar)
if message.content.startswith('vaccine'):
print("jcvhb")
conn = http.client.HTTPSConnection("cdn-api.co-vin.in")
url = 'https://cdn-api.co-vin.in/api/v2/admin/location/states'
conn = http.client.HTTPSConnection("cdn-api.co-vin.in")
conn.request("GET",url)
res = conn.getresponse()
print(res)
if res.status == 200:
await message.channel.send('Hi Choose You State')
d = res.read()
data = json.loads(d)
state = data.get('states')
arr_len = len(state)
num_str = ''
for i in range(0,arr_len):
state_data = str(state[i].get('state_name')) + " (" + " Id: " + str(data.get('states')[i].get('state_id')) + ")"
num_str += str(state[i].get('state_name')) + " 🆔 == " + "**!" + str(data.get('states')[i].get('state_id')) + "**"
if i < (arr_len - 1):
num_str += '\n'
embedVar = discord.Embed(title="Choose Your State", description=num_str, color=15462131)
embedVar.set_footer(text="Get Vaccinated",icon_url='https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae')
await message.channel.send(embed=embedVar)
if message.content.startswith('!'):
if message.content == '!':
await message.reply('Please enter valid commands')
else:
user_input = message.content.split('!')[1]
url = "https://cdn-api.co-vin.in/api/v2/admin/location/districts/" + user_input
conn = http.client.HTTPSConnection("cdn-api.co-vin.in")
conn.request("GET",url)
res = conn.getresponse()
print(res)
if res.status == 200:
await message.channel.send('Hi Choose You District')
d = res.read()
data = json.loads(d)
district = data.get('districts')
dis_length = len(district)
dist_string = ''
for i in range(0,dis_length):
dist_data = str(district[i].get('district_name')) + " (" + " Id: " + str(data.get('districts')[i].get('district_id')) + ")"
dist_string += str(district[i].get('district_name')) + " 🆔 == " + "#" + str(data.get('districts')[i].get('district_id'))
if i < (dis_length - 1):
dist_string += '\n'
embedVar = discord.Embed(title="Choose Your District", description=dist_string, color=15462131)
embedVar.set_footer(text="Get Vaccinated",icon_url='https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae')
await message.channel.send(embed=embedVar)
if message.content.startswith('#'):
if message.content == '#':
await message.reply('Please enter valid commands')
else:
user_input = message.content.split('#')[1]
await message.channel.send("\n" + "Please Enter Your Preferred Date in this format ** 01-05-2021 **")
print("dcbv")
try:
date = await client.wait_for('message', check=check, timeout=60000)
print(date.content)
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
conn = http.client.HTTPSConnection("cdn-api.co-vin.in")
url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByDistrict?district_id=" + user_input + "&date=" + date.content
conn.request("GET",url)
res = conn.getresponse()
print(res.status)
if res.status == 200:
d = res.read()
data = json.loads(d)
session = data.get('sessions')
s_len = len(session)
s_str = ''
abc = []
if s_len < 1:
await message.reply("Sorry, there is no Centers Avaliable on " + date.content +"\n"+ "Please enter district id and try again! ")
for i in range(0,s_len):
session_data = str(session[i].get('center_id')) + " (" + str(data.get('sessions')[i].get('name')) + ")" + " (" + str(data.get('sessions')[i].get('block_name')) + ")" + " (" + str(data.get('sessions')[i].get('pincode')) + ")" + " (" + str(data.get('sessions')[i].get('from')) + ")" + " (" + str(data.get('sessions')[i].get('to')) + ")" + " (" + str(data.get('sessions')[i].get('lat')) + ")" + " (" + str(data.get('sessions')[i].get('long')) + ")" + " (" + str(data.get('sessions')[i].get('slots')) + ")"
s_str = ":hospital:" + "\n" + "**Center Id: ** " + str(data.get('sessions')[i].get('center_id')) + "\n" + "**Center Name: ** " + str(data.get('sessions')[i].get('name')) + "\n" + "**Block: **" + str(data.get('sessions')[i].get('block_name')) + "\n" +"**PIN: **" + str(data.get('sessions')[i].get('pincode')) + "\n" +"**Fees: **" + str(data.get('sessions')[i].get('fee_type')) + "\n" + "**Slot Avaliable For Dose 1: **" + str(data.get('sessions')[i].get('available_capacity_dose1')) + "\n" + "**Slot Avaliable For Dose 2: **" + str(data.get('sessions')[i].get('available_capacity_dose2')) + "\n" + "**Slot Avaliable- **" + str(data.get('sessions')[i].get('available_capacity')) + "\n" + "**Age: **" + str(data.get('sessions')[i].get('min_age_limit')) + "+" + "\n" + ":syringe:**Vaccine: **" + str(data.get('sessions')[i].get('vaccine')) + "\n" +":stopwatch:**Session Timings**:stopwatch:" + "\n" + str(data.get('sessions')[i].get('slots')) + "\n" + "\n"
abc.append(s_str)
await message.channel.send("\n" + "** Center Details **")
# def fun(x):
# embedVar = discord.Embed(title="Session Details", description=x, color=3447003)
# embedVar.set_footer(text=f"Total Parts {len(abc)}",icon_url='https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae')
# message.channel.send(embed=embedVar)
# await asyncio.wait(map(fun, abc))
for i in abc:
embedVar = discord.Embed(title="Session Details", description=i, color=3447003)
embedVar.set_footer(text=f"Total Parts {len(abc)}",icon_url='https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae')
await message.channel.send(embed=embedVar)
else:
print(res.status)
await message.channel.send("Sorry, There is no available slots on ")
if message.content.startswith('register'):
await message.channel.send("I'm Concernd About Your privacy, so I have directly send you the details 🔒")
await message.author.send("Enter your Phone number with your contry code (91-India) 📞")
if message.content.startswith('91'):
phone = message.content.split('91')[1]
sql = ("SELECT id FROM users where userId = %s and status = 0")
val = (message.author.id,)
cursor.execute(sql, val)
res = cursor.fetchone()
if res:
pass
else:
sql = "INSERT INTO users (id, userId, phoneNo) VALUES (default,%s, %s)"
val = (message.author.id,phone)
cursor.execute(sql, val)
db.commit()
conn = http.client.HTTPSConnection("cdn-api.co-vin.in")
url = "https://cdn-api.co-vin.in/api/v2/auth/generateMobileOTP"
payload = json.dumps({
"secret": "U2FsdGVkX18NuNa/jso3AJbIkh1Rf6DDBC58kOBELnGJA58OH/R5EKIz6hrONnCg2kTB8ktbqt0gyJ9aCKyWFw==",
"mobile": phone,
})
headers = {
'authority': 'cdn-api.co-vin.in',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
'accept': 'application/json, text/plain, */*',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
'content-type': 'application/json',
'origin': 'https://selfregistration.cowin.gov.in',
'sec-fetch-site': 'cross-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://selfregistration.cowin.gov.in/',
'accept-language': 'en-IN,en;q=0.9,hi-IN;q=0.8,hi;q=0.7,en-GB;q=0.6,en-US;q=0.5'
}
conn.request("POST", url, payload, headers)
res = conn.getresponse()
if res.status == 200:
d = res.read()
data = json.loads(d)
sql = "UPDATE users SET txnId = %s WHERE userId = %s"
val = (data['txnId'],message.author.id)
cursor.execute(sql, val)
db.commit()
#otp verification
await message.author.send("Enter OTP ")
try:
otp = await client.wait_for('message', check=check, timeout=60000)
print(otp.content)
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
encoded_otp = encrypt_string(otp.content)
payload = json.dumps({
"otp": encoded_otp,
"txnId": data["txnId"]
})
headers = {
'authority': 'cdn-api.co-vin.in',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
'accept': 'application/json, text/plain, */*',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
'content-type': 'application/json',
'origin': 'https://selfregistration.cowin.gov.in',
'sec-fetch-site': 'cross-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://selfregistration.cowin.gov.in/',
'accept-language': 'en-IN,en;q=0.9,hi-IN;q=0.8,hi;q=0.7,en-GB;q=0.6,en-US;q=0.5'
}
conn.request("POST", "/api/v2/auth/validateMobileOtp", payload, headers)
res = conn.getresponse()
if res.status == 200:
d = res.read()
data = json.loads(d)
# token = data["token"]
sql = "UPDATE users SET token = %s WHERE userId = %s"
val = (data["token"],message.author.id)
cursor.execute(sql, val)
db.commit()
await message.author.send("OTP Verification Successfull 👍")
## Taking user details
await message.author.send("Enter your Full Name")
try:
name = await client.wait_for('message', check=check, timeout=60000)
sql = "UPDATE users SET name = %s WHERE userId = %s"
val = (name.content,message.author.id)
cursor.execute(sql, val)
db.commit()
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
await message.author.send("Enter your District")
try:
district = await client.wait_for('message', check=check, timeout=60000)
sql = "UPDATE users SET district = %s WHERE userId = %s"
val = (district.content,message.author.id)
cursor.execute(sql, val)
db.commit()
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
await message.author.send("Enter your Address")
try:
address = await client.wait_for('message', check=check, timeout=60000)
sql = "UPDATE users SET address = %s WHERE userId = %s"
val = (address.content,message.author.id)
cursor.execute(sql, val)
db.commit()
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
await message.author.send("Enter your age")
try:
age = await client.wait_for('message', check=check, timeout=60000)
sql = "UPDATE users SET age = %s WHERE userId = %s"
val = (age.content,message.author.id)
cursor.execute(sql, val)
db.commit()
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
await message.author.send("Enter your ID Type (adhaar, election id, pan card...)")
try:
idType = await client.wait_for('message', check=check, timeout=60000)
sql = "UPDATE users SET idType = %s WHERE userId = %s"
val = (idType.content,message.author.id)
cursor.execute(sql, val)
db.commit()
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
await message.author.send("Enter your ID Number")
try:
idNo = await client.wait_for('message', check=check, timeout=60000)
sql = "UPDATE users SET idNo = %s WHERE userId = %s"
val = (idNo.content,message.author.id)
cursor.execute(sql, val)
db.commit()
await message.author.send("✅ Done!!" + "\n" + "Enter 'myInfo' to know your details.");
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
else:
await message.author.send("Sorry, OTP is incorrect 👎")
await message.author.send("You can still store your data for future use \n Enter **'storeInfo'**")
if message.content.startswith('myInfo'):
await message.channel.send("Checking....⌛")
sql = ("SELECT name,district,address,age,idType,idNo,phoneNo FROM users where userId = %s")
val = (message.author.id,)
cursor.execute(sql, val)
res = cursor.fetchone()
if res:
await message.channel.send("I'm Concernd About Your privacy so I'm sending it directly to you 🔒")
embedVar = discord.Embed(title=res[0], description="**District: **" + res[1] + "\n" + "**Address: **" + res[2] + "\n" + "**Age: **" + str(res[3]) + "\n" + "**Personal ID: **" + res[4] + "\n" + "**ID Card no.: **" + str(res[5]) + "\n" + "**Phone no.: **" + str(res[6]) + "\n" + "\n"
+ "Go to the server to use me Again ", color=3447003)
embedVar.set_footer(text=f"Get Vaccinated",icon_url='https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae')
await message.author.send(embed=embedVar)
else:
await message.channel.send("Sorry You Are Not Registered 😞" + "\n" + "Enter 'register' for registration")
if message.content.startswith('notify'):
conn = http.client.HTTPSConnection("cdn-api.co-vin.in")
url = 'https://cdn-api.co-vin.in/api/v2/admin/location/states'
conn = http.client.HTTPSConnection("cdn-api.co-vin.in")
conn.request("GET",url)
res = conn.getresponse()
print(res)
if res.status == 200:
await message.channel.send('Hi Choose You State')
d = res.read()
data = json.loads(d)
state = data.get('states')
arr_len = len(state)
num_str = ''
for i in range(0,arr_len):
state_data = str(state[i].get('state_name')) + " (" + " Id: " + str(data.get('states')[i].get('state_id')) + ")"
num_str += str(state[i].get('state_name')) + " 🆔 == " + "**" + str(data.get('states')[i].get('state_id')) + "**"
if i < (arr_len - 1):
num_str += '\n'
embedVar = discord.Embed(title="Choose Your State", description=num_str, color=15462131)
embedVar.set_footer(text="Get Vaccinated",icon_url='https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae')
await message.channel.send(embed=embedVar)
try:
state_id = await client.wait_for('message', check=check, timeout=60000)
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
url = "https://cdn-api.co-vin.in/api/v2/admin/location/districts/" + state_id.content
conn = http.client.HTTPSConnection("cdn-api.co-vin.in")
conn.request("GET",url)
res = conn.getresponse()
print(res)
if res.status == 200:
await message.channel.send('Hi Choose You District')
d = res.read()
data = json.loads(d)
district = data.get('districts')
dis_length = len(district)
dist_string = ''
for i in range(0,dis_length):
dist_data = str(district[i].get('district_name')) + " (" + " Id: " + str(data.get('districts')[i].get('district_id')) + ")"
dist_string += str(district[i].get('district_name')) + " 🆔 == " + "**" + str(data.get('districts')[i].get('district_id'))
if i < (dis_length - 1):
dist_string += '\n'
embedVar = discord.Embed(title="Choose Your District", description=dist_string, color=15462131)
embedVar.set_footer(text="Get Vaccinated",icon_url='https://firebasestorage.googleapis.com/v0/b/bot-discord-f0d02.appspot.com/o/bot.png?alt=media&token=edbbf198-5a38-4434-a0c0-c12a885de0ae')
await message.channel.send(embed=embedVar)
try:
district_id = await client.wait_for('message', check=check, timeout=60000)
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
sql = ("SELECT id FROM notify where user_id = %s and status = 0")
val = (message.author.id,)
cursor.execute(sql, val)
res = cursor.fetchone()
if res:
pass
else:
sql = "INSERT INTO users (id, user_id, district) VALUES (default,%s, %s)"
val = (message.author.id,district_id.content)
cursor.execute(sql, val)
db.commit()
await message.channel.send('Enter Your Age')
try:
age = await client.wait_for('message', check=check, timeout=60000)
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
sql = "UPDATE notify SET age = %s WHERE userId = %s"
val = (age.content,message.author.id)
cursor.execute(sql, val)
db.commit()
await message.channel.send("**✅ Done!!** You are subscribed to get notification. You will get notification every hour when slots are available \n If you want to unsubscribe notification, then Just Enter '**stopNotify**'")
await message.author.send("✅ Done!! You are Subscribed To Get Notification")
if message.content.startswith('stopNotify'):
sql = "DELETE FROM notify WHERE userId = %s"
val = (message.author.id)
cursor.execute(sql, val)
db.commit()
await message.channel.send("❌ You have successfully unsubscribed ")
if message.content.startswith('deleteMyInfo'):
sql = "DELETE FROM users WHERE userId = %s"
val = (message.author.id)
cursor.execute(sql, val)
db.commit()
await message.channel.send("❌ You have successfully deleted your information")
if message.content.startswith('storeInfo'):
## Taking user details
await message.author.send("Enter your Full Name")
try:
name = await client.wait_for('message', check=check, timeout=60000)
sql = "UPDATE users SET name = %s WHERE userId = %s"
val = (name.content,message.author.id)
cursor.execute(sql, val)
db.commit()
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
await message.author.send("Enter your District")
try:
district = await client.wait_for('message', check=check, timeout=60000)
sql = "UPDATE users SET district = %s WHERE userId = %s"
val = (district.content,message.author.id)
cursor.execute(sql, val)
db.commit()
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
await message.author.send("Enter your Address")
try:
address = await client.wait_for('message', check=check, timeout=60000)
sql = "UPDATE users SET address = %s WHERE userId = %s"
val = (address.content,message.author.id)
cursor.execute(sql, val)
db.commit()
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
await message.author.send("Enter your age")
try:
age = await client.wait_for('message', check=check, timeout=60000)
sql = "UPDATE users SET age = %s WHERE userId = %s"
val = (age.content,message.author.id)
cursor.execute(sql, val)
db.commit()
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
await message.author.send("Enter your ID Type (adhaar, election id, pan card...)")
try:
idType = await client.wait_for('message', check=check, timeout=60000)
sql = "UPDATE users SET idType = %s WHERE userId = %s"
val = (idType.content,message.author.id)
cursor.execute(sql, val)
db.commit()
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
await message.author.send("Enter your ID Number")
try:
idNo = await client.wait_for('message', check=check, timeout=60000)
sql = "UPDATE users SET idNo = %s WHERE userId = %s"
val = (idNo.content,message.author.id)
cursor.execute(sql, val)
db.commit()
await message.author.send("✅ Done!!" + "\n" + "Enter 'myInfo' to know your details.");
except asyncio.TimeoutError:
return await message.channel.send(f'Sorry, you took too long.')
client.run(DISCORD_TOKEN)