monolith/legacy/core/parser.py

28 lines
964 B
Python
Raw Normal View History

import main
2022-07-21 12:40:05 +00:00
from utils.logging.log import warn
2022-07-21 12:40:09 +00:00
from utils.logging.send import incorrectUsage, sendFailure, sendInfo, sendSuccess
2022-07-21 12:39:41 +00:00
def parseCommand(addr, authed, data):
2022-07-21 12:39:41 +00:00
# call command modules with: (addr, authed, data, spl, success, failure, info, incUsage, length)
spl = data.split()
if addr in main.connections.keys():
obj = main.connections[addr]
else:
warn("Got connection object with no instance in the address pool")
return
2022-07-21 12:40:05 +00:00
success = lambda data: sendSuccess(addr, data) # noqa: E731
failure = lambda data: sendFailure(addr, data) # noqa: E731
info = lambda data: sendInfo(addr, data) # noqa: E731
2022-07-21 12:40:05 +00:00
incUsage = lambda mode: incorrectUsage(addr, mode) # noqa: E731
length = len(spl)
if spl[0] in main.CommandMap.keys():
2022-09-05 06:20:30 +00:00
main.CommandMap[spl[0]](
addr, authed, data, obj, spl, success, failure, info, incUsage, length
)
return
incUsage(None)
return