tuxbot-bot/tuxbot/cogs/Crypto/functions/parser.py

37 lines
851 B
Python
Raw Normal View History

import re
2021-04-20 15:12:38 +00:00
from typing import Optional
2021-04-20 15:12:38 +00:00
def data_parser(data: Optional[str]) -> dict:
output = {
2021-03-31 16:08:41 +00:00
"message": "",
"compressed": False,
"graphical": False,
2021-04-20 13:51:03 +00:00
"chars": tuple,
}
if not data:
return output
if "--compressed" in data:
output["compressed"] = True
data = "".join(data.rsplit("--compressed", 1))
if "--graphical" in data:
output["graphical"] = True
data = "".join(data.rsplit("--graphical", 1))
if "compressed" in output.keys():
del output["compressed"]
if "--chars" in data:
regex = r"--chars=(\S\S)"
2021-03-31 16:08:41 +00:00
if match := re.search(regex, data):
output["chars"] = tuple(match.group()[-2:])
data = "".join(data.rsplit(match.group(), 1))
output["message"] = data.strip()
return output