forked from xSerpentineX/BubbleBoiBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BubblyBoiBot.py
799 lines (722 loc) · 40.4 KB
/
BubblyBoiBot.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
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
import os
import sys
import time
import string
import asyncio
import socketio
import requests
import colorama as color
import commentjson
import hitherdither
from io import BytesIO
import random as r
from PIL import Image, ImageDraw, ImageFont
color.init(autoreset="true")
clear = True
def errexit(errcode, sleep):
time.sleep(sleep)
os._exit(errcode)
try:
with open('settings.json') as settings_file:
SETTINGS = commentjson.load(settings_file)
messageLength = len(SETTINGS["SpamMessage"])
except Exception as e:
print(f"{color.Back.RED}{color.Style.BRIGHT}Error: Loading json file.")
print(e)
errexit(1,5)
if len(SETTINGS["SpamMessage"]) > 100:
under_101 = False
else:
under_101 = True
async def sendSpamMessage():
global under_101
if SETTINGS["SpamServer"]:
if not under_101:
if SETTINGS["BrightOrDim"].lower() == "bright":
print(f"{color.Back.YELLOW}{color.Style.BRIGHT}Warning: Your message has {messageLength - 100} extra characters.")
else:
print(f"{color.Back.YELLOW}{color.Style.DIM}Warning: Your message has {messageLength - 100} extra characters.")
else:
if SETTINGS["AutomaticFormatting"]:
await sio.emit("chat", f"{SETTINGS['SpamMessage']}".replace(".", ","))
else:
await sio.emit("chat", f"{SETTINGS['SpamMessage']}")
if not (SETTINGS["Algorithm"].lower() == 'cluster' or SETTINGS["Algorithm"].lower() == 'yliluoma'):
print(f"{color.Back.RED}{color.Style.BRIGHT}Error: Algorithm \"{SETTINGS['Algorithm']}\" was not found. See settings.json and change \"Algorithm\" to \"cluster\" or \"yliluoma\".")
errexit(1,5)
if not (SETTINGS["Port"] == 5001 or SETTINGS["Port"] == 5002 or SETTINGS["Port"] == 5003):
print(f"{color.Back.RED}{color.Style.BRIGHT}Error: Port {SETTINGS['Port']} does not exist. See settings.json and change \"Port\" to 5001, 5002 or 5003.")
errexit(1,5)
if not (SETTINGS["ColourTheme"].lower() == "emerald" or SETTINGS["ColourTheme"].lower() == "fire" or SETTINGS["ColourTheme"].lower() == "ocean" or SETTINGS["ColourTheme"].lower() == "storm" or SETTINGS["ColourTheme"].lower() == "candy" or SETTINGS["ColourTheme"].lower() == "plain" or SETTINGS["ColourTheme"].lower() == "gold"):
print(f"{color.Fore.RED}Warning: Colour Theme \"{SETTINGS['ColourTheme']}\" does not exist. See settings.json and change \"ColourTheme\" to a correct theme listed (Using plain as default).")
print()
if not (SETTINGS["BrightOrDim"].lower() == "dim" or SETTINGS["BrightOrDim"].lower() == "bright"):
print(f"{color.Fore.RED}Warning: \"BrightOrDim\" is not set to either \"bright\" or \"dim\". Please change \"BrightOrDim\" to either \"bright\" or \"dim\" (Using DIM as default).")
print()
if len(sys.argv) == 2:
"""
U can set port using command line
"""
SETTINGS['Port'] = sys.argv[1]
GAME_DATA = {'died': False}
sio = socketio.AsyncClient(logger=False, reconnection=True) # U can turn logger True, if u need to catch events that are not described in current version of program
"""
Game palette
"""
palette = hitherdither.palette.Palette(
[0xFFFFFF, 0x000000, 0xC1C1C1, 0x4C4C4C,
0xEF130B, 0x740B07, 0xFF7100, 0xC23800,
0xFFE400, 0xE8A200, 0x00CC00, 0x005510,
0x00B2FF, 0x00569E, 0x231FD3, 0x0E0865,
0xA300BA, 0x550069, 0xD37CAA, 0xA75574,
0xA0522D, 0x63300D]
)
async def dither(word):
if (SETTINGS["RandomImage"]):
path = "images/"
files = os.listdir(path)
index = r.randrange(0, len(files))
image2Draw = files[index]
else:
image2Draw = SETTINGS["ImageToDraw"]
img = Image.open("images/" + image2Draw)
img = img.resize((int(275), int(150)))
if SETTINGS["BrightOrDim"].lower() == "bright":
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.LIGHTGREEN_EX}{color.Style.BRIGHT}Drawing: {image2Draw} with {img.size}")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.LIGHTRED_EX}{color.Style.BRIGHT}Drawing: {image2Draw} with {img.size}")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.LIGHTBLUE_EX}{color.Style.BRIGHT}Drawing: {image2Draw} with {img.size}")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}Drawing: {image2Draw} with {img.size}")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}Drawing: {image2Draw} with {img.size}")
elif SETTINGS["ColourTheme"].lower() == "plain":
print(f"Drawing: {image2Draw} with {img.size}")
else:
print(f"Drawing: {image2Draw} with {img.size}")
else:
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.LIGHTGREEN_EX}{color.Style.DIM}Drawing: {image2Draw} with {img.size}")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.LIGHTRED_EX}{color.Style.DIM}Drawing: {image2Draw} with {img.size}")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.LIGHTBLUE_EX}{color.Style.DIM}Drawing: {image2Draw} with {img.size}")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.YELLOW}{color.Style.DIM}Drawing: {image2Draw} with {img.size}")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.YELLOW}{color.Style.DIM}Drawing: {image2Draw} with {img.size}")
elif SETTINGS["ColourTheme"].lower() == "plain":
print(f"Drawing: {image2Draw} with {img.size}")
else:
print(f"Drawing: {image2Draw} with {img.size}")
if SETTINGS["Algorithm"].lower() == 'cluster':
img_dithered = hitherdither.ordered.cluster.cluster_dot_dithering(img, palette, [1, 1, 1], 4)
return img_dithered
elif SETTINGS["Algorithm"].lower() == 'yliluoma':
img_dithered = hitherdither.ordered.yliluoma.yliluomas_1_ordered_dithering(img, palette, order=8)
return img_dithered
def GenRandomLine(length=8, chars=string.ascii_letters):
"""
Generate random line
"""
return ''.join([r.choice(chars) for i in range(length)])
@sio.on('connect')
async def on_connect():
"""
On connection to the lobby we must introduce ourselves
"""
if SETTINGS["BrightOrDim"].lower() == "bright":
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}Connection established")
print()
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}Connection established")
print()
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}Connection established")
print()
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.BLUE}{color.Style.BRIGHT}Connection established")
print()
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}Connection established")
print()
elif SETTINGS["ColourTheme"].lower() == "plain":
print("Connection established")
print()
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}Connection established")
print()
else:
print("Connection established")
print()
else:
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.WHITE}{color.Style.DIM}Connection established")
print()
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.YELLOW}{color.Style.DIM}Connection established")
print()
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.WHITE}{color.Style.DIM}Connection established")
print()
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.BLUE}{color.Style.DIM}Connection established")
print()
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.YELLOW}{color.Style.DIM}Connection established")
print()
elif SETTINGS["ColourTheme"].lower() == "plain":
print("Connection established")
print()
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f"{color.Fore.WHITE}{color.Style.DIM}Connection established")
print()
else:
print("Connection established")
print()
if (SETTINGS["RandomAvatar"]):
num1 = r.randint(1, 5)
num2 = r.randint(1, 5)
num3 = r.randint(1, 5)
num4 = r.randint(1, 5)
else:
num1 = -1
num2 = -1
num3 = -1
num4 = -1
await sio.emit('userData' , {"name": SETTINGS['BotName'], "code":"", "avatar": [num1, num2, num3, num4], "join": SETTINGS['Join'], "language": SETTINGS['Language'], "createPrivate": False})
del num1,num2,num3,num4
await sio.emit('chat', f'{SETTINGS["SpamMessage"]}')
@sio.on('lobbyConnected')
async def on_lobbyConnected(data):
global clear
"""
When we connected to the lobby we print out the current round, the number of players, the players names and their score, we also also store that info into GAME_DATA dict
"""
if SETTINGS["BrightOrDim"].lower() == "bright":
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}Lobby connected")
print(f"{color.Fore.GREEN}{color.Style.BRIGHT}Round {data['round']} / {data['roundMax']}")
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}There {len(data['players'])} players: ")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}Lobby connected")
print(f"{color.Fore.RED}{color.Style.BRIGHT}Round {data['round']} / {data['roundMax']}")
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}There {len(data['players'])} players: ")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}Lobby connected")
print(f"{color.Fore.BLUE}{color.Style.BRIGHT}Round {data['round']} / {data['roundMax']}")
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}There {len(data['players'])} players: ")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}Lobby connected")
print(f"{color.Fore.CYAN}{color.Style.BRIGHT}Round {data['round']} / {data['roundMax']}")
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}There {len(data['players'])} players: ")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}Lobby connected")
print(f"{color.Fore.MAGENTA}{color.Style.BRIGHT}Round {data['round']} / {data['roundMax']}")
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}There {len(data['players'])} players: ")
elif SETTINGS["ColourTheme"].lower() == "plain":
print("Lobby connected")
print(f"Round {data['round']} / {data['roundMax']}")
print(f"There {len(data['players'])} players: ")
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}Lobby connected")
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}Round {data['round']} / {data['roundMax']}")
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}There {len(data['players'])} players: ")
else:
print("Lobby connected")
print(f"Round {data['round']} / {data['roundMax']}")
print(f"There {len(data['players'])} players: ")
else:
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.WHITE}{color.Style.DIM}Lobby connected")
print(f"{color.Fore.GREEN}{color.Style.DIM}Round {data['round']} / {data['roundMax']}")
print(f"{color.Fore.WHITE}{color.Style.DIM}There {len(data['players'])} players: ")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.YELLOW}{color.Style.DIM}Lobby connected")
print(f"{color.Fore.RED}{color.Style.DIM}Round {data['round']} / {data['roundMax']}")
print(f"{color.Fore.YELLOW}{color.Style.DIM}There {len(data['players'])} players: ")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.WHITE}{color.Style.DIM}Lobby connected")
print(f"{color.Fore.BLUE}{color.Style.DIM}Round {data['round']} / {data['roundMax']}")
print(f"{color.Fore.WHITE}{color.Style.DIM}There {len(data['players'])} players: ")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.YELLOW}{color.Style.DIM}Lobby connected")
print(f"{color.Fore.CYAN}{color.Style.DIM}Round {data['round']} / {data['roundMax']}")
print(f"{color.Fore.YELLOW}{color.Style.DIM}There {len(data['players'])} players: ")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.YELLOW}{color.Style.DIM}Lobby connected")
print(f"{color.Fore.MAGENTA}{color.Style.DIM}Round {data['round']} / {data['roundMax']}")
print(f"{color.Fore.YELLOW}{color.Style.DIM}There {len(data['players'])} players: ")
elif SETTINGS["ColourTheme"].lower() == "plain":
print("Lobby connected")
print(f"Round {data['round']} / {data['roundMax']}")
print(f"There {len(data['players'])} players: ")
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f"{color.Fore.YELLOW}{color.Style.DIM}Lobby connected")
print(f"{color.Fore.WHITE}{color.Style.DIM}Round {data['round']} / {data['roundMax']}")
print(f"{color.Fore.YELLOW}{color.Style.DIM}There {len(data['players'])} players: ")
else:
print("Lobby connected")
print(f"Round {data['round']} / {data['roundMax']}")
print(f"There {len(data['players'])} players: ")
doLeave = False
for player in data['players']:
if SETTINGS["BrightOrDim"].lower() == "bright":
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f" {color.Fore.LIGHTGREEN_EX}{player['id']} = {player['name']} > {player['score']}")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f" {color.Fore.LIGHTYELLOW_EX}{player['id']} = {player['name']} > {player['score']}")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f" {color.Fore.LIGHTCYAN_EX}{player['id']} = {player['name']} > {player['score']}")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f" {color.Fore.LIGHTYELLOW_EX}{player['id']} = {player['name']} > {player['score']}")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f" {color.Fore.LIGHTCYAN_EX}{player['id']} = {player['name']} > {player['score']}")
elif SETTINGS["ColourTheme"].lower() == "plain":
print(f" {player['id']} = {player['name']} > {player['score']}")
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f" {color.Fore.LIGHTWHITE_EX}{player['id']} = {player['name']} > {player['score']}")
else:
print(f" {player['id']} = {player['name']} > {player['score']}")
else:
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f" {color.Fore.GREEN}{player['id']} = {player['name']} > {player['score']}")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f" {color.Fore.YELLOW}{player['id']} = {player['name']} > {player['score']}")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f" {color.Fore.CYAN}{player['id']} = {player['name']} > {player['score']}")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f" {color.Fore.YELLOW}{player['id']} = {player['name']} > {player['score']}")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f" {color.Fore.CYAN}{player['id']} = {player['name']} > {player['score']}")
elif SETTINGS["ColourTheme"].lower() == "plain":
print(f" {player['id']} = {player['name']} > {player['score']}")
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f" {color.Fore.WHITE}{player['id']} = {player['name']} > {player['score']}")
else:
print(f" {player['id']} = {player['name']} > {player['score']}")
if player['name'] == SETTINGS["OnlyUserName"] and SETTINGS['OnlyUser']:
doLeave = True
print()
if not doLeave and SETTINGS['OnlyUser']:
print(f"{color.Back.WHITE}{color.Style.BRIGHT}{color.Fore.GREEN}Info: Leaving because {SETTINGS['OnlyUserName']} was not found.")
await sio.disconnect()
os._exit(1)
GAME_DATA.update({'players' : {player['id'] : {'name': player['name'], 'score': player['score'], 'guessedWord': player['guessedWord']} for player in data['players']}})
GAME_DATA.update({'myID': data['myID']})
GAME_DATA.update({'round' : data['round']})
await sio.emit('chat', f'{SETTINGS["SpamMessage"]}')
@sio.on('lobbyState')
def on_lobbyState(data):
"""
When lobby change its state, we want to show that
"""
if SETTINGS["BrightOrDim"].lower() == 'bright':
if SETTINGS["ColourTheme"].lower() == 'emerald':
print(f"{color.Fore.LIGHTWHITE_EX}Lobby State: {data}")
elif SETTINGS["ColourTheme"].lower() == 'fire':
print(f"{color.Fore.LIGHTRED_EX}Lobby State: {data}")
elif SETTINGS["ColourTheme"].lower() == 'ocean':
print(f"{color.Fore.LIGHTCYAN_EX}Lobby State: {data}")
elif SETTINGS["ColourTheme"].lower() == 'storm':
print(f"{color.Fore.LIGHTYELLOW_EX}Lobby State: {data}")
elif SETTINGS["ColourTheme"].lower() == 'candy':
print(f"{color.Fore.LIGHTBLUE_EX}Lobby State: {data}")
elif SETTINGS["ColourTheme"].lower() == 'plain':
print(f"Lobby State: {data}")
elif SETTINGS["ColourTheme"].lower() == 'gold':
print(f"{color.Fore.LIGHTWHITE_EX}Lobby State: {data}")
else:
print(f"Lobby State: {data}")
else:
if SETTINGS["ColourTheme"].lower() == 'emerald':
print(f"{color.Fore.WHITE}Lobby State: {data}")
elif SETTINGS["ColourTheme"].lower() == 'fire':
print(f"{color.Fore.RED}Lobby State: {data}")
elif SETTINGS["ColourTheme"].lower() == 'ocean':
print(f"{color.Fore.CYAN}Lobby State: {data}")
elif SETTINGS["ColourTheme"].lower() == 'storm':
print(f"{color.Fore.YELLOW}Lobby State: {data}")
elif SETTINGS["ColourTheme"].lower() == 'candy':
print(f"{color.Fore.CYAN}Lobby State: {data}")
elif SETTINGS["ColourTheme"].lower() == 'plain':
print(f"Lobby State: {data}")
elif SETTINGS["ColourTheme"].lower() == 'gold':
print(f"{color.Fore.WHITE}Lobby State: {data}")
else:
print(f"Lobby State: {data}")
@sio.on('lobbyCurrentWord')
def on_lobbyCurrentWord(data):
"""
When lobby updates current word, we want to show this.
"""
if SETTINGS["BrightOrDim"].lower() == 'bright':
if SETTINGS["ColourTheme"].lower() == 'emerald':
print(f"{color.Style.BRIGHT}{color.Fore.WHITE}Current Word: {data}")
print()
elif SETTINGS["ColourTheme"].lower() == 'fire':
print(f"{color.Style.BRIGHT}{color.Fore.YELLOW}Current Word: {data}")
print()
elif SETTINGS["ColourTheme"].lower() == 'ocean':
print(f"{color.Style.BRIGHT}{color.Fore.LIGHTCYAN_EX}Current Word: {data}")
print()
elif SETTINGS["ColourTheme"].lower() == 'storm':
print(f"{color.Style.BRIGHT}{color.Fore.YELLOW}Current Word: {data}")
print()
elif SETTINGS["ColourTheme"].lower() == 'candy':
print(f"{color.Style.BRIGHT}{color.Fore.LIGHTBLUE_EX}Current Word: {data}")
print()
elif SETTINGS["ColourTheme"].lower() == 'plain':
print(f"Current Word: {data}")
print()
elif SETTINGS["ColourTheme"].lower() == 'gold':
print(f"{color.Style.BRIGHT}{color.Fore.WHITE}Current Word: {data}")
print()
else:
print(f"Current Word: {data}")
print()
else:
if SETTINGS["ColourTheme"].lower() == 'emerald':
print(f"{color.Style.DIM}{color.Fore.WHITE}Current Word: {data}")
print()
elif SETTINGS["ColourTheme"].lower() == 'fire':
print(f"{color.Style.DIM}{color.Fore.YELLOW}Current Word: {data}")
print()
elif SETTINGS["ColourTheme"].lower() == 'ocean':
print(f"{color.Style.DIM}{color.Fore.LIGHTCYAN_EX}Current Word: {data}")
print()
elif SETTINGS["ColourTheme"].lower() == 'storm':
print(f"{color.Style.DIM}{color.Fore.YELLOW}Current Word: {data}")
print()
elif SETTINGS["ColourTheme"].lower() == 'candy':
print(f"{color.Style.DIM}{color.Fore.LIGHTBLUE_EX}Current Word: {data}")
print()
elif SETTINGS["ColourTheme"].lower() == 'plain':
print(f"Current Word: {data}")
print()
elif SETTINGS["ColourTheme"].lower() == 'gold':
print(f"{color.Style.DIM}{color.Fore.WHITE}Current Word: {data}")
print()
else:
print(f"Current Word: {data}")
print()
@sio.on('chat')
async def on_chat(data):
global clear
"""
Chat function, prints username or id of user and their message
"""
if 'players' in GAME_DATA.keys():
if SETTINGS["BrightOrDim"].lower() == "bright":
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.LIGHTGREEN_EX}{color.Style.BRIGHT}{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.LIGHTRED_EX}{color.Style.BRIGHT}{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.LIGHTBLUE_EX}{color.Style.BRIGHT}{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.LIGHTCYAN_EX}{color.Style.BRIGHT}{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.LIGHTMAGENTA_EX}{color.Style.BRIGHT}{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
elif SETTINGS["ColourTheme"].lower() == "plain":
print(f"{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f"{color.Fore.LIGHTYELLOW_EX}{color.Style.BRIGHT}{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
else:
print(f"{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
else:
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.GREEN}{color.Style.DIM}{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.RED}{color.Style.DIM}{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.BLUE}{color.Style.DIM}{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.CYAN}{color.Style.DIM}{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.MAGENTA}{color.Style.DIM}{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
elif SETTINGS["ColourTheme"].lower() == "plain":
print(f"{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f"{color.Fore.YELLOW}{color.Style.DIM}{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
else:
print(f"{GAME_DATA['players'][data['id']]['name']} wrote > {data['message']}")
if clear == True:
clear = False
time.sleep(1.4)
await sendSpamMessage()
clear = True
else:
print(f"{color.Style.DIM}{data['id']} wrote > {data['message']}")
@sio.on('lobbyPlayerConnected')
async def on_lobbyPlayerConnected(data):
"""
When someone enters the lobby, we want to know this, so this is what this function does
"""
GAME_DATA['players'].update({data['id'] : {'name': data['name'], 'score': data['score'], 'guessedWord': data['guessedWord']}})
if SETTINGS["BrightOrDim"].lower() == "bright":
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}{data['name']} connected.")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}{data['name']} connected.")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}{data['name']} connected.")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}{data['name']} connected.")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}{data['name']} connected.")
elif SETTINGS["ColourTheme"].lower() == "plain":
print(f"{data['name']} connected.")
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}{data['name']} connected.")
else:
print(f"{data['name']} connected.")
else:
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.WHITE}{color.Style.DIM}{data['name']} connected.")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.YELLOW}{color.Style.DIM}{data['name']} connected.")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.WHITE}{color.Style.DIM}{data['name']} connected.")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.YELLOW}{color.Style.DIM}{data['name']} connected.")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.YELLOW}{color.Style.DIM}{data['name']} connected.")
elif SETTINGS["ColourTheme"].lower() == "plain":
print(f"{data['name']} connected.")
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f"{color.Fore.WHITE}{color.Style.DIM}{data['name']} connected.")
else:
print(f"{data['name']} connected.")
@sio.on('lobbyPlayerDisconnected')
async def on_lobbyPlayerDisconnected(data):
"""
When someone leaves the lobby, we want to know this, so this is what this function does
It also makes the bot leave if OnlyUser is enabled
"""
if SETTINGS["BrightOrDim"].lower() == "bright":
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}{GAME_DATA['players'][data]['name']} left.")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}{GAME_DATA['players'][data]['name']} left.")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}{GAME_DATA['players'][data]['name']} left.")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}{GAME_DATA['players'][data]['name']} left.")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}{GAME_DATA['players'][data]['name']} left.")
elif SETTINGS["ColourTheme"].lower() == "plain":
print(f"{GAME_DATA['players'][data]['name']} left.")
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f"{color.Fore.WHITE}{color.Style.BRIGHT}{GAME_DATA['players'][data]['name']} left.")
else:
print(f"{GAME_DATA['players'][data]['name']} left.")
else:
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.WHITE}{color.Style.DIM}{GAME_DATA['players'][data]['name']} left.")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.YELLOW}{color.Style.DIM}{GAME_DATA['players'][data]['name']} left.")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.WHITE}{color.Style.DIM}{GAME_DATA['players'][data]['name']} left.")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.YELLOW}{color.Style.DIM}{GAME_DATA['players'][data]['name']} left.")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.YELLOW}{color.Style.DIM}{GAME_DATA['players'][data]['name']} left.")
elif SETTINGS["ColourTheme"].lower() == "plain":
print(f"{GAME_DATA['players'][data]['name']} left.")
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f"{color.Fore.WHITE}{color.Style.DIM}{GAME_DATA['players'][data]['name']} left.")
else:
print(f"{GAME_DATA['players'][data]['name']} left.")
if SETTINGS["OnlyUser"] and GAME_DATA['players'][data]['name'] == SETTINGS["OnlyUserName"]:
await sio.eio.disconnect(True)
time.sleep(2)
await start_server()
@sio.on('lobbyPlayerGuessedWord')
def on_lobbyPlayerGuessedWord(data):
"""
When someone guesses a word, we want to know it, so this is what this function does
"""
if SETTINGS["BrightOrDim"].lower() == "bright":
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.LIGHTWHITE_EX}{color.Style.BRIGHT}{GAME_DATA['players'][data]['name']} the guessed word!")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.LIGHTYELLOW_EX}{color.Style.BRIGHT}{GAME_DATA['players'][data]['name']} the guessed word!")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.LIGHTCYAN_EX}{color.Style.BRIGHT}{GAME_DATA['players'][data]['name']} the guessed word!")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.YELLOW}{color.Style.BRIGHT}{GAME_DATA['players'][data]['name']} the guessed word!")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.LIGHTBLUE_EX}{color.Style.BRIGHT}{GAME_DATA['players'][data]['name']} the guessed word!")
elif SETTINGS["ColourTheme"].lower() == "plain":
print(f"{GAME_DATA['players'][data]['name']} the guessed word!")
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f"{color.Fore.LIGHTWHITE_EX}{color.Style.BRIGHT}{GAME_DATA['players'][data]['name']} the guessed word!")
else:
print(f"{GAME_DATA['players'][data]['name']} the guessed word!")
else:
if SETTINGS["ColourTheme"].lower() == "emerald":
print(f"{color.Fore.WHITE}{color.Style.DIM}{GAME_DATA['players'][data]['name']} the guessed word!")
elif SETTINGS["ColourTheme"].lower() == "fire":
print(f"{color.Fore.YELLOW}{color.Style.DIM}{GAME_DATA['players'][data]['name']} the guessed word!")
elif SETTINGS["ColourTheme"].lower() == "ocean":
print(f"{color.Fore.CYAN}{color.Style.DIM}{GAME_DATA['players'][data]['name']} the guessed word!")
elif SETTINGS["ColourTheme"].lower() == "storm":
print(f"{color.Fore.YELLOW}{color.Style.DIM}{GAME_DATA['players'][data]['name']} the guessed word!")
elif SETTINGS["ColourTheme"].lower() == "candy":
print(f"{color.Fore.CYAN}{color.Style.DIM}{GAME_DATA['players'][data]['name']} the guessed word!")
elif SETTINGS["ColourTheme"].lower() == "plain":
print(f"{GAME_DATA['players'][data]['name']} the guessed word!")
elif SETTINGS["ColourTheme"].lower() == "gold":
print(f"{color.Fore.WHITE}{color.Style.DIM}{GAME_DATA['players'][data]['name']} the guessed word!")
else:
print(f"{GAME_DATA['players'][data]['name']} the guessed word!")
@sio.on('drawCommands')
def on_drawCommands(data):
"""
Here can be your logic to work with draw data that we get from lobby, u can use kivy to easily draw that
"""
pass
@sio.on('disconnect')
async def on_disconnect():
"""
When we disconnected from server we need explicitly call eio.disconnect or Sio would stuck in forever wait loop
"""
print(f"{color.Back.RED}Disconnected from server")
await sio.eio.disconnect(True)
@sio.on('kicked')
def on_kicked():
"""
The lobby can kick us, we can't do anything about it, at least I have no idea
"""
print(f"{color.Back.RED}The lobby kicked us!")
GAME_DATA['died'] = True
@sio.on('lobbyChooseWord')
async def on_lobbyChooseWord(data):
"""
When the lobby says that someone can choose a word, we check that it is us
"""
if data['id'] == GAME_DATA["myID"]:
GAME_DATA.update({"word": data['words'][2]}) # We always choose the third word, you can change it the way you want it to work
if SETTINGS["BrightOrDim"].lower() == "dim":
print(f"{color.Style.BRIGHT}I am drawing {data['words'][2]}")
else:
print(f"{color.Style.DIM}I am drawing {data['words'][2]}")
if SETTINGS["AnnounceWord"]:
await sio.emit("chat", f"The actual word is: {data['words'][2]}.")
await sio.emit("lobbyChooseWord", 2)
def image_optimize(img, x_size, y_size):
"""
Pixels to line, optimization
Not perfect but it works fast and good enough
"""
draw_data_y = []
draw_data_x = []
img_x, img_y = img.size
"""
THIS DRAWS FROM TOP TO BOTTOM FROM LEFT TO RIGHT
"""
for x in range(x_size, img_x*x_size, x_size):
color = img.getpixel((int(x/x_size), 0))
color_start = 0
for y in range(0, img_y*y_size, y_size):
if img.getpixel((int(x/x_size), int(y/y_size))) != color:
draw_data_y.append([[0, color, y_size, x, color_start, x, y]])
color = img.getpixel((int(x/x_size), int(y/y_size)))
color_start = y
if y == img_y*y_size-y_size:
draw_data_y.append([[0, img.getpixel((int(x/x_size), int(color_start/y_size))), y_size, x, color_start, x, y]])
"""
THIS DRAWS FROM LEFT TO RIGHT FROM TOP TO BOTTOM
"""
for y in range(y_size, img_y*y_size, y_size-1):
color = img.getpixel((0, int(y/y_size)))
color_start = 0
for x in range(0, img_x*x_size, x_size):
if img.getpixel((int(x/x_size), int(y/y_size))) != color:
draw_data_x.append([[0, color, y_size, color_start, y, x, y]])
color = img.getpixel((int(x/x_size), int(y/y_size)))
color_start = x
if x == img_x*x_size-x_size:
draw_data_x.append([[0, img.getpixel((int(color_start/x_size), int(y/y_size))), y_size, color_start, y, x, y]])
"""
Counting lines, that are not white
"""
x = 0
for line in draw_data_x:
if line[0][1] != 0:
x += 1
y = 0
for line in draw_data_y:
if line[0][1] != 0:
y += 1
print('y = ', y, 'x = ', x)
"""
Depending on the size of the operations, we choose what will be more efficient to draw
"""
if x > y:
r.shuffle(draw_data_y) if SETTINGS['Shuffle'] else False
return draw_data_y
else:
r.shuffle(draw_data_x) if SETTINGS['Shuffle'] else False
return draw_data_x
@sio.on('lobbyPlayerDrawing')
async def on_lobbyPlayerDrawing(data):
"""
When lobby says that someone is drawing and that one is us, we draw
"""
if data == GAME_DATA["myID"]:
img = await dither(GAME_DATA['word']) # Image Dither
for line in image_optimize(img, SETTINGS['X'], SETTINGS['Y']): # Optimization for fast draw here, 3 and 5 are sizes of pixels for x drawing and y drawing, changing them u can make image bigger or smaller
if line[0][1] != 0: # We loop through image
await sio.emit('drawCommands', line) # Draw line
async def start_server():
await sio.connect(f"wss://skribbl.io:{SETTINGS['Port']}/")
await sio.wait()
print(f"{color.Back.RED}{color.Style.BRIGHT}Et tu, Brute?")
if __name__ == '__main__':
if SETTINGS["BrightOrDim"].lower() == 'bright':
if SETTINGS["ColourTheme"].lower() == 'emerald':
print(f"{color.Fore.LIGHTWHITE_EX}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
elif SETTINGS["ColourTheme"].lower() == 'fire':
print(f"{color.Fore.LIGHTYELLOW_EX}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
elif SETTINGS["ColourTheme"].lower() == 'ocean':
print(f"{color.Fore.LIGHTCYAN_EX}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
elif SETTINGS["ColourTheme"].lower() == 'storm':
print(f"{color.Fore.LIGHTYELLOW_EX}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
elif SETTINGS["ColourTheme"].lower() == 'candy':
print(f"{color.Fore.LIGHTBLUE_EX}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
elif SETTINGS["ColourTheme"].lower() == 'plain':
print(f"{color.Fore.LIGHTWHITE_EX}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
elif SETTINGS["ColourTheme"].lower() == 'gold':
print(f"{color.Fore.LIGHTYELLOW_EX}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
else:
print(f"{color.Fore.LIGHTWHITE_EX}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
else:
if SETTINGS["ColourTheme"].lower() == 'emerald':
print(f"{color.Fore.WHITE}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
elif SETTINGS["ColourTheme"].lower() == 'fire':
print(f"{color.Fore.YELLOW}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
elif SETTINGS["ColourTheme"].lower() == 'ocean':
print(f"{color.Fore.CYAN}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
elif SETTINGS["ColourTheme"].lower() == 'storm':
print(f"{color.Fore.YELLOW}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
elif SETTINGS["ColourTheme"].lower() == 'candy':
print(f"{color.Fore.CYAN}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
elif SETTINGS["ColourTheme"].lower() == 'plain':
print(f"{color.Fore.WHITE}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
elif SETTINGS["ColourTheme"].lower() == 'gold':
print(f"{color.Fore.YELLOW}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
else:
print(f"{color.Fore.WHITE}Logging into server \"{SETTINGS['Language']}\" with the username: \"{SETTINGS['BotName']}\".")
loop = asyncio.get_event_loop()
loop.run_until_complete(start_server())
loop.close()
# Thank you for using our bot.
# Original bot created by alekxeyuk.
# New features created by Izarus#6723.
# .bat support and configeration of features created by ! [( TheGamerX )]#7912.
# Discord community server managed by PotassiumSnek#6853, ! [( TheGamerX )]#7912 and Kittler#4652