-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.py
More file actions
661 lines (563 loc) · 26.9 KB
/
Client.py
File metadata and controls
661 lines (563 loc) · 26.9 KB
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
# Ver 0.2.9
# Credits to enzomtp
import requests, json, os, datetime, discord, pytz
from discord.ext import tasks
print("Python Pronote Bot V0.2.9 by enzomtp")
# Define all variables
preconf = open('./config.json')
config = json.load(preconf)
totimestamp = slice(10)
utc = pytz.utc
now=datetime.datetime.now()
FRTZ = pytz.timezone('Europe/Paris')
def ToUtcHour(h):
return int(FRTZ.localize(datetime.datetime(int(now.strftime('%Y')), int(now.strftime('%m')), int(now.strftime('%d')), h, 12, 0)).astimezone(utc).strftime('%H'))
def ToUtcMin(m):
return int(FRTZ.localize(datetime.datetime(int(now.strftime('%Y')), int(now.strftime('%m')), int(now.strftime('%d')), 12, m, 0)).astimezone(utc).strftime('%M'))
# Verify, Create and Read the data.json
if os.path.isfile("./data.json"):
data = json.load(open('./data.json'))
print(data)
else:
f = open("data.json", "x")
data = {
"UsersHomeworks1":[],
"UsersTimetables1":[],
"UsersHomeworks2":[],
"UsersTimetables2":[],
"Menu":[]
}
with open('data.json', 'w') as f:
json.dump(data, f, ensure_ascii=False)
print("created file")
data = json.load(open('./data.json'))
print(data)
# A hex to rgb function
def hex_to_rgb(value):
value = value.lstrip('#')
lv = len(value)
return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
# Login in the api
def Login(grp):
print("Logging in as group "+config["group"][str(grp)]["username"])
# Login
urlogin = "http://127.0.0.1:21727/auth/login"
payloadlogin = '{"url": "'+config["pronoteurl"]+'","username":"'+config["group"][str(grp)]["username"]+'","password":"'+config["group"][str(grp)]["password"]+'"}'
headerslogin = {'content-type': "application/json"}
tokenjson = json.loads(requests.request("POST", urlogin, data=payloadlogin, headers=headerslogin).text)
token = tokenjson["token"]
return token
# Get Timetables from the api
def getTimetables(grp):
ajd = str(datetime.date.today())
print("Getting Timetables as group "+config["group"][str(grp)]["username"])
try:
token = Login(grp)
except:
print("Server not running or don't have internet")
# Pickup Infos
urlquery = "http://127.0.0.1:21727/graphql"
payloadquery = '{ "query": "query { timetable(from: \\"'+ajd+'\\") { teacher, room, from, to, color, subject, isCancelled } }"}'
headersquery = {'content-type': "application/json",'token': token}
timetables = requests.request("POST", urlquery, data=payloadquery, headers=headersquery).text
print("Parsed json for Timetables : \n"+str(timetables))
return(timetables)
# Get Homeworks from the api
def getHomeworks(grp):
ajd = str(datetime.date.today())
print("Getting Homeworks as group "+config["group"][str(grp)]["username"])
try:
token = Login(grp)
except:
print("Server not running or don't have internet")
# Pickup Infos
urlquery = "http://127.0.0.1:21727/graphql"
payloadquery = '{ "query": "query { homeworks(from: \\"'+ajd+'\\") { description, subject, color } }"}'
headersquery = {'content-type': "application/json",'token': token}
homeworks = requests.request("POST", urlquery, data=payloadquery, headers=headersquery).text
print("Parsed json for homeworks : \n"+str(homeworks))
return(homeworks)
# Get Menu from the api
def getMenu():
ajdm = str(datetime.date.today()-datetime.timedelta(days=1))
print("Getting Menu as "+config["group"]["2"]["username"])
try:
token = Login("2")
except:
print("Server not running or don't have internet")
# Pickup Infos
urlquery = "http://127.0.0.1:21727/graphql"
payloadquery = '{ "query": "query { menu(from: \\"'+ajdm+'\\") { meals { name } } }"}'
headersquery = {'content-type': "application/json",'token': token}
timetables = requests.request("POST", urlquery, data=payloadquery, headers=headersquery).text
print("Parsed json for Menu : \n"+str(timetables))
return(timetables)
global home
global timetab
# Init bot
bot = discord.Bot()
# On bot ready
@bot.event
async def on_ready():
print(f"We have logged in as {bot.user}")
h24homeworks.start()
h24timetables.start()
h24menu.start()
async for guild in bot.fetch_guilds():
global guilds
guilds = []
guilds.append(guild.id)
return guilds
# Schedule the daily Timetables task
@tasks.loop(time=datetime.time(hour=ToUtcHour(7), minute=ToUtcMin(55)))
async def h24timetables():
for a in range(1,3):
print("Executing daily timetables")
global timechan
weekend = datetime.date.today()
timetab = json.loads(getTimetables(str(a)))
#Send timetables in the channel defined in config.json
timechan = bot.get_channel(int(config["group"][str(a)]["timetables"]))
if weekend.weekday() <= 4:
await timechan.send("Voici l'emplois du temps d'aujourd'hui : ")
for i in timetab["data"]["timetable"]:
col = hex_to_rgb(str(i["color"]))
# Verify if there is a teacher
if i["teacher"]:
if i["isCancelled"]==True:
embedVar = discord.Embed(title=str(i["subject"]) , description="Salle : "+str(i["room"])+"\nAvec : "+i["teacher"]+"\nEst annulé : Oui. \nDe : <t:"+str(i["from"])[totimestamp]+":t>\nÀ : <t:"+str(i["to"])[totimestamp]+":t>", color=discord.Color.from_rgb(col[0],col[1],col[2]))
else:
embedVar = discord.Embed(title=str(i["subject"]) , description="Salle : "+str(i["room"])+"\nAvec : "+i["teacher"]+"\nEst annulé : Non. \nDe : <t:"+str(i["from"])[totimestamp]+":t>\nÀ : <t:"+str(i["to"])[totimestamp]+":t>", color=discord.Color.from_rgb(col[0],col[1],col[2]))
else:
if i["isCancelled"]==True:
embedVar = discord.Embed(title=str(i["subject"]) , description="Salle : "+str(i["room"])+"\nAvec :\nEst annulé : Oui. \nDe : <t:"+str(i["from"])[totimestamp]+":t>\nÀ : <t:"+str(i["to"])[totimestamp]+":t>", color=discord.Color.from_rgb(col[0],col[1],col[2]))
else:
embedVar = discord.Embed(title=str(i["subject"]) , description="Salle : "+str(i["room"])+"\nAvec :\nEst annulé : Non. \nDe : <t:"+str(i["from"])[totimestamp]+":t>\nÀ : <t:"+str(i["to"])[totimestamp]+":t>", color=discord.Color.from_rgb(col[0],col[1],col[2]))
await timechan.send(embed=embedVar)
else:
await timechan.send("Weekend !")
# Send timetables to everyone who is in the list
print("Sending daily Timetables for group "+str(a)+" : ")
for usr in data["UsersTimetables"+str(a)]:
try:
user = await bot.fetch_user(usr)
print(user)
if weekend.weekday() <= 4:
await user.send("Voici l'emplois du temps d'aujourd'hui pour le **groupe "+str(a)+"** : ")
for i in timetab["data"]["timetable"]:
col = hex_to_rgb(str(i["color"]))
# Verify if there is a teacher
if i["teacher"]:
if i["isCancelled"]==True:
embedVar = discord.Embed(title=str(i["subject"]) , description="Salle : "+str(i["room"])+"\nAvec : "+i["teacher"]+"\nEst annulé : Oui. \nDe : <t:"+str(i["from"])[totimestamp]+":t>\nÀ : <t:"+str(i["to"])[totimestamp]+":t>", color=discord.Color.from_rgb(col[0],col[1],col[2]))
else:
embedVar = discord.Embed(title=str(i["subject"]) , description="Salle : "+str(i["room"])+"\nAvec : "+i["teacher"]+"\nEst annulé : Non. \nDe : <t:"+str(i["from"])[totimestamp]+":t>\nÀ : <t:"+str(i["to"])[totimestamp]+":t>", color=discord.Color.from_rgb(col[0],col[1],col[2]))
else:
if i["isCancelled"]==True:
embedVar = discord.Embed(title=str(i["subject"]) , description="Salle : "+str(i["room"])+"\nAvec :\nEst annulé : Oui. \nDe : <t:"+str(i["from"])[totimestamp]+":t>\nÀ : <t:"+str(i["to"])[totimestamp]+":t>", color=discord.Color.from_rgb(col[0],col[1],col[2]))
else:
embedVar = discord.Embed(title=str(i["subject"]) , description="Salle : "+str(i["room"])+"\nAvec :\nEst annulé : Non. \nDe : <t:"+str(i["from"])[totimestamp]+":t>\nÀ : <t:"+str(i["to"])[totimestamp]+":t>", color=discord.Color.from_rgb(col[0],col[1],col[2]))
await user.send(embed=embedVar)
except Exception as err:
print("An error occured while sending dm to a user : {0}".format(err))
# Schedule the daily Homeworks task
@tasks.loop(time=datetime.time(hour=ToUtcHour(15), minute=ToUtcMin(55)))
async def h24homeworks():
for a in range(1,3):
print("Executing daily homeworks")
global homechan
home = json.loads(getHomeworks(str(a)))
#Send homeworks in the channel defined in config.json
weekendhome = datetime.date.today()+datetime.timedelta(days=1)
homechan = bot.get_channel(int(config["group"][str(a)]["homeworks"]))
if weekendhome.weekday() <= 4:
await homechan.send("Voici les devoirs de demain : ")
for i in home["data"]["homeworks"]:
col = hex_to_rgb(str(i["color"]))
embedVar = discord.Embed(title="Pour demain en " + str(i["subject"]), description=i["description"], color=discord.Color.from_rgb(col[0],col[1],col[2]))
await homechan.send(embed=embedVar)
else:
await homechan.send("Weekend !")
# Send homeworks to every users who is in the list
print("Sending daily Homeworks for group "+str(a)+" : ")
for usr in data["UsersHomeworks"+str(a)]:
try:
user = await bot.fetch_user(usr)
print(user)
if weekendhome.weekday() <= 4:
await user.send("Voici les devoirs de demain pour le **groupe "+str(a)+"** : ")
for i in home["data"]["homeworks"]:
col = hex_to_rgb(str(i["color"]))
embedVar = discord.Embed(title="Pour demain en " + str(i["subject"]), description=i["description"], color=discord.Color.from_rgb(col[0],col[1],col[2]))
await user.send(embed=embedVar)
except Exception as err:
print("An error occured while sending dm to a user : {0}".format(err))
# Schedule the daily Menu task
@tasks.loop(time=datetime.time(hour=ToUtcHour(7), minute=ToUtcMin(55)))
async def h24menu():
menu = json.loads(str(getMenu()))
print("Executing daily menu")
global menuchan
weekend = datetime.date.today()
#Send menu in the channel defined in config.json
if config["discord"]["sendmenu"] == True:
menuchan = bot.get_channel(int(config["discord"]["menuchannel"]))
if weekend.weekday() <= 4:
await menuchan.send("Voici le menu d'aujourd'hui : ")
menuindex = 0
entree = ""
viandes = ""
acomp = ""
laits = ""
desserts = ""
for i in menu["data"]["menu"][0]["meals"][0]:
for a in i:
if menuindex == 0:
entree = entree + a["name"]+"\n"
elif menuindex == 1:
viandes = viandes + a["name"]+"\n"
elif menuindex == 2:
acomp = acomp + a["name"]+"\n"
elif menuindex == 3:
laits = laits + a["name"]+"\n"
elif menuindex == 4:
desserts = desserts + a["name"]+"\n"
menuindex += 1
embedVar = discord.Embed(title="Le menu d'ajourd'hui est composé de :", description=" ", color=0xff3950)
embedVar.insert_field_at(index=0, name="Entrée", value=entree, inline=False)
embedVar.insert_field_at(index=1, name="Viandes", value=viandes, inline=False)
embedVar.insert_field_at(index=2, name="Acompagnements", value=acomp, inline=False)
embedVar.insert_field_at(index=3, name="Laitages", value=laits, inline=False)
embedVar.insert_field_at(index=4, name="Desserts", value=desserts, inline=False)
await menuchan.send(embed=embedVar)
else:
await timechan.send("Weekend !")
# Send menu to everyone who is in the list
print("Sending daily Menu to : ")
for usr in data["Menu"]:
try:
user = await bot.fetch_user(usr)
print(user)
if weekend.weekday() <= 4:
await user.send("Voici le menu d'aujourd'hui : ")
menuindex = 0
entree = ""
viandes = ""
acomp = ""
laits = ""
desserts = ""
for i in menu["data"]["menu"][0]["meals"][0]:
for a in i:
if menuindex == 0:
entree = entree + a["name"]+"\n"
elif menuindex == 1:
viandes = viandes + a["name"]+"\n"
elif menuindex == 2:
acomp = acomp + a["name"]+"\n"
elif menuindex == 3:
laits = laits + a["name"]+"\n"
elif menuindex == 4:
desserts = desserts + a["name"]+"\n"
menuindex += 1
embedVar = discord.Embed(title="Le menu d'ajourd'hui est composé de :", description=" ", color=0xff3950)
embedVar.insert_field_at(index=0, name="Entrée", value=entree, inline=False)
embedVar.insert_field_at(index=1, name="Viandes", value=viandes, inline=False)
embedVar.insert_field_at(index=2, name="Acompagnements", value=acomp, inline=False)
embedVar.insert_field_at(index=3, name="Laitages", value=laits, inline=False)
embedVar.insert_field_at(index=4, name="Desserts", value=desserts, inline=False)
await user.send(embed=embedVar)
except Exception as err:
print("An error occured while sending dm to a user : {0}".format(err))
# On slash command "menu"
@bot.slash_command(guild_ids=config["discord"]["guildid"], description="Envoye le menu dans ce channel")
async def menu(ctx):
menu = json.loads(getMenu())
print(str(ctx.author) + " Executed \"menu\"")
try:
await ctx.respond("Voici le menu d'aujourd'hui : ")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
menuindex = 0
entree = ""
viandes = ""
acomp = ""
laits = ""
desserts = ""
for i in menu["data"]["menu"][0]["meals"][0]:
for a in i:
if menuindex == 0:
entree = entree + a["name"]+"\n"
elif menuindex == 1:
viandes = viandes + a["name"]+"\n"
elif menuindex == 2:
acomp = acomp + a["name"]+"\n"
elif menuindex == 3:
laits = laits + a["name"]+"\n"
elif menuindex == 4:
desserts = desserts + a["name"]+"\n"
menuindex += 1
embedVar = discord.Embed(title="Le menu d'ajourd'hui est composé de :", description=" ", color=0xff3950)
embedVar.insert_field_at(index=0, name="Entrée", value=entree, inline=False)
embedVar.insert_field_at(index=1, name="Viandes", value=viandes, inline=False)
embedVar.insert_field_at(index=2, name="Acompagnements", value=acomp, inline=False)
embedVar.insert_field_at(index=3, name="Laitages", value=laits, inline=False)
embedVar.insert_field_at(index=4, name="Desserts", value=desserts, inline=False)
print("Entrée : \n" + entree + "\nViandes : \n" + viandes)
await ctx.send(embed=embedVar)
# On slash command "devoirs"
@bot.slash_command(guild_ids=config["discord"]["guildid"], description="Envoye les devoirs dans ce channel")
async def devoirs(
ctx,
group: discord.Option(int, "Enter your group", min_value=1, max_value=2, default=1)
):
home = json.loads(getHomeworks(group))
print(str(ctx.author) + " Executed \"devoirs\"")
try:
await ctx.respond("Voici les devoirs de demain : ")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
for i in home["data"]["homeworks"]:
col = hex_to_rgb(str(i["color"]))
embedVar = discord.Embed(title="Pour demain en " + str(i["subject"]), description=i["description"], color=discord.Color.from_rgb(col[0],col[1],col[2]))
await ctx.send(embed=embedVar)
# On slash command "emplois du temps"
@bot.slash_command(guild_ids=config["discord"]["guildid"], description="Envoye l'emplois du temps dans ce channel")
async def edt(
ctx,
group: discord.Option(int, "Enter your group", min_value=1, max_value=2, default=1)
):
timetab = json.loads(getTimetables(str(group)))
print(str(ctx.author) + " Executed \"edt\"")
try:
await ctx.respond("Voici l'emplois du temps d'aujourd'hui : ")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
for i in timetab["data"]["timetable"]:
col = hex_to_rgb(str(i["color"]))
#verify if there is a teacher
if i["teacher"]:
if i["isCancelled"]==True:
embedVar = discord.Embed(title=str(i["subject"]) , description="Salle : "+str(i["room"])+"\nAvec : "+i["teacher"]+"\nEst annulé : Oui. \nDe : <t:"+str(i["from"])[totimestamp]+":t>\nÀ : <t:"+str(i["to"])[totimestamp]+":t>", color=discord.Color.from_rgb(col[0],col[1],col[2]))
else:
embedVar = discord.Embed(title=str(i["subject"]) , description="Salle : "+str(i["room"])+"\nAvec : "+i["teacher"]+"\nEst annulé : Non. \nDe : <t:"+str(i["from"])[totimestamp]+":t>\nÀ : <t:"+str(i["to"])[totimestamp]+":t>", color=discord.Color.from_rgb(col[0],col[1],col[2]))
else:
if i["isCancelled"]==True:
embedVar = discord.Embed(title=str(i["subject"]) , description="Salle : "+str(i["room"])+"\nAvec :\nEst annulé : Oui. \nDe : <t:"+str(i["from"])[totimestamp]+":t>\nÀ : <t:"+str(i["to"])[totimestamp]+":t>", color=discord.Color.from_rgb(col[0],col[1],col[2]))
else:
embedVar = discord.Embed(title=str(i["subject"]) , description="Salle : "+str(i["room"])+"\nAvec :\nEst annulé : Non. \nDe : <t:"+str(i["from"])[totimestamp]+":t>\nÀ : <t:"+str(i["to"])[totimestamp]+":t>", color=discord.Color.from_rgb(col[0],col[1],col[2]))
await ctx.send(embed=embedVar)
# Add you to the list of daily Menu
@bot.slash_command(guild_ids=config["discord"]["guildid"], description="Te rajoutte a la liste des personnes qui recoivent le menu tout les jours")
async def menudm(ctx):
print(str(ctx.author) + " Executed \"menudm\"")
verf = 0
for d in data["Menu"]:
if d==ctx.author.id :
verf += 1
if not verf==1 :
successful = False
try:
data["Menu"].append(ctx.author.id)
with open('data.json', 'w') as f:
json.dump(data, f, ensure_ascii=False)
print(data)
successful = True
except Exception as err:
try:
await ctx.respond("Foirré")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
await ctx.channel.send("Erreur : \n{0}".format(err))
if successful:
try:
await ctx.respond("Sucessfully added.")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
else:
try:
await ctx.respond("Tu est déja dans la liste !")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
# Remove you from the list of daily Menu
@bot.slash_command(guild_ids=config["discord"]["guildid"], description="Te retire de la liste des personnes qui recoivent le menu tout les jours")
async def menudmremove(ctx):
print(str(ctx.author) + " Executed \"menudmremove\"")
successful = False
try:
for i in data["Menu"]:
remcount = -1
if ctx.author.id == i:
remcount += 1
break
else:
remcount += 1
data["Menu"].pop(remcount)
with open('data.json', 'w') as f:
json.dump(data, f, ensure_ascii=False)
print(data)
successful = True
except Exception as err:
try:
await ctx.respond("Foirré")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
await ctx.channel.send("Erreur : \n{0}".format(err))
if successful:
try:
await ctx.respond("Sucessfully Removed.")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
# Add you to the list of daily Timetables
@bot.slash_command(guild_ids=config["discord"]["guildid"], description="Te rajoutte a la liste des personnes qui recoivent l'emplois du temps tout les jours")
async def edtdm(
ctx,
group: discord.Option(int, "Enter your group", min_value=1, max_value=2, default=1)
):
print(str(ctx.author) + " Executed \"edtdm\"")
verf = 0
for d in data["UsersTimetables"+str(group)]:
if d==ctx.author.id :
verf += 1
if not verf==1 :
successful = False
try:
data["UsersTimetables"+str(group)].append(ctx.author.id)
with open('data.json', 'w') as f:
json.dump(data, f, ensure_ascii=False)
print(data)
successful = True
except Exception as err:
try:
await ctx.respond("Foirré")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
await ctx.channel.send("Erreur : \n{0}".format(err))
if successful:
try:
await ctx.respond("Sucessfully added.")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
else:
try:
await ctx.respond("Tu est déja dans la liste !")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
# Remove you from the list of daily Timetables
@bot.slash_command(guild_ids=config["discord"]["guildid"], description="Te retire de la liste des personnes qui recoivent l'emplois du temps tout les jours")
async def edtdmremove(
ctx,
group: discord.Option(int, "Enter your group", min_value=1, max_value=2, default=1)
):
print(str(ctx.author) + " Executed \"edtdmremove\"")
successful = False
try:
for i in data["UsersTimetables"+str(group)]:
remcount = -1
if ctx.author.id == i:
remcount += 1
break
else:
remcount += 1
data["UsersTimetables"+str(group)].pop(remcount)
with open('data.json', 'w') as f:
json.dump(data, f, ensure_ascii=False)
print(data)
successful = True
except Exception as err:
try:
await ctx.respond("Foirré")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
await ctx.channel.send("Erreur : \n{0}".format(err))
if successful:
try:
await ctx.respond("Sucessfully Removed.")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
# Add you to the list of daily homeworks
@bot.slash_command(guild_ids=config["discord"]["guildid"], description="Te rajoutte a la liste des personnes qui recoivent les devoirs tout les jours")
async def devoirsdm(
ctx,
group: discord.Option(int, "Enter your group", min_value=1, max_value=2, default=1)
):
print(str(ctx.author) + " Executed \"devoirsdm\"")
verf = 0
for d in data["UsersHomeworks"+str(group)]:
if d==ctx.author.id :
verf += 1
if not verf==1 :
successful = False
try:
data["UsersHomeworks"+str(group)].append(ctx.author.id)
with open('data.json', 'w') as f:
json.dump(data, f, ensure_ascii=False)
print(data)
successful = True
except Exception as err:
try:
await ctx.respond("Foirré")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
await ctx.channel.send("Erreur : \n{0}".format(err))
if successful:
try:
await ctx.respond("Sucessfully added.")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
else:
try:
await ctx.respond("Tu est déja dans la liste !")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
# Remove you from the list of daily homeworks
@bot.slash_command(guild_ids=config["discord"]["guildid"], description="Te retire de la liste des personnes qui recoivent les devoirs tout les jours")
async def devoirsdmremove(
ctx,
group: discord.Option(int, "Enter your group", min_value=1, max_value=2, default=1)
):
print(str(ctx.author) + " Executed \"devoirsdmremove\"")
successful = False
try:
for i in data["UsersHomeworks"+str(group)]:
remcount = -1
if ctx.author.id == i:
remcount += 1
break
else:
remcount += 1
data["UsersHomeworks"+str(group)].pop(remcount)
with open('data.json', 'w') as f:
json.dump(data, f, ensure_ascii=False)
print(data)
successful = True
except Exception as err:
try:
await ctx.respond("Foirré")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
await ctx.channel.send("Erreur : \n{0}".format(err))
if successful:
try:
await ctx.respond("Sucessfully Removed.")
except:
print("Discord Response Timed Out !")
await ctx.send("Discord Response Timed Out !")
# Run the bot with the token in config.json
bot.run(config["discord"]["discordtoken"])