-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsers.py
277 lines (248 loc) · 7.61 KB
/
parsers.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
from commands import *
def commandParser(cmdList: list) -> None:
"""
Parses a list of commands and delegates each command to the appropriate parser function.
Parameters
----------
cmdList : list
A list of commands, where each command is a string. The first character of each command
determines which parser function is called.
Notes
-----
- Commands starting with "0" are parsed by `parseMute`.
- Commands starting with "1" are parsed by `parseUnmute`.
- Commands starting with "4" are parsed by `parseDelay`.
- Commands starting with "5" are parsed by `parseDev`.
- Commands starting with "6" are parsed by `parseInfo`.
- Commands starting with "7" are parsed by `parseIgnored`.
- Commands starting with "8" are parsed by `parseUser`.
- Commands starting with "9" are parsed by `parseDead`.
- An "Invalid Command" message is printed for unrecognized commands.
"""
for cmd in cmdList:
match cmd[0]:
case "0":
parseMute(cmd)
case "1":
parseUnmute(cmd)
case "4":
parseDelay(cmd)
case "5":
parseDev(cmd)
case "6":
parseInfo(cmd)
case "7":
parseIgnored(cmd)
case "8":
parseUser(cmd)
case "9":
parseDead(cmd)
case _:
print("Invalid Command")
def parseMute(cmd: str):
"""
Parse the mute command.
Parameters
----------
cmd : str
The command to parse.
Notes
-----
If the command is "00", it will mute all users.
If the command is "01", it will mute a user selected by the user.
If the command is "0" only, it will mute all undead users.
"""
if len(cmd) > 1:
match cmd[1]:
case "0":
muteAll()
case "1":
if len(cmd) > 2:
if int(cmd[2:]) <= len(unamesList):
UID = int(cmd[2:])
ID = unamesList[UID-1]
else:
ID = selectUser()
if ID != "":
muteUser(ID)
print(f"{ID} muted")
else:
print("Cancelled")
else:
muteUndead()
def parseUnmute(cmd: str):
"""
Parse the unmute command.
Parameters
----------
cmd : str
The command to parse.
Notes
-----
If the command is "10", it will unmute all users.
If the command is "11", it will unmute a user selected by the user.
If the command is "1" only, it will unmute all undead users.
"""
if len(cmd) > 1:
match cmd[1]:
case "0":
unmuteAll()
case "1":
if len(cmd) > 2:
if int(cmd[2:]) <= len(unamesList):
UID = int(cmd[2:])
ID = unamesList[UID-1]
else:
ID = selectUser()
if ID != "":
unmuteUser(ID)
print(f"{ID} unmuted")
else:
print("Cancelled")
else:
unmuteUndead()
def parseDelay(cmd: str) -> None:
"""
Parse the delay command.
Parameters
----------
cmd : str
The command to parse.
Notes
-----
If the command is "4" only, it will delay for 0.5 seconds.
If the command is "4?" where ? is a number, it will delay for ? seconds.
"""
hold = 0.5
if len(cmd) > 1:
hold = float(cmd[1:])
delay(hold)
def parseDev(cmd: str):
"""
Parse the dev command.
Parameters
----------
cmd : str
The command to parse.
Notes
-----
If the command is "50", it will disable developer output.
If the command is "51", it will enable developer output.
If the command is "5" only, it will print out the current state of developer mode.
"""
global dev
if len(cmd) > 1:
match cmd[1]:
case "0":
dev = False
print("Developer Output Disabled")
case "1":
dev = True
print("Developer Output Enabled")
else:
print(f"Dev Mode: {dev}")
def parseInfo(cmd: str):
"""
Parse the info command.
Parameters
----------
cmd : str
The command to parse.
Notes
-----
If the command is "60", it will exit the program.
If the command is "61", it will print out the command list.
If the command is "6" only, it will print out the program's version.
"""
global stayGate, version
if len(cmd) > 1:
match cmd[1]:
case "0":
print("Closing AMuteUs...")
exit()
case "1":
print('Command List:\n-----------------------\n0 - mute\n\t00 - all\n\t01 - user\n1 - unmute\n\t10 - all\n\t11 - user\n5 - debug mode\n\t50 - off\n\t51 - on\n6 - program version\n\t60 - exit program\n\t61 - help\n7 - ignored list\n\t70 - reload\n\t71 - add\n8 - list users\n\t80 - list dead & ignored\n\t81 - list alive\n9 - deadlist\n\t90 - clear\n\t91 - add')
else:
print(f"AMuteUs {version}")
def parseIgnored(cmd: str):
"""
Parse the ignored command.
Parameters
----------
cmd : str
The command to parse.
Notes
-----
If the command is "70", it will reload the ignored list.
If the command is "71", it will add the user to the ignored list.
If the command is "7" only, it will list all users in the ignored list.
"""
global ignoredList
if len(cmd) > 1:
match cmd[1]:
case "0":
reloadIgnoredList()
case "1":
if len(cmd) > 2:
if int(cmd[2:]) <= len(unamesList):
UID = int(cmd[2:])
ID = unamesList[UID-1]
else:
ID = selectUser()
if ID != "":
ignoredList.append(ID)
print(f"{ID} added to Ignored List")
else:
print("Cancelled")
else:
listStatus(2)
def parseUser(cmd: str):
"""
Parse the user command.
Parameters
----------
cmd : str
The command to parse.
Notes
-----
If the command is only "8", it will list all users.
If the command is "8" followed by a number, it will list the users with that status.
"""
if len(cmd) > 1:
listStatus(int(cmd[1:]))
else:
listAllUsers
def parseDead(cmd: str):
"""
Parse the dead command.
Parameters
----------
cmd : str
The command to parse.
Notes
-----
If the command is "90", it will clear the deadlist.
If the command is "91", it will add the user to the deadlist.
If the command is "9" only, it will list all users in the deadlist.
"""
global deadList
if len(cmd) > 1:
match cmd[1]:
case "0":
clearDeadList()
case "1":
if len(cmd) > 2:
if int(cmd[2:]) <= len(unamesList):
UID = int(cmd[2:])
ID = unamesList[UID-1]
else:
ID = selectUser()
if ID != "":
deadList.append(ID)
print(f"{ID} added to Deadlist")
else:
print("Cancelled")
else:
listStatus(0)
if __name__ == "__main__":
print("This file is not intended to be run directly. Please run main.py instead.")