This repository has been archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logMonitor.py
1159 lines (933 loc) · 36.8 KB
/
logMonitor.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
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
import os
from time import thread_time
from Enums import ChatEvents as CE, GameStatus as GS, GameOrigin as GO, SystemStatus as SS
from PlayerQueue import PlayerQueue
class LogMonitor:
combinedLog = "./logs/combined.txt"
if not os.path.exists("/".join(combinedLog.split("/")[:-1])):
os.makedirs("/".join(combinedLog.split("/")[:-1]))
open(combinedLog, "w").close() # Reset file
# Do not break anything if not reset
isPartyLeader = None
lobbyName = None
ownUsername = None
newToken = None
debug = None
resetStats = False
modificationTime = 0
lineNumber = 0
lobbyCap = 0
timeLeftEstimate = 0
toxicMessages = {
"trash": "You lost to trash!",
"bad": "You lost to bad players!",
"gay": "You lost to gays!",
"suck": "You lost to players that suck!"
}
status = GS.unknown
# Must be reset after reading old logs
toxicReaction = None
autoWho = False
autoLeave = False
autoPartyList = False
autoLeavePartyLeave = False
partyMemberMissing = False
partyMemberMissingTwo = False
isStartup = False
autoInvite = []
failedWho = []
game = []
party = []
queue = PlayerQueue()
left = PlayerQueue()
def __init__(self, logFilePath: str, ownUsername, debug = False):
self.logFilePath = logFilePath
self.ownUsername = ownUsername
self.debug = debug
def resetExposed(self):
self.autoWho = False
self.autoLeave = False
self.autoLeavePartyLeave = False
self.resetStats = False
self.autoPartyList = False
self.partyMemberMissing = False
self.partyMemberMissingTwo = False
self.toxicReaction = None
self.autoInvite.clear()
self.failedWho.clear()
self.game.clear()
self.party.clear()
self.left.reset()
self.queue.reset()
def tick(self, isStartup = False):
"""Ticks the logger. Only ticks if there is a log change.
"""
self.isStartup = isStartup
if not os.path.exists(self.logFilePath):
self.file(CE.error, "Log file non-existant! Did you restart?")
self.file(CE.error, "If so, ignore this. If you did not, please re-select the log file")
return
if self.modificationTime != os.path.getmtime(self.logFilePath):
self.modificationTime = os.path.getmtime(self.logFilePath)
self.readlog()
def readlog(self):
"""Reads the log file
"""
# Retrieve log file content
content = open(self.logFilePath, "r").read().splitlines()
# If the length of the log file is shorter than the linenumber, reset the linenumber
if len(content) < self.lineNumber:
self.lineNumber = 0
if self.debug: self.file(CE.system, "Reset linenumber. Likely due to Minecraft restarting.")
# Selects log lines that need to be seen
if self.lineNumber != 0: content = content[self.lineNumber + 1:len(content)]
# Loops over all lines in reversed order
for line in content:
# Add one to linecounter
self.lineNumber += 1
# Clean and process the line
line = self.cleanLine(line)
if line == None:
continue
elif not LogMonitor.lineIsUseful(line):
self.file(CE.useless, line, False)
else:
self.process(line)
def cleanLine(self, line: str):
"""Cleans an inputted line and prevents unimportant lines from being parsed
Args:
line (str): The line to clean / process
Returns:
line (str): Cleaned line or None (if the line was rejected)
"""
if line.count("[Client thread/INFO]: [CHAT]") != 0:
split = line.strip().split("[Client thread/INFO]: [CHAT]")[1].strip()
if split != "":
return split
self.file(CE.removed, split)
return None
def process(self, line: str):
"""Process a line
Args:
line (str): The line to process
"""
if line.startswith("ONLINE:"):
self.whoCommand(line)
elif line.startswith("Party Leader: "):
self.partyLeader(line)
elif line.startswith("Members: ") or line.startswith("Party Members: ") or line.startswith("Party Moderators: "):
self.partyMembers(line)
elif line.startswith("You are currently connected to server ") or line.startswith("Sending you to") or line.startswith("Taking you to"):
self.moveLobby(line)
elif line.endswith("fell into the void."):
self.voided(line)
elif line.startswith("BED DESTRUCTION > "):
self.bedDestroy(line)
elif line.startswith("TEAM ELIMINATED > "):
self.teamEliminated(line)
elif line.endswith("has disconnected, they have 5 minutes to rejoin before they are removed from the party."):
self.partyMemberLeft(line)
elif line == "You have been eliminated!":
self.selfDied()
elif line.endswith(" to the party! They have 60 seconds to accept."):
self.partyInvite(line)
elif line.endswith(" joined the party."):
self.partyJoin(line)
elif line.endswith(" left the party."):
self.partyLeave(line)
elif line.endswith(" has been kicked from the party"):
self.partyKick(line)
elif line.startswith("You have been kicked from the party by "):
self.partyGotKicked(line)
elif line == "The party was disbanded because all invites expired and the party was empty" or line.endswith(" has disbanded the party!"):
self.partyDisbanded(line)
elif line.count(" has promoted" ) > 0 and line.endswith("to Party Leader"):
self.partyPromote(line)
elif line.startswith("The party was transferred to "):
self.partyTransfer(line)
elif line == "Bed Wars":
self.endGameBedwars()
elif line.count("joined the lobby!") > 0:
self.joinLobby(line)
elif line.count("has joined") > 0:
self.playerJoinGame(line)
elif line.endswith(" reconnected."):
self.playerRejoinGame(line)
elif line == "You are AFK. Move around to return from AFK.":
self.afk()
elif line.endswith("has quit!") or line.endswith("disconnected"):
self.quitGame(line)
elif line.startswith("The game starts in") and line.count("second") > 0:
self.gameTime(line)
elif line == "We don't have enough players! Start cancelled.":
self.file("Game", "Start cancelled")
elif line.startswith("Your new API key is "):
self.newAPIKey(line)
elif line.count(":") > 0:
self.chat(line)
else:
self.unprocessed(line)
""" Chat message events """
def lobbyChatMessage(self, line: str):
"""Process a lobby chat event
Args:
line (str): Line to process
Examples:
[STAR?] username: message may contain spaces
[STAR?] [RANK] username: message may contain spaces
"""
if self.status == GS.inGame or self.status == GS.afterGame:
self.gameChatMessage(line)
return
split = line.split(" ")
# ["[STAR?]", "username:", "message", "may", "contain", "spaces"]
# ["[STAR?]", "[RANK]", "username:", "message", "may", "contain", "spaces"]
# Retrieve stars
stars = split[0].removeprefix("[").removesuffix("?]")
# Retrieve rank, username and message
if split[1].endswith(":"):
rank = "NON"
user = split[1].removesuffix(":")
message = " ".join(split[2:])
else:
rank = LogMonitor.getRank(split[1])
user = split[2].removesuffix(":")
message = " ".join(split[3:])
# Clean the message
message = message.replace("?", "")+"?" if message.endswith("?") else message.replace("?", "").strip()
while (message.count(" ") > 0):
message = message.replace(" ", " ")
# Check if the player is the main player
if user == self.ownUsername:
self.file(CE.chat, "[{}] {}{}: {}".format(stars, rank, user, message.strip()))
return
# Add the player to the playerqueue
self.queue.add(user, rank, stars, GO.mainChat)
rank = "[" + rank + "] " if rank != "NON" else ""
for word in message.strip().split(" "):
if word.count(self.ownUsername) > 0:
# This word mentions one of the main users' usernames, invite this player!
if not user in self.party: self.autoInvite.append(user)
self.file(CE.chat, "[{}] {}{}: {}".format(stars, rank, user, message.strip()))
def gameChatMessage(self, line: str):
"""Process a game chat event
Args:
line (str): Line to process
Examples:
username: message may contain spaces
[RANK] username: message may contain spaces
"""
split = line.split(" ")
# Retrieve rank, username and message
if split[0].endswith(":"):
rank = "NON"
user = split[0].removesuffix(":")
message = " ".join(split[1:])
else:
rank = LogMonitor.getRank(split[0])
user = split[1].removesuffix(":")
message = " ".join(split[2:])
# Clean the message
while (message.count(" ") > 0):
message = message.replace(" ", " ")
# Check if the player is the main player
if user == self.ownUsername:
rank = ""
else:
rank = "[" + rank + "] " if rank != "NON" else ""
if (message.count("/who") > 0 and message.count(" ") < 2 or message.count("who") > 0 and message.count(" ") == 0)\
and self.status == GS.gameLobby:
if user == self.ownUsername:
self.autoWho = True
self.file(CE.chat, "You failed an autowho! Sending again...")
else:
self.failedWho.append(user)
self.file(CE.chat, "{}{} failed /who: {}".format(rank, user, message.strip()))
else:
self.file(CE.chat, "{}{}: {}".format(rank, user, message.strip()))
def moveLobby(self, line: str):
"""Process a lobby move event
Args:
line (str): Line to process
Example:
You are currently connected to server x
Sending you to x
Taking you to x
Status:
Unchanged
"""
# Retrieve the lobby name
name = line.removeprefix("You are currently connected to server").removeprefix("Sending you to").removeprefix("Taking you to").removesuffix("!").strip().split(' ')[0]
# Set the lobby name if changed
if name != self.lobbyName:
# Reset the lobby counter
self.timeLeftEstimate = 0
self.file(CE.lobby, "[{}] -> [{}]".format(self.lobbyName, name))
# Set the lobby name
self.lobbyName = name
def voided(self, line: str):
"""Process a fell in the void event
Args:
line (str): Line to process
Example:
username fell into the void.
Status:
inGame
"""
self.status = GS.inGame
name = line.replace("username fell into the void.", "").strip()
if not name == self.ownUsername:
# Do not process statistics (useless)
self.file(CE.removed, line)
else:
self.file(CE.void, "You voided!")
def bedDestroy(self, line: str):
"""Process a lobby join event
Args:
line (str): Line to process
Example:
BED DESTRUCTION > White Bed description username!
Status:
inGame
"""
self.status = GS.inGame
name = line.removeprefix("BED DESTRUCTION > ").removesuffix("!").split(" ")[-1]
if name != self.ownUsername:
self.file(CE.removed, line)
else:
self.file(CE.bed, "You destroyed a bed!")
def joinLobby(self, line: str):
"""Process a lobby join event
Args:
line (str): Line to process
Example:
>>> [RANK] username joined the lobby! <<<
Status:
MainLobby
"""
self.status = GS.mainLobby
# Reset the lobby counter
self.timeLeftEstimate = 0
line = line.removeprefix(">>>").removesuffix("joined the lobby!").strip().split(" ")
# ["[RANK]", "username"]
rank = LogMonitor.getRank(line[0])
rank = "[" + rank + "] " if rank != "NON" else ""
name = line[1]
if name == self.ownUsername:
return
self.queue.add(name, rank, origin=GO.mainLobby)
self.file(CE.player, "{}{}".format(rank, name))
def teamEliminated(self, line:str):
"""Process a team eliminated event
Args:
line (str): Line to process
Example:
TEAM ELIMINATED > Color Team has been eliminated!
"""
team = line.removeprefix("TEAM ELIMINATED > ").removesuffix("has been eliminated!").strip()
self.file(CE.eliminated, team + " eliminated!")
def partyMemberLeft(self, line:str):
"""Process a party member leave event
Args:
line (str): Line to process
Example:
[RANK] username has disconnected, they have 5 minutes to rejoin before they are removed from the party.
username has disconnected, they have 5 minutes to rejoin before they are removed from the party.
Status:
unchanged
"""
x = line.removesuffix("has disconnected, they have 5 minutes to rejoin before they are removed from the party.").strip().split(" ")
if self.status == GS.gameLobby and self.timeLeftEstimate > 5:
self.autoLeavePartyLeave = True
if len(x) == 1:
self.file(CE.party, "Your party member: " + x[0] + " disconnected!")
else:
self.file(CE.party, "Your party member: " + x[0] + " " + x[1] + " disconnected!")
def selfDied(self):
"""Process player death
Status:
inGame
"""
self.status = GS.inGame
self.file(CE.died, "You died")
def partyInvite(self, line:str):
"""Process a party invite
Args:
line (str): Line to process
Example:
[RANK] name1 invited [RANK] name2 to the party! They have 60 seconds to accept.
[RANK] name1 invited name2 to the party! They have 60 seconds to accept.
name1 invited [RANK] name2 to the party! They have 60 seconds to accept.
name1 invited name2 to the party! They have 60 seconds to accept.
"""
line = line.removesuffix(" to the party! They have 60 seconds to accept.").strip().split(" ")
x = LogMonitor.getRank(line[0])
if x == "NON":
name1 = x
rank1 = ""
else:
name1 = line[1]
rank1 = "[" + x + "] "
if name1 == self.ownUsername:
name1 = "You"
rank1 = ""
name2 = line[-1]
x = LogMonitor.getRank(line[-2])
rank2 = "" if x == "NON" else "[" + x + "] "
self.file(CE.party, "{}{} invited {}{}".format(rank1, name1, rank2, name2))
def partyLeader(self, line: str):
"""Process a party list leader line
Args:
line (str): Line to process
Example:
Party Leader: [RANK] username ?
Party Leader: username ?
"""
x = line.removeprefix("Party Leader: ").split(" ")
rank = LogMonitor.getRank(x[0])
if rank == "NON":
name = x[0]
rank = ""
else:
name = x[1]
rank = rank + " "
if name == self.ownUsername:
self.isPartyLeader = True
self.file(CE.party, "Party List:")
self.file(CE.party, "Leader: {}{}".format(rank, name))
def partyMembers(self, line: str):
"""Process a party list member line
Args:
line (str): Line to process
Example:
Party Members: [RANK] username ? username ? [RANK] username
"""
x = line.removeprefix("Party ").removeprefix("Members: ").removeprefix("Moderators: ").split(" ? ")
for playerWithRank in x:
playerWithRank = playerWithRank.split(" ")
rank = LogMonitor.getRank(playerWithRank[0])
if rank == "NON":
name = playerWithRank[0]
else:
name = playerWithRank[1]
if not name in self.party:
self.party.append(name)
self.queue.add(name, rank, origin=GO.party)
self.file(CE.party, "Members: {}".format(", ".join(self.party)))
def partyDisband(self, line: str):
"""Process a party disband
Args:
line(str): Line to process
Example:
[RANK] username has disbanded the party!
username has disbanded the party!
"""
x = line.removesuffix(" has disbanded the party!").split(" ")
rank = LogMonitor.getRank(x[0])
if rank == "NON":
name = x[0]
rank = ""
else:
name = x[1]
rank = rank + " "
self.party.clear()
self.isPartyLeader = None
self.file(CE.party, "The party was disbanded by {}{}".format(rank, name))
def partyJoin(self, line: str):
"""Process a party join
Args:
line (str): Line to process
Example:
[RANK] name1 joined the party.
name1 joined the party.
Status:
unchanged
"""
x = LogMonitor.getRank(line.split(" ")[0])
if x == "NON":
name = line.split(" ")[0]
rank = ""
else:
name = line.split(" ")[1]
rank = "[" + x + "] "
self.party.append(name)
self.queue.add(name, rank, origin=GO.party)
if len(self.party) == 0:
self.isPartyLeader = False
self.file(CE.party, "{}{} joined the party".format(rank, name))
self.file(CE.party, ("Party members are now: {}".format(", ".join(self.party))) if len(self.party) > 0 else "The party is empty!")
def partyLeave(self, line: str):
"""Process a party leave
Args:
line (str): Line to process
Example:
[RANK] name1 left the party.
name1 left the party.
Status:
unchanged
"""
if line == "You left the party.":
self.isPartyLeader = False
self.party.clear()
return
x = LogMonitor.getRank(line.split(" ")[0])
if x == "NON":
name = x
rank = ""
else:
name = line.split(" ")[1]
rank = "[" + x + "] "
if not name in self.party:
self.file(CE.bug, "Someone left the party that was not in it?! BUG!")
self.autoPartyList = True
else:
self.party.remove(name)
self.file(CE.party, "{}{} left the party".format(rank, name))
self.file(CE.party, ("Party members are now: {}".format(", ".join(self.party))) if len(self.party) > 0 else "The party is empty!")
def partyKick(self, line: str):
""" Processes a party kick event
Args:
line (str): The line to process
Example
[RANK] username
username has been kicked from the party
"""
x = line.removesuffix(" has been kicked from the party").split(" ")
rank = LogMonitor.getRank(x[0])
if rank == "NON":
name = x[0]
rank = ""
else:
name = x[1]
rank = "[" + rank + "] "
if name not in self.party:
self.file(CE.party, "{}{} has been kicked from the party but was not in it!".format(rank, name))
else:
self.party.remove(name)
self.file(CE.party, "{}{} has been kicked from the party".format(rank, name))
def partyGotKicked(self, line: str):
""" Processes a party got kicked event
Args:
line (str): The line to process
Example
You have been kicked from the party by [RANK] username
You have been kicked from the party by username
"""
self.isPartyLeader = None
self.party.clear()
self.autoPartyList = False
self.autoLeavePartyLeave = False
self.partyMemberMissing = False
self.partyMemberMissingTwo = False
x = line.removeprefix("You have been kicked from the party ").split(" ")
rank = LogMonitor.getRank(x[0])
if rank == "NON":
name = x[0]
rank = ""
else:
name = x[1]
rank = "[" + rank + "] "
self.file(CE.party, "{}{} kicked you from the party".format(rank, name))
def partyDisbanded(self, line: str):
"""Process a party disband
Args
line (str): Line to process
Example:
The party was disbanded because all invites expired and the party was empty
[RANK] username has disbanded the party!
username has disbanded the party!
"""
self.isPartyLeader = None
self.party.clear()
self.autoPartyList = False
self.autoLeavePartyLeave = False
self.partyMemberMissing = False
self.partyMemberMissingTwo = False
if line.endswith("has disbanded the party!"):
x = line.removesuffix("has disbanded the party!").strip().split(" ")
rank = LogMonitor.getRank(x[0])
if rank == "NON":
name = x[0]
rank = ""
else:
name = x[1]
rank = "[" + rank + "] "
self.file(CE.party, "{}{} has disbanded the party".format(rank, name))
else:
self.file(CE.party, "The party was disbanded")
def partyPromote(self, line: str):
"""Process a party promote
Args:
line (str): Line to process
Example:
[RANK] name1 has promoted [RANK] name2 to Party Leader
name1 has promoted name2 to Party Leader
"""
x = line.replace(" has promoted", "").removesuffix(" to Party Leader").split(" ")
if x[-1] == self.ownUsername:
self.isPartyLeader = True
else:
self.isPartyLeader = False
rank1 = LogMonitor.getRank(x[0])
if rank1 == "NON":
rank1 = ""
name1 = x[0]
else:
rank1 = "[" + rank1 + "] "
name1 = x[1]
rank2 = LogMonitor.getRank(x[-2])
if rank2 == "NON":
rank2 = ""
name2 = x[-1]
else:
rank2 = "[" + rank2 + "] "
name2 = x[-1]
if name1 == self.ownUsername:
rank1 = ""
name1 = "You"
if name2 == self.ownUsername:
rank2 = ""
name2 = "you"
self.file(CE.party, "{}{} promoted {}{} to Party Leader".format(rank1, name1, rank2, name2))
def partyTransfer(self, line: str):
"""Process a party transfer
Args:
line (str): Line to process
Example:
The party was transferred to [RANK] name1 by [RANK] name2
The party was transferred to name1 by name2
"""
x = line.removeprefix("The party was transferred to ").replace(" by", "").split(" ")
if x[-2] == self.ownUsername:
self.isPartyLeader = True
else:
self.isPartyLeader = False
rank1 = LogMonitor.getRank(x[0])
if rank1 == "NON":
rank1 = ""
name1 = x[0]
else:
rank1 = "[" + rank1 + "] "
name1 = x[1]
rank2 = LogMonitor.getRank(x[-2])
if rank2 == "NON":
rank2 = ""
name2 = x[-1]
else:
rank2 = "[" + rank2 + "] "
name2 = x[-1]
if name1 == self.ownUsername:
rank1 = ""
name1 = "you"
if name2 == self.ownUsername:
rank2 = ""
name2 = "you"
self.file(CE.party, "{}{} transferred the party to {}{}".format(rank1, name1, rank2, name2))
def endGameBedwars(self):
"""Process a game end event for bedwars games
Example:
"Bed Wars"
Status:
Based on current status type, switches to:
MainLobby (if in game)
InGame (if in lobby)
"""
if self.status == GS.inGame:
self.status = GS.afterGame
self.autoWho = False
self.autoLeave = True
self.resetStats = True
self.game.clear()
self.file(CE.game, "Finished")
else:
self.status = GS.inGame
self.file(CE.game, "Started")
def playerJoinGame(self, line: str):
"""Process a player game lobby join event
Args:
line (str): Line to process
Example:
username has joined (x/y)!
Status:
GameLobby
"""
self.status = GS.gameLobby
line = line.split(" ")
# ["username", "has", "joined", "(x/y)!"]
name = line[0]
x = line[-1].replace("(","").replace(")!","").split("/")
lobbyCap = int(x[1])
# Store player by username
self.queue.add(name, origin=GO.gameLobby)
self.game.append(name)
if not len(self.game) == int(x[0]):
self.autoWho = True
if len(self.game) > int(x[0]):
self.game.clear()
elif name == self.ownUsername and int(x[0]) > 1:
self.autoWho = True
# Save the amount of players in the lobby
self.lobbyCap = lobbyCap
self.file(CE.join, "{} ({}/{})".format(name, len(self.game), lobbyCap))
if self.debug: self.file(CE.join, "Currently in lobby ({}/{}): {}".format(len(self.game), self.lobbyCap, ", ".join(self.game)))
def playerRejoinGame(self, line: str):
"""Process a player game lobby rejoin event
Args:
line (str): Line to process
Example:
username reconnected.
Status:
inGame
"""
self.status = GS.inGame
name = line.removesuffix(" reconnected.")
self.file(CE.join, "{} rejoined".format(name))
def whoCommand(self, line: str):
"""Process a who command
Args:
line (str): Line to process
Example:
ONLINE: username, username, username, username, ...
Status:
GameLobby
"""
self.status = GS.gameLobby
line = line.removeprefix("ONLINE: ").split(", ")
self.resetStats = True
self.game.clear()
for username in line:
self.file(CE.who, username)
self.queue.add(username, origin=GO.gameLobby)
self.game.append(username)
self.file(CE.who, "({}/{}) players in the lobby".format(len(line), self.lobbyCap))
def afk(self):
"""Process an afk event
Args:
line (str): Line to process
Status:
afk
"""
self.status = GS.afk
self.file(CE.afk, "You went AFK")
def quitGame(self, line: str):
"""Process a game lobby quit event
Args:
line (str): Line to process
Example:
username has quit!
username has disconnected
"""
# Remove one player from the lobby count
# Remove the player from the queue
name = line.removesuffix(" has quit!").removesuffix("disconnected").strip()
self.queue.delete(name)
self.left.add(name, "UNK", -1)
if name in self.game:
self.game.remove(name)
else:
self.file(CE.lobby, "{} left but were not in the game! BUG?!".format(name))
self.file(CE.lobby, "Currently in game: {}".format(", ".join(self.game)))
self.file(CE.quit, "{} ({}/{})".format(name, len(self.game), self.lobbyCap))
if name == self.ownUsername:
self.file(CE.lobby, "Left lobby [{}]".format(self.lobbyName))
def gameTime(self, line: str):
"""Process a game lobby time event
Args:
line (str): Line to process
Example:
The game starts in x seconds!
Status:
GameLobby
"""
self.status = GS.gameLobby
time = int(line.removeprefix("The game starts in").removesuffix("!").removesuffix("s").removesuffix("second").strip())
self.timeLeftEstimate = time
if self.timeLeftEstimate > 3:
for player in self.party:
if not player in self.game:
self.file(CE.lobby, "Party member missing: {} | Game: {}".format(player, ", ".join(self.game)))
if self.partyMemberMissing:
self.partyMemberMissingTwo = True
else:
self.partyMemberMissing = True
self.autoWho = True
self.file(CE.time, str(time) + "s")
def newAPIKey(self, line: str):
"""Process a new api key event
Args:
line (str): Line to process
Examples:
Your new API key is x
Status:
MainLobby
"""
self.status = GS.mainLobby
# Retrieve key
key = line.removeprefix("Your new API key is ").strip()
# Store key
self.newToken = key
self.file(CE.api, key)
def chat(self, line: str):
"""Process a line with a colon.
Likely chat, but unsure.
Args:
line (str): The line to process
"""
if self.status == GS.mainLobby and line.startswith("[") and line.split(" ")[0].endswith("?]") and (line.split(" ")[1].endswith(":") or line.split(" ")[2].endswith(":")):
self.lobbyChatMessage(line)
elif self.status == GS.inGame or self.status == GS.gameLobby:
self.gameChatMessage(line)
elif self.status == GS.afterGame:
self.afterGameChat(line)
self.potentialChat(line)
def potentialChat(self, line: str):
"""Process a potential chat message
Args:
line (str): Line to process
Examples:
[RANK] username: message with spaces
username: message with spaces
Status:
inGame
"""
line = line.split(" ")
if len(line) < 3: self.unprocessed(" ".join(line))
rank = LogMonitor.getRank(line[0])
name = line[0] if rank == "NON" else line[1]
message = " ".join(line[(1 if rank == "NON" else 2):])
if not name.endswith(":"):
self.unprocessed(" ".join(line))
else: