-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconparser.py
More file actions
110 lines (79 loc) · 2.78 KB
/
conparser.py
File metadata and controls
110 lines (79 loc) · 2.78 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
import time
import configparser
import keyboard
import psutil
config = configparser.ConfigParser()
CONFIG_FILE = 'config.ini'
config.read(CONFIG_FILE, encoding='utf-8')
BLACKLISTED_USERNAME = config['SETTINGS']['username']
CON_LOG_FILE_PATH = config['SETTINGS']['gameconlogpath']
CHAT_KEY = config['SETTINGS']['chatkey']
def detect_game(custom_proc="customproc"):
pname = None
for proc in psutil.process_iter():
match proc.name():
case "hl.exe":
pname = "hl"
break
case "hl2.exe":
pname = "hl2"
break
case "cs2.exe":
pname = "cs2"
break
case _:
if proc.name() == custom_proc:
pname = custom_proc.strip(".exe")
break
else:
continue
return pname
# really hacky but it works
def parse_log(game, line: str):
"""
Parses source console logs, if it detects
Args:
game (str): Specifies the game as to use the appropriate format
line (str): String fetched from the source console log to parse
Returns:
list: In-game username (index 0), and message (index 1)
"""
if "Source2Shutdown" in line:
exit() #TODO: make this optional
parsed_log = ["",""]
username = ""
message = ""
match game:
case "cs2":
if "[ALL]" in line:
parsed_log = line.partition("[ALL] ")[2].split(": ")
if "[TEAM]" in line:
parsed_log = line.partition("[TEAM] ")[2].split(": ")
if "[DEAD]" in line:
parsed_log[0] = parsed_log[0].replace(" [DEAD]", '')
print(f"DEAD {parsed_log}")
case "hl":
if ": " in line:
parsed_log = line.split(": ")
parsed_log[0] = parsed_log[0][1:] # For some reason usernames start with '☻' in this game, probably some weird unicode thing.
case "hl2":
if "*DEAD*" in line:
parsed_log = line.replace("*DEAD* ", '')
if " : " in line:
parsed_log = line.split(" : ")
case _:
return None
username = parsed_log[0]
username = username.replace(u'\u200e', '') # This gets rid of the 'LEFT-TO-RIGHT MARK' char.
message = parsed_log[1]
return [username, message]
def rt_file_read(file: __file__):
# Reads console.log in real time
line = file.readline()
return line
def sim_key_presses(text: str):
keyboard.press_and_release(CHAT_KEY)
time.sleep(0.01)
keyboard.write(text)
time.sleep(0.01)
keyboard.press_and_release('enter')