This repository was archived by the owner on Feb 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdolphinbot.py
More file actions
executable file
·1087 lines (1019 loc) · 69.9 KB
/
dolphinbot.py
File metadata and controls
executable file
·1087 lines (1019 loc) · 69.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
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import discord, random, os, re, json
from os import path
from shutil import copyfile
from datetime import datetime, timedelta
client = discord.Client()
directory = os.path.dirname(os.path.realpath(__file__))
clockfile = directory + "/clocks.json"
if not path.isfile(clockfile):
copyfile(directory+"/sample clocks.json",clockfile)
settingsfile = directory + "/settings.json"
if not path.isfile(settingsfile):
with open(settingsfile,"w") as settings_file:
settings = {"Last Meme": str(datetime.now())}
json.dump(settings, settings_file, indent=4)
with open(directory + "/bot.key","r") as file:
key = file.read()
rulings = ["Obi-wan importantly told Anakin he had the High Ground! In light of this, and the game state, clearly your opponent's position is correct",
"You can re-roll all failed hit rolls for this unit if, before rolling the dice, you hold aloft a grail or goblet and shout 'For the Lady' in a heroic voice.",
"You can re-roll any failed hit rolls when attacking with the Runefang so long as you have a bigger and more impressive moustache than your opponent.",
"If you actually talk to your imaginary horse you can re-roll failed wound rolls as well.",
"You can add 1 to these dice rolls if, between the time you declare the target of the attack and time you roll the dice, your opponent looks you directly in the eye.",
"Active Player Chooses.",
"Has anyone told you the story of Darth Plagueis the wise? It's not a story the Jedi would tell you. I too, cannot give you a ruling here. Please ask dyno to flip a coin.",
"Inactive Player Chooses.",
"Electro leap will not remove from play.",
"You can not use opening the gate to bring a companion model in.",
"After you determine if it was a successful slam, meaning the model ended its slam movement within its slam range (.5'' for most models), it then can cast telekinesis and slam from its new location. As stated assuming it still has the model being slammed in its slam range.",
"Because it is intended that with blood bound that no souls or corpses apythre able to be gained. We will look further at the wording and see what can be done, but for now there is no need for further discussion."]
scenarios = ["King of the Hill","Bunkers","Spread the Net","Invasion","Anarchy","Recon II"]
help = """Currently the commands available are:
> !help: Displays this help message.
> !stream: Get the link the the Knight Twitch Stream.
> !judge: Ask for a (meme worthy) Judgement call from Dolphin.
> !timer: Set a countdown timer. Syntax `!timer {hh:mm} ({reason}). Use `!timer` for more details.
> !heret: Set a countdown timer that pings here on completion. Syntax `!heret {hh:mm} {reason}. Use `!timer` for more details.
> !chessclock: Creates a chess clock between 2 players. Use `!chessclock` and `!chessclock help` for more details.
> !scenario: Provides a random Stream Roller 2019 Scenario.
> !github: Provides a link to the bot's GitHub page for reporting issues.
`{}` denote parameters. Parameters wrapped in `()` are optional."""
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as {0}!'.format(self.user))
game = discord.Game("Judge | !help")
await client.change_presence(status=discord.Status.online, activity=game)
async def on_message(self, message):
#print('Message from {0.author}: {0.content}'.format(message))
import time, uuid
if message.author == client.user:
return
if message.content.lower() == ("!help"):
await message.channel.send(help)
return
if message.content.lower().startswith("hello"):
image = directory + "/Images/hello.gif"
print(image)
await message.channel.send("Hello there!")
await message.channel.send(file=discord.File(image))
return
if message.content.lower() == ("!judge"):
if str(message.channel).startswith("table"):
#response = "I haven't been trained to give Judge calls yet, sorry {0.author.mention}. :(".format(message)
response = "Thanks for asking for a Judgement call {0.author.mention}.".format(message)
await message.channel.send(response)
r = len(rulings)
i = random.randint(0,r)
response = rulings[i].format(message)
await message.channel.send(response)
return
else:
response = "We're not in a game channel, {0.author.mention}. Please get my attention in the correct Vassal Game Channel. Thanks! :)".format(message)
await message.channel.send(response)
return
if message.content.lower() == "!stream":
await message.channel.send("You can watch the Knight's Stream here: https://www.twitch.tv/knightsmachine")
return
if message.content.lower() == "!scenario":
s = len(scenarios)
i = random.randint(0,s)
response = scenarios[i].format(message)
await message.channel.send(response)
map = directory + "/Images/" + scenarios[i].replace(" ","") + "-2019.png"
await message.channel.send(file=discord.File(map))
return
if message.content.lower() == "!timer":
await message.channel.send("The !timer command must be followed by a time period, and optionally a reason. For example: `!timer 03:00` will set a timer for 3 hours. If you wish, you can include a reason afterwards. For example: `!timer 01:30 Ryan and Thom's game` will set a timer for 1 hour 30 minutes with the reason *\"Ryan and Thom's game\"*.")
return
if message.content.lower().startswith("!timer "):
timer = message.content[7:12]
hours = message.content[7:9]
minutes = message.content[10:12]
seconds = "00"
reason = message.content[13:]
if re.match("[0-9][0-9]:[0-5][0-9]",timer):
response = "Setting timer for " + str(int(hours)) + " hour(s) and " + str(int(minutes)) + " minute(s). Let the count down begin!"
await message.channel.send(response.format(message))
duration = int(seconds) + (int(minutes) * 60) + (int(hours) * 60 *60)
embed = discord.Embed(title="Timer", description=reason, color=0x4444dd)
embed.add_field(name="Duration", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
embed.add_field(name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
timermsg = await message.channel.send(embed=embed)
#Start counting down
start = datetime.now()
end = start + timedelta(seconds=duration)
while datetime.now() < end:
time.sleep(0.5)
remaining = int((end - datetime.now()).total_seconds())
hours = str(int(remaining / 3600))
minutes = str(int((remaining % 3600)/60))
seconds = str(remaining % 60)
embed.set_field_at(1,name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
await timermsg.edit(embed=embed)
#timer complete!
embed.set_field_at(1,name="Remaining", value="`00:00:00` ", inline=True)
await timermsg.edit(embed=embed)
response = "Your timer has finished {0.author.mention}!".format(message)
await message.channel.send(response)
else:
await message.channel.send("That isn't a valid time!")
return
#I have been lazy with this name for now.
if message.content.lower().startswith("!heret "):
timer = message.content[7:12]
hours = message.content[7:9]
minutes = message.content[10:12]
seconds = "00"
reason = message.content[13:]
if reason == "":
await message.channel.send("Here timers must have a reason.")
return
roles = message.author.roles
isJudge = False
for role in roles:
if role.name == "Judge":
isJudge = True
if isJudge == False:
await message.channel.send("You must be a Judge to use Here Timers.")
elif re.match("[0-9][0-9]:[0-5][0-9]",timer):
response = "Setting timer for " + str(int(hours)) + " hour(s) and " + str(int(minutes)) + " minute(s). Let the count down begin!"
await message.channel.send(response.format(message))
duration = int(seconds) + (int(minutes) * 60) + (int(hours) * 60 *60)
embed = discord.Embed(title="Here Timer", description=reason, color=0x4444dd)
embed.add_field(name="Duration", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
embed.add_field(name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
timermsg = await message.channel.send(embed=embed)
#Start counting down
start = datetime.now()
end = start + timedelta(seconds=duration)
while datetime.now() < end:
time.sleep(0.5)
remaining = int((end - datetime.now()).total_seconds())
hours = str(int(remaining / 3600))
minutes = str(int((remaining % 3600)/60))
seconds = str(remaining % 60)
embed.set_field_at(1,name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
await timermsg.edit(embed=embed)
#timer complete!
embed.set_field_at(1,name="Remaining", value="`00:00:00` ", inline=True)
await timermsg.edit(embed=embed)
response = "".join(["@here , the timer, ", reason, ", has finished!"]).format(message)
await message.channel.send(response)
else:
await message.channel.send("That isn't a valid time!")
return
if message.content.lower() == "!github":
await message.channel.send("Please report any issues with the bot on GitHub: <https://github.com/LarnuUK/dolphinbot>".format(message))
return
#######################################
# Here start the Chess Clock Commands #
#######################################
if message.content.lower() == "!chessclock":
await message.channel.send("The !chessclock command must be followed by a time period and a mentioned opponent. For example: `!chessclock 01:00 @Thom` will set a timer for 1 hour for each player. For a list of Chess Clock commands, use `!chessclock help`.")
return
if message.content.lower() == "!chessclock help":
response = """The chessclock commands are as follows:
> !start - Starts/unpauses the chessclock.
> !update - Provides an update with the current times on the Chessclock.
> !switch - Switches the active opponent.
> !pause - Pauses your chessclock
> !end - Ends your chessclock. The chessclock **cannot** be restarted once it has ended.
All commands can be optionally followed by an ID, which allows a Judge to interact with another player's clock."""
await message.channel.send(response.format(message))
return
if message.content.lower().startswith("!chessclock "):
with open(clockfile,"r") as clocks_file:
clocks = json.load(clocks_file)
for (id,clock) in clocks.items():
player1 = clock["Player1"]
player2 = clock["Player2"]
if clock["Status"] != "Finished" and int(clock["Channel ID"]) == message.channel.id and (int(player1["ID"]) == message.author.id or int(player2["ID"]) == message.author.id):
await message.channel.send("You already have an active clock in this channel. Please !end your active clock before starting a new one.".format(message))
return
clockid = uuid.uuid4()
timer = message.content[12:17]
if len(message.mentions) == 0:
await message.channel.send("Chess clocks require an opponent!")
elif re.match("[0-9][0-9]:[0-5][0-9]",timer):
hours = message.content[12:14]
minutes = message.content[15:17]
seconds = "00"
duration = int(seconds) + (int(minutes) * 60) + (int(hours) * 60 *60)
description = "".join([message.author.display_name, " vs ", message.mentions[0].display_name])
time = '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds)
embed = discord.Embed(title="Chess Clock", description=description, color=0xdddddd)
embed.add_field(name="ID", value=clockid, inline=False)
embed.add_field(name="__**" + message.author.display_name+ "**__", value="`" + time + "`", inline=True)
embed.add_field(name=message.mentions[0].display_name, value="`" + time + "` ", inline=True)
embed.add_field(name="Status", value="Not Started", inline=False)
embed.add_field(name="Pauses", value="0(0)", inline=True)
clockmsg = await message.channel.send(embed=embed)
with open(clockfile,"w") as clocks_file:
newclock = {str(clockid): { "Status": "Not Started", "Status Time": str(datetime.now()), "Channel ID": message.channel.id, "Active Player": "1", "Message ID" : str(clockmsg.id), "Pauses": 0, "Judge Pauses": 0, "Player1": {"Name": message.author.display_name, "ID": message.author.id, "Remaining": duration},"Player2": {"Name": message.mentions[0].display_name, "ID": message.mentions[0].id, "Remaining": duration}}}
clocks.update(newclock)
#print(clocks)
json.dump(clocks, clocks_file, indent=4)
else:
await message.channel.send("That isn't a valid time!")
return
if message.content.lower().startswith("!start"):
if message.content.lower() == "!start":
clockfound = False
with open(clockfile,"r") as clocks_file:
clocks = json.load(clocks_file)
for (id,clock) in clocks.items():
if clockfound == False:
player1 = clock["Player1"]
player2 = clock["Player2"]
if clock["Status"] != "Finished" and int(clock["Channel ID"]) == message.channel.id and (int(player1["ID"]) == message.author.id or int(player2["ID"]) == message.author.id):
clockfound = True
break
if clockfound == False:
await message.channel.send("You do not currently have an active clock to end in this channel!".format(message))
elif clock["Status"] == "Running":
await message.channel.send("Your clock is already running.".format(message))
else:
if int(clock["Active Player"]) == 1:
colour = 0xaa3333
playerone = "__**" + player1["Name"] + "**__"
playertwo = player2["Name"]
else:
colour = 0x3333aa
playerone = player1["Name"]
playertwo = "__**" + player2["Name"] + "**__"
#await message.channel.delete(clockmsg)
#await message.channel.send("I would delete the prior message, with the clock times, but Python or DiscordPy is being dick. If you want to solve the problem, suck it.")
p1hours = str(int(player1["Remaining"] / 3600))
p1minutes = str(int((player1["Remaining"] % 3600)/60))
p1seconds = str(player1["Remaining"] % 60)
p2hours = str(int(player2["Remaining"] / 3600))
p2minutes = str(int((player2["Remaining"] % 3600)/60))
p2seconds = str(player2["Remaining"] % 60)
#embed.set_field_at(1,name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
p1remaining = '%02d' % int(p1hours) + ":" + '%02d' % int(p1minutes) + ":" + '%02d' % int(p1seconds)
p2remaining = '%02d' % int(p2hours) + ":" + '%02d' % int(p2minutes) + ":" + '%02d' % int(p2seconds)
description = "".join([player1["Name"], " vs ", player2["Name"]])
embed = discord.Embed(title="Chess Clock", description=description, color=colour)
embed.add_field(name="ID", value=id, inline=False)
embed.add_field(name=playerone, value="`" + p1remaining + "`", inline=True)
embed.add_field(name=playertwo, value="`" + p2remaining + "` ", inline=True)
embed.add_field(name="Status", value="Running", inline=False)
embed.add_field(name="Pauses", value="".join([str(clock["Pauses"]),"(",str(clock["Judge Pauses"]),")"]), inline=True)
clockmsg = await message.channel.send(embed=embed)
with open(clockfile,"w") as clocks_file:
clocks[id]["Status"] = "Running"
clocks[id]["Status Time"] = str(datetime.now())
clocks[id]["Message ID"] = clockmsg.id
json.dump(clocks, clocks_file, indent=4)
else:
roles = message.author.roles
isJudge = False
for role in roles:
if role.name == "Judge":
isJudge = True
if isJudge == False:
await message.channel.send("You must be a Judge to effect Chess Clocks with an ID.")
else:
id = message.content.lower()[7:]
with open(clockfile,"r") as clocks_file:
clocks = json.load(clocks_file)
try:
clock = clocks[id]
except:
await message.channel.send("That clock does not exist!".format(message))
return
player1 = clock["Player1"]
player2 = clock["Player2"]
if clock["Status"] == "Running":
await message.channel.send("That clock is already running!".format(message))
elif clock["Status"] == "Finished":
response = "That clock is already finished!"
await message.channel.send(response.format(message))
else:
if int(clock["Active Player"]) == 1:
colour = 0xaa3333
playerone = "__**" + player1["Name"] + "**__"
playertwo = player2["Name"]
else:
colour = 0x3333aa
playerone = player1["Name"]
playertwo = "__**" + player2["Name"] + "**__"
#await message.channel.send("I would delete the prior message, with the clock times, but Python or DiscordPy is being dick. If you want to solve the problem, suck it.")
p1hours = str(int(player1["Remaining"] / 3600))
p1minutes = str(int((player1["Remaining"] % 3600)/60))
p1seconds = str(player1["Remaining"] % 60)
p2hours = str(int(player2["Remaining"] / 3600))
p2minutes = str(int((player2["Remaining"] % 3600)/60))
p2seconds = str(player2["Remaining"] % 60)
#embed.set_field_at(1,name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
p1remaining = '%02d' % int(p1hours) + ":" + '%02d' % int(p1minutes) + ":" + '%02d' % int(p1seconds)
p2remaining = '%02d' % int(p2hours) + ":" + '%02d' % int(p2minutes) + ":" + '%02d' % int(p2seconds)
description = "".join([player1["Name"], " vs ", player2["Name"]])
embed = discord.Embed(title="Chess Clock", description=description, color=colour)
embed.add_field(name="ID", value=id, inline=False)
embed.add_field(name=playerone, value="`" + p1remaining + "`", inline=True)
embed.add_field(name=playertwo, value="`" + p2remaining + "` ", inline=True)
embed.add_field(name="Status", value="Running", inline=False)
embed.add_field(name="Pauses", value="".join([str(clock["Pauses"]),"(",str(clock["Judge Pauses"]),")"]), inline=True)
clockmsg = await message.channel.send(embed=embed)
with open(clockfile,"w") as clocks_file:
clocks[id]["Status"] = "Running"
clocks[id]["Status Time"] = str(datetime.now())
clocks[id]["Message ID"] = clockmsg.id
json.dump(clocks, clocks_file, indent=4)
return
if message.content.lower().startswith("!update"):
if message.content.lower() == "!update":
clockfound = False
with open(clockfile,"r") as clocks_file:
clocks = json.load(clocks_file)
for (id,clock) in clocks.items():
if clockfound == False:
player1 = clock["Player1"]
player2 = clock["Player2"]
if clock["Status"] != "Finished" and int(clock["Channel ID"]) == message.channel.id and (int(player1["ID"]) == message.author.id or int(player2["ID"]) == message.author.id):
clockfound = True
break
if clockfound == False:
await message.channel.send("You do not currently have an active clock to update in this channel!".format(message))
elif clock["Status"] == "Paused" or clock["Status"] == "Not Started":
await message.channel.send("Your clock is currently not running. You need to !start your clock.".format(message))
else:
laststatus = datetime.strptime(clock["Status Time"],"%Y-%m-%d %H:%M:%S.%f")
if int(clock["Active Player"]) == 1:
remaining = player1["Remaining"]
activeplayer = player1["ID"]
else:
remaining = player2["Remaining"]
activeplayer = player2["ID"]
timepassed = int((datetime.now() - laststatus).total_seconds())
newremaining = remaining - timepassed
if newremaining <= 0:
newremaining = 0
if int(clock["Active Player"]) == 1:
colour = 0xaa3333
playerone = "__**" + player1["Name"] + "**__"
playertwo = player2["Name"]
p1hours = str(int(newremaining / 3600))
p1minutes = str(int((newremaining % 3600) / 60))
p1seconds = str(int(newremaining % 60))
p2hours = str(int(player2["Remaining"] / 3600))
p2minutes = str(int((player2["Remaining"] % 3600)/60))
p2seconds = str(player2["Remaining"] % 60)
else:
colour = 0x3333aa
playerone = player1["Name"]
playertwo = "__**" + player2["Name"] + "**__"
p1hours = str(int(player1["Remaining"] / 3600))
p1minutes = str(int((player1["Remaining"] % 3600)/60))
p1seconds = str(player1["Remaining"] % 60)
p2hours = str(int(newremaining / 3600))
p2minutes = str(int((newremaining % 3600) / 60))
p2seconds = str(int(newremaining % 60))
if newremaining == 0:
colour = 0x000000
#await message.channel.send("I would delete the prior message, with the clock times, but Python or DiscordPy is being dick. If you want to solve the problem, suck it.")
#embed.set_field_at(1,name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
p1remaining = '%02d' % int(p1hours) + ":" + '%02d' % int(p1minutes) + ":" + '%02d' % int(p1seconds)
p2remaining = '%02d' % int(p2hours) + ":" + '%02d' % int(p2minutes) + ":" + '%02d' % int(p2seconds)
description = "".join([player1["Name"], " vs ", player2["Name"]])
embed = discord.Embed(title="Chess Clock", description=description, color=colour)
embed.add_field(name="ID", value=id, inline=False)
embed.add_field(name=playerone, value="`" + p1remaining + "`", inline=True)
embed.add_field(name=playertwo, value="`" + p2remaining + "` ", inline=True)
if newremaining > 0:
embed.add_field(name="Status", value="Running", inline=False)
else:
embed.add_field(name="Status", value="Finished", inline=False)
response = "".join(["Your clock has expired, <@", str(activeplayer), ">!"])
await message.channel.send(response.format(message))
embed.add_field(name="Pauses", value="".join([str(clock["Pauses"]),"(",str(clock["Judge Pauses"]),")"]), inline=True)
clockmsg = await message.channel.send(embed=embed)
with open(clockfile,"w") as clocks_file:
clocks[id]["Status Time"] = str(datetime.now())
clocks[id]["Message ID"] = clockmsg.id
if int(clock["Active Player"]) == 1:
clocks[id]["Player1"]["Remaining"] = newremaining
else:
clocks[id]["Player2"]["Remaining"] = newremaining
if newremaining == 0:
clocks[id]["Status"] = "Finished"
json.dump(clocks, clocks_file, indent=4)
else:
roles = message.author.roles
isJudge = False
for role in roles:
if role.name == "Judge":
isJudge = True
if isJudge == False:
await message.channel.send("You must be a Judge to effect Chess Clocks with an ID.")
elif message.content.lower() == "!update all":
await message.channel.send("I haven't written the `!update all` command yet. Give me a break. Please? @Judge !".format(message))
else:
id = message.content.lower()[8:]
with open(clockfile,"r") as clocks_file:
clocks = json.load(clocks_file)
try:
clock = clocks[id]
except:
response = "That clock doesn't exist!"
await message.channel.send(response.format(message))
return
player1 = clock["Player1"]
player2 = clock["Player2"]
if clock["Status"] == "Finished":
response = "That clock is already finished!"
await message.channel.send(response.format(message))
elif clock["Status"] != "Running":
response = "That clock not running. Please use the !start command."
await message.channel.send(response.format(message))
else:
laststatus = datetime.strptime(clock["Status Time"],"%Y-%m-%d %H:%M:%S.%f")
if int(clock["Active Player"]) == 1:
remaining = player1["Remaining"]
activeplayer = player1["ID"]
else:
remaining = player2["Remaining"]
activeplayer = player2["ID"]
timepassed = int((datetime.now() - laststatus).total_seconds())
newremaining = remaining - timepassed
if newremaining <= 0:
newremaining = 0
if int(clock["Active Player"]) == 1:
colour = 0xaa3333
playerone = "__**" + player1["Name"] + "**__"
playertwo = player2["Name"]
p1hours = str(int(newremaining / 3600))
p1minutes = str(int((newremaining % 3600) / 60))
p1seconds = str(int(newremaining % 60))
p2hours = str(int(player2["Remaining"] / 3600))
p2minutes = str(int((player2["Remaining"] % 3600)/60))
p2seconds = str(player2["Remaining"] % 60)
else:
colour = 0x3333aa
playerone = player1["Name"]
playertwo = "__**" + player2["Name"] + "**__"
p1hours = str(int(player1["Remaining"] / 3600))
p1minutes = str(int((player1["Remaining"] % 3600)/60))
p1seconds = str(player1["Remaining"] % 60)
p2hours = str(int(newremaining / 3600))
p2minutes = str(int((newremaining % 3600) / 60))
p2seconds = str(int(newremaining % 60))
if newremaining == 0:
colour = 0x000000
#await message.channel.send("I would delete the prior message, with the clock times, but Python or DiscordPy is being dick. If you want to solve the problem, suck it.")
#embed.set_field_at(1,name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
p1remaining = '%02d' % int(p1hours) + ":" + '%02d' % int(p1minutes) + ":" + '%02d' % int(p1seconds)
p2remaining = '%02d' % int(p2hours) + ":" + '%02d' % int(p2minutes) + ":" + '%02d' % int(p2seconds)
description = "".join([player1["Name"], " vs ", player2["Name"]])
embed = discord.Embed(title="Chess Clock", description=description, color=colour)
embed.add_field(name="ID", value=id, inline=False)
embed.add_field(name=playerone, value="`" + p1remaining + "`", inline=True)
embed.add_field(name=playertwo, value="`" + p2remaining + "` ", inline=True)
if newremaining > 0:
embed.add_field(name="Status", value="Running", inline=False)
else:
embed.add_field(name="Status", value="Finished", inline=False)
response = "".join(["Your clock has expired, <@", str(activeplayer), ">!"])
await message.channel.send(response.format(message))
embed.add_field(name="Pauses", value="".join([str(clock["Pauses"]),"(",str(clock["Judge Pauses"]),")"]), inline=True)
clockmsg = await message.channel.send(embed=embed)
with open(clockfile,"w") as clocks_file:
clocks[id]["Status Time"] = str(datetime.now())
clocks[id]["Message ID"] = clockmsg.id
if int(clock["Active Player"]) == 1:
clocks[id]["Player1"]["Remaining"] = newremaining
else:
clocks[id]["Player2"]["Remaining"] = newremaining
if newremaining == 0:
clocks[id]["Status"] = "Finished"
json.dump(clocks, clocks_file, indent=4)
return
if message.content.lower().startswith("!switch"):
if message.content.lower() == "!switch":
clockfound = False
with open(clockfile,"r") as clocks_file:
clocks = json.load(clocks_file)
for (id,clock) in clocks.items():
if clockfound == False:
player1 = clock["Player1"]
player2 = clock["Player2"]
if clock["Status"] != "Finished" and int(clock["Channel ID"]) == message.channel.id and (int(player1["ID"]) == message.author.id or int(player2["ID"]) == message.author.id):
clockfound = True
break
if clockfound == False:
await message.channel.send("You do not currently have an active clock to update in this channel!".format(message))
elif clock["Status"] == "Paused" or clock["Status"] == "Not Started":
if int(clock["Active Player"]) == 2: #reversed logic. it's intentional
playerone = "__**" + player1["Name"] + "**__"
playertwo = player2["Name"]
newplayer = 1
else:
playerone = player1["Name"]
playertwo = "__**" + player2["Name"] + "**__"
newplayer = 2
if clock["Status"] == "Paused":
colour = 0x33aa33
else:
colour = 0xdddddd
p1hours = str(int(player1["Remaining"] / 3600))
p1minutes = str(int((player1["Remaining"] % 3600)/60))
p1seconds = str(player1["Remaining"] % 60)
p2hours = str(int(player2["Remaining"] / 3600))
p2minutes = str(int((player2["Remaining"] % 3600)/60))
p2seconds = str(player2["Remaining"] % 60)
p1remaining = '%02d' % int(p1hours) + ":" + '%02d' % int(p1minutes) + ":" + '%02d' % int(p1seconds)
p2remaining = '%02d' % int(p2hours) + ":" + '%02d' % int(p2minutes) + ":" + '%02d' % int(p2seconds)
description = "".join([player1["Name"], " vs ", player2["Name"]])
embed = discord.Embed(title="Chess Clock", description=description, color=colour)
embed.add_field(name="ID", value=id, inline=False)
embed.add_field(name=playerone, value="`" + p1remaining + "`", inline=True)
embed.add_field(name=playertwo, value="`" + p2remaining + "` ", inline=True)
embed.add_field(name="Status", value="Running", inline=False)
embed.add_field(name="Pauses", value="".join([str(clock["Pauses"]),"(",str(clock["Judge Pauses"]),")"]), inline=True)
clockmsg = await message.channel.send(embed=embed)
with open(clockfile,"w") as clocks_file:
clocks[id]["Status Time"] = str(datetime.now())
clocks[id]["Message ID"] = clockmsg.id
clocks[id]["Active Player"] = newplayer
json.dump(clocks, clocks_file, indent=4)
else:
laststatus = datetime.strptime(clock["Status Time"],"%Y-%m-%d %H:%M:%S.%f")
if int(clock["Active Player"]) == 1:
remaining = player1["Remaining"]
activeplayer = player1["ID"]
else:
remaining = player2["Remaining"]
activeplayer = player2["ID"]
timepassed = int((datetime.now() - laststatus).total_seconds())
newremaining = remaining - timepassed
if newremaining <= 0:
newremaining = 0
if int(clock["Active Player"]) == 1:
colour = 0x3333aa
playerone = player1["Name"]
playertwo = "__**" + player2["Name"] + "**__"
p1hours = str(int(newremaining / 3600))
p1minutes = str(int((newremaining % 3600) / 60))
p1seconds = str(int(newremaining % 60))
p2hours = str(int(player2["Remaining"] / 3600))
p2minutes = str(int((player2["Remaining"] % 3600)/60))
p2seconds = str(player2["Remaining"] % 60)
else:
colour = 0xaa3333
playerone = "__**" +player1["Name"] + "**__"
playertwo = player2["Name"]
p1hours = str(int(player1["Remaining"] / 3600))
p1minutes = str(int((player1["Remaining"] % 3600)/60))
p1seconds = str(player1["Remaining"] % 60)
p2hours = str(int(newremaining / 3600))
p2minutes = str(int((newremaining % 3600) / 60))
p2seconds = str(int(newremaining % 60))
if newremaining == 0:
colour = 0x000000
#await message.channel.send("I would delete the prior message, with the clock times, but Python or DiscordPy is being dick. If you want to solve the problem, suck it.")
#embed.set_field_at(1,name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
p1remaining = '%02d' % int(p1hours) + ":" + '%02d' % int(p1minutes) + ":" + '%02d' % int(p1seconds)
p2remaining = '%02d' % int(p2hours) + ":" + '%02d' % int(p2minutes) + ":" + '%02d' % int(p2seconds)
description = "".join([player1["Name"], " vs ", player2["Name"]])
embed = discord.Embed(title="Chess Clock", description=description, color=colour)
embed.add_field(name="ID", value=id, inline=False)
embed.add_field(name=playerone, value="`" + p1remaining + "`", inline=True)
embed.add_field(name=playertwo, value="`" + p2remaining + "` ", inline=True)
if newremaining > 0:
embed.add_field(name="Status", value="Running", inline=False)
else:
embed.add_field(name="Status", value="Finished", inline=False)
response = "".join(["Your clock has expired, <@", str(activeplayer), ">!"])
await message.channel.send(response.format(message))
embed.add_field(name="Pauses", value="".join([str(clock["Pauses"]),"(",str(clock["Judge Pauses"]),")"]), inline=True)
clockmsg = await message.channel.send(embed=embed)
with open(clockfile,"w") as clocks_file:
clocks[id]["Status Time"] = str(datetime.now())
clocks[id]["Message ID"] = clockmsg.id
if int(clock["Active Player"]) == 1:
clocks[id]["Player1"]["Remaining"] = newremaining
clocks[id]["Active Player"] = 2
else:
clocks[id]["Player2"]["Remaining"] = newremaining
clocks[id]["Active Player"] = 1
if newremaining == 0:
clocks[id]["Status"] = "Finished"
json.dump(clocks, clocks_file, indent=4)
return
if message.content.lower().startswith("!end"):
if message.content.lower() == "!end":
clockfound = False
with open(clockfile,"r") as clocks_file:
clocks = json.load(clocks_file)
for (id,clock) in clocks.items():
if clockfound == False:
player1 = clock["Player1"]
player2 = clock["Player2"]
if clock["Status"] != "Finished" and int(clock["Channel ID"]) == message.channel.id and (int(player1["ID"]) == message.author.id or int(player2["ID"]) == message.author.id):
clockfound = True
if clockfound == False:
await message.channel.send("You do not currently have an active clock to end in this channel!".format(message))
elif clock["Status"] != "Running":
#await message.channel.delete(clockmsg)
#await message.channel.send("I would delete the prior message, with the clock times, but Python or DiscordPy is being dick. If you want to solve the problem, suck it.")
p1hours = str(int(player1["Remaining"] / 3600))
p1minutes = str(int((player1["Remaining"] % 3600)/60))
p1seconds = str(player1["Remaining"] % 60)
p2hours = str(int(player2["Remaining"] / 3600))
p2minutes = str(int((player2["Remaining"] % 3600)/60))
p2seconds = str(player2["Remaining"] % 60)
p1remaining = '%02d' % int(p1hours) + ":" + '%02d' % int(p1minutes) + ":" + '%02d' % int(p1seconds)
p2remaining = '%02d' % int(p2hours) + ":" + '%02d' % int(p2minutes) + ":" + '%02d' % int(p2seconds)
description = "".join([player1["Name"], " vs ", player2["Name"]])
embed = discord.Embed(title="Chess Clock", description=description, color=0x000000)
embed.add_field(name="ID", value=id, inline=False)
embed.add_field(name=player1["Name"], value="`" + p1remaining + "`", inline=True)
embed.add_field(name=player2["Name"], value="`" + p2remaining + "` ", inline=True)
embed.add_field(name="Status", value="Finished", inline=False)
embed.add_field(name="Pauses", value="".join([str(clock["Pauses"]),"(",str(clock["Judge Pauses"]),")"]), inline=True)
clockmsg = await message.channel.send(embed=embed)
with open(clockfile,"w") as clocks_file:
clocks[id]["Status"] = "Finished"
clocks[id]["Message ID"] = clockmsg.id
json.dump(clocks, clocks_file, indent=4)
else:
laststatus = datetime.strptime(clock["Status Time"],"%Y-%m-%d %H:%M:%S.%f")
if int(clock["Active Player"]) == 1:
remaining = player1["Remaining"]
activeplayer = player1["ID"]
else:
remaining = player2["Remaining"]
activeplayer = player2["ID"]
timepassed = int((datetime.now() - laststatus).total_seconds())
newremaining = remaining - timepassed
if newremaining <= 0:
newremaining = 0
if int(clock["Active Player"]) == 1:
playerone = "__**" + player1["Name"] + "**__"
playertwo = player2["Name"]
p1hours = str(int(newremaining / 3600))
p1minutes = str(int((newremaining % 3600) / 60))
p1seconds = str(int(newremaining % 60))
p2hours = str(int(player2["Remaining"] / 3600))
p2minutes = str(int((player2["Remaining"] % 3600)/60))
p2seconds = str(player2["Remaining"] % 60)
else:
playerone = player1["Name"]
playertwo = "__**" + player2["Name"] + "**__"
p1hours = str(int(player1["Remaining"] / 3600))
p1minutes = str(int((player1["Remaining"] % 3600)/60))
p1seconds = str(player1["Remaining"] % 60)
p2hours = str(int(newremaining / 3600))
p2minutes = str(int((newremaining % 3600) / 60))
p2seconds = str(int(newremaining % 60))
colour = 0x000000
#await message.channel.send("I would delete the prior message, with the clock times, but Python or DiscordPy is being dick. If you want to solve the problem, suck it.")
#embed.set_field_at(1,name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
p1remaining = '%02d' % int(p1hours) + ":" + '%02d' % int(p1minutes) + ":" + '%02d' % int(p1seconds)
p2remaining = '%02d' % int(p2hours) + ":" + '%02d' % int(p2minutes) + ":" + '%02d' % int(p2seconds)
description = "".join([player1["Name"], " vs ", player2["Name"]])
embed = discord.Embed(title="Chess Clock", description=description, color=colour)
embed.add_field(name="ID", value=id, inline=False)
embed.add_field(name=playerone, value="`" + p1remaining + "`", inline=True)
embed.add_field(name=playertwo, value="`" + p2remaining + "` ", inline=True)
if newremaining == 0:
response = "".join(["Your clock has expired, <@", str(activeplayer), ">!"])
await message.channel.send(response.format(message))
embed.add_field(name="Status", value="Finished", inline=False)
embed.add_field(name="Pauses", value="".join([str(clock["Pauses"]),"(",str(clock["Judge Pauses"]),")"]), inline=True)
clockmsg = await message.channel.send(embed=embed)
with open(clockfile,"w") as clocks_file:
clocks[id]["Status Time"] = str(datetime.now())
clocks[id]["Message ID"] = clockmsg.id
if int(clock["Active Player"]) == 1:
clocks[id]["Player1"]["Remaining"] = newremaining
else:
clocks[id]["Player2"]["Remaining"] = newremaining
clocks[id]["Status"] = "Finished"
json.dump(clocks, clocks_file, indent=4)
else:
roles = message.author.roles
isJudge = False
for role in roles:
if role.name == "Judge":
isJudge = True
if isJudge == False:
await message.channel.send("You must be a Judge to effect Chess Clocks with an ID.")
else:
id = message.content.lower()[5:]
with open(clockfile,"r") as clocks_file:
clocks = json.load(clocks_file)
try:
clock = clocks[id]
except:
response = "That clock doesn't exist!"
await message.channel.send(response.format(message))
return
player1 = clock["Player1"]
player2 = clock["Player2"]
if clock["Status"] == "Finished":
response = "That clock is already finished!"
await message.channel.send(response.format(message))
#await message.channel.send("I would delete the prior message, with the clock times, but Python or DiscordPy is being dick. If you want to solve the problem, suck it.")
if clock["Status"] != "Running":
p1hours = str(int(player1["Remaining"] / 3600))
p1minutes = str(int((player1["Remaining"] % 3600)/60))
p1seconds = str(player1["Remaining"] % 60)
p2hours = str(int(player2["Remaining"] / 3600))
p2minutes = str(int((player2["Remaining"] % 3600)/60))
p2seconds = str(player2["Remaining"] % 60)
p1remaining = '%02d' % int(p1hours) + ":" + '%02d' % int(p1minutes) + ":" + '%02d' % int(p1seconds)
p2remaining = '%02d' % int(p2hours) + ":" + '%02d' % int(p2minutes) + ":" + '%02d' % int(p2seconds)
description = "".join([player1["Name"], " vs ", player2["Name"]])
embed = discord.Embed(title="Chess Clock", description=description, color=0x000000)
embed.add_field(name="ID", value=id, inline=False)
embed.add_field(name=player1["Name"], value="`" + p1remaining + "`", inline=True)
embed.add_field(name=player2["Name"], value="`" + p2remaining + "` ", inline=True)
embed.add_field(name="Status", value="Finished", inline=False)
embed.add_field(name="Pauses", value="".join([str(clock["Pauses"]),"(",str(clock["Judge Pauses"]),")"]), inline=True)
clockmsg = await message.channel.send(embed=embed)
with open(clockfile,"w") as clocks_file:
clocks[id]["Status"] = "Finished"
clocks[id]["Message ID"] = clockmsg.id
json.dump(clocks, clocks_file, indent=4)
else:
laststatus = datetime.strptime(clock["Status Time"],"%Y-%m-%d %H:%M:%S.%f")
if int(clock["Active Player"]) == 1:
remaining = player1["Remaining"]
activeplayer = player1["ID"]
else:
remaining = player2["Remaining"]
activeplayer = player2["ID"]
timepassed = int((datetime.now() - laststatus).total_seconds())
newremaining = remaining - timepassed
if newremaining <= 0:
newremaining = 0
if int(clock["Active Player"]) == 1:
playerone = "__**" + player1["Name"] + "**__"
playertwo = player2["Name"]
p1hours = str(int(newremaining / 3600))
p1minutes = str(int((newremaining % 3600) / 60))
p1seconds = str(int(newremaining % 60))
p2hours = str(int(player2["Remaining"] / 3600))
p2minutes = str(int((player2["Remaining"] % 3600)/60))
p2seconds = str(player2["Remaining"] % 60)
else:
playerone = player1["Name"]
playertwo = "__**" + player2["Name"] + "**__"
p1hours = str(int(player1["Remaining"] / 3600))
p1minutes = str(int((player1["Remaining"] % 3600)/60))
p1seconds = str(player1["Remaining"] % 60)
p2hours = str(int(newremaining / 3600))
p2minutes = str(int((newremaining % 3600) / 60))
p2seconds = str(int(newremaining % 60))
colour = 0x000000
#await message.channel.send("I would delete the prior message, with the clock times, but Python or DiscordPy is being dick. If you want to solve the problem, suck it.")
#embed.set_field_at(1,name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
p1remaining = '%02d' % int(p1hours) + ":" + '%02d' % int(p1minutes) + ":" + '%02d' % int(p1seconds)
p2remaining = '%02d' % int(p2hours) + ":" + '%02d' % int(p2minutes) + ":" + '%02d' % int(p2seconds)
description = "".join([player1["Name"], " vs ", player2["Name"]])
embed = discord.Embed(title="Chess Clock", description=description, color=colour)
embed.add_field(name="ID", value=id, inline=False)
embed.add_field(name=playerone, value="`" + p1remaining + "`", inline=True)
embed.add_field(name=playertwo, value="`" + p2remaining + "` ", inline=True)
if newremaining == 0:
response = "".join(["Your clock has expired, <@", str(activeplayer), ">!"])
await message.channel.send(response.format(message))
embed.add_field(name="Status", value="Finished", inline=False)
embed.add_field(name="Pauses", value="".join([str(clock["Pauses"]),"(",str(clock["Judge Pauses"]),")"]), inline=True)
clockmsg = await message.channel.send(embed=embed)
with open(clockfile,"w") as clocks_file:
clocks[id]["Status Time"] = str(datetime.now())
clocks[id]["Message ID"] = clockmsg.id
if int(clock["Active Player"]) == 1:
clocks[id]["Player1"]["Remaining"] = newremaining
else:
clocks[id]["Player2"]["Remaining"] = newremaining
clocks[id]["Status"] = "Finished"
json.dump(clocks, clocks_file, indent=4)
return
if message.content.lower().startswith("!pause"):
if message.content.lower() == "!pause":
clockfound = False
with open(clockfile,"r") as clocks_file:
clocks = json.load(clocks_file)
for (id,clock) in clocks.items():
if clockfound == False:
player1 = clock["Player1"]
player2 = clock["Player2"]
if clock["Status"] != "Finished" and int(clock["Channel ID"]) == message.channel.id and (int(player1["ID"]) == message.author.id or int(player2["ID"]) == message.author.id):
clockfound = True
if clockfound == False:
await message.channel.send("You do not currently have an active clock to end in this channel!".format(message))
elif clock["Status"] != "Running":
await message.channel.send("Your clock is not currently running. Use the !start command.".format(message))
else:
laststatus = datetime.strptime(clock["Status Time"],"%Y-%m-%d %H:%M:%S.%f")
if int(clock["Active Player"]) == 1:
remaining = player1["Remaining"]
activeplayer = player1["ID"]
else:
remaining = player2["Remaining"]
activeplayer = player2["ID"]
timepassed = int((datetime.now() - laststatus).total_seconds())
newremaining = remaining - timepassed
if newremaining <= 0:
newremaining = 0
if int(clock["Active Player"]) == 1:
playerone = "__**" + player1["Name"] + "**__"
playertwo = player2["Name"]
p1hours = str(int(newremaining / 3600))
p1minutes = str(int((newremaining % 3600) / 60))
p1seconds = str(int(newremaining % 60))
p2hours = str(int(player2["Remaining"] / 3600))
p2minutes = str(int((player2["Remaining"] % 3600)/60))
p2seconds = str(player2["Remaining"] % 60)
else:
playerone = player1["Name"]
playertwo = "__**" + player2["Name"] + "**__"
p1hours = str(int(player1["Remaining"] / 3600))
p1minutes = str(int((player1["Remaining"] % 3600)/60))
p1seconds = str(player1["Remaining"] % 60)
p2hours = str(int(newremaining / 3600))
p2minutes = str(int((newremaining % 3600) / 60))
p2seconds = str(int(newremaining % 60))
colour = 0x33aa33
#await message.channel.send("I would delete the prior message, with the clock times, but Python or DiscordPy is being dick. If you want to solve the problem, suck it.")
#embed.set_field_at(1,name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
p1remaining = '%02d' % int(p1hours) + ":" + '%02d' % int(p1minutes) + ":" + '%02d' % int(p1seconds)
p2remaining = '%02d' % int(p2hours) + ":" + '%02d' % int(p2minutes) + ":" + '%02d' % int(p2seconds)
description = "".join([player1["Name"], " vs ", player2["Name"]])
embed = discord.Embed(title="Chess Clock", description=description, color=colour)
embed.add_field(name="ID", value=id, inline=False)
embed.add_field(name=playerone, value="`" + p1remaining + "`", inline=True)
embed.add_field(name=playertwo, value="`" + p2remaining + "` ", inline=True)
if newremaining == 0:
response = "".join(["Your clock has expired, <@", str(activeplayer), ">!"])
await message.channel.send(response.format(message))
embed.add_field(name="Status", value="Finished", inline=False)
else:
embed.add_field(name="Status", value="Paused", inline=False)
embed.add_field(name="Pauses", value="".join([str(int(str(clock["Pauses"]))+1),"(",str(clock["Judge Pauses"]),")"]), inline=True)
clockmsg = await message.channel.send(embed=embed)
with open(clockfile,"w") as clocks_file:
clocks[id]["Status Time"] = str(datetime.now())
clocks[id]["Message ID"] = clockmsg.id
clocks[id]["Pauses"] = str(int(str(clock["Pauses"]))+1)
if int(clock["Active Player"]) == 1:
clocks[id]["Player1"]["Remaining"] = newremaining
else:
clocks[id]["Player2"]["Remaining"] = newremaining
if newremaining == 0:
clocks[id]["Status"] = "Finished"
else:
clocks[id]["Status"] = "Paused"
json.dump(clocks, clocks_file, indent=4)
else:
roles = message.author.roles
isJudge = False
for role in roles:
if role.name == "Judge":
isJudge = True
if isJudge == False:
await message.channel.send("You must be a Judge to effect Chess Clocks with an ID.")
else:
id = message.content.lower()[7:]
with open(clockfile,"r") as clocks_file:
clocks = json.load(clocks_file)
try:
clock = clocks[id]
except:
response = "That clock doesn't exist!"
await message.channel.send(response.format(message))
return
player1 = clock["Player1"]
player2 = clock["Player2"]
if clock["Status"] == "Finished":
response = "That clock is already finished!"
await message.channel.send(response.format(message))
#await message.channel.send("I would delete the prior message, with the clock times, but Python or DiscordPy is being dick. If you want to solve the problem, suck it.")
if clock["Status"] != "Running":
await message.channel.send("That clock is not currently running. Use the !start command.".format(message))
else:
laststatus = datetime.strptime(clock["Status Time"],"%Y-%m-%d %H:%M:%S.%f")
if int(clock["Active Player"]) == 1:
remaining = player1["Remaining"]
activeplayer = player1["ID"]
else:
remaining = player2["Remaining"]
activeplayer = player2["ID"]
timepassed = int((datetime.now() - laststatus).total_seconds())
newremaining = remaining - timepassed
if newremaining <= 0:
newremaining = 0
if int(clock["Active Player"]) == 1:
playerone = "__**" + player1["Name"] + "**__"
playertwo = player2["Name"]
p1hours = str(int(newremaining / 3600))
p1minutes = str(int((newremaining % 3600) / 60))
p1seconds = str(int(newremaining % 60))
p2hours = str(int(player2["Remaining"] / 3600))
p2minutes = str(int((player2["Remaining"] % 3600)/60))
p2seconds = str(player2["Remaining"] % 60)
else:
playerone = player1["Name"]
playertwo = "__**" + player2["Name"] + "**__"
p1hours = str(int(player1["Remaining"] / 3600))
p1minutes = str(int((player1["Remaining"] % 3600)/60))
p1seconds = str(player1["Remaining"] % 60)
p2hours = str(int(newremaining / 3600))
p2minutes = str(int((newremaining % 3600) / 60))
p2seconds = str(int(newremaining % 60))
colour = 0x33aa33
#await message.channel.send("I would delete the prior message, with the clock times, but Python or DiscordPy is being dick. If you want to solve the problem, suck it.")
#embed.set_field_at(1,name="Remaining", value="`" + '%02d' % int(hours) + ":" + '%02d' % int(minutes) + ":" + '%02d' % int(seconds) + "` ", inline=True)
p1remaining = '%02d' % int(p1hours) + ":" + '%02d' % int(p1minutes) + ":" + '%02d' % int(p1seconds)
p2remaining = '%02d' % int(p2hours) + ":" + '%02d' % int(p2minutes) + ":" + '%02d' % int(p2seconds)
description = "".join([player1["Name"], " vs ", player2["Name"]])
embed = discord.Embed(title="Chess Clock", description=description, color=colour)
embed.add_field(name="ID", value=id, inline=False)
embed.add_field(name=playerone, value="`" + p1remaining + "`", inline=True)
embed.add_field(name=playertwo, value="`" + p2remaining + "` ", inline=True)
if newremaining == 0:
response = "".join(["Your clock has expired, <@", str(activeplayer), ">!"])
await message.channel.send(response.format(message))
embed.add_field(name="Status", value="Finished", inline=False)
embed.add_field(name="Pauses", value="".join([str(int(str(clock["Pauses"]))+1),"(",str(int(str(clock["Judge Pauses"]))+1),")"]), inline=True)
clockmsg = await message.channel.send(embed=embed)