-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthoritativeSystem.py
46 lines (36 loc) · 1.59 KB
/
AuthoritativeSystem.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
from DynamicSystem import DynamicSystem
import re
from Logger import globalLogger, LogLevel
import traceback
class AuthoritativeSystem(DynamicSystem):
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
self.Commands = {}
self.RegisterCommands()
def Run(self, proxy, prompt, role):
command = ""
globalLogger.log(message = f"Prompt: {prompt}", logLevel = LogLevel.authoritativeLog)
try:
if(re.match(r"\W", prompt)): #check if prompt is a command. Commands must ALWAYS start with \W, non word char
if(prompt == "/help"):
result = list(map(lambda x: x[0] + " :: " + x[1].description, self.Commands.items()))
for item in result:
globalLogger.log(message = item, logLevel = LogLevel.authoritativeLog)
return ""
expressions = self.Commands.keys()
for expression in expressions:
if(not prompt):
break
command = re.match(expression, prompt)
if(command):
prompt = self.Commands[expression].func(proxy=proxy,prompt=prompt, command = command.group())
return prompt
except Exception as e:
globalLogger.log(message = f"Error processing authoritative prompt {prompt}: {e}", logLevel = LogLevel.errorLog)
globalLogger.log(message = traceback.format_exc(), logLevel = LogLevel.errorLog)
def getProcessPath(self):
return "AuthoritativeModules"
def RegisterCommands(self):
for process in self.processes.values():
process.RegisterCommands(self)
authoritativeSystem = AuthoritativeSystem()