Skip to content

Commit

Permalink
Stop using Regex for evidence desc command processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystalwarrior committed Nov 10, 2024
1 parent bd5cba2 commit 9af0d04
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions server/evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,34 @@ def correct_format(self, client, desc):
return False

def parse_desc(self, desc):
for match in re.findall(r"<.*?=.*?>", desc):
args = match.strip("<>").split("=")
if len(args) < 2:
continue
key, value = args
if key == "owner":
if value == "":
value = "hidden"
poses = value
if key == "can_hide_in":
can_hide_in = value == "1"
if key == "show_in_dark":
print(value)
show_in_dark = int(value)

desc = re.sub(r"<.*?=.*?>\n?", '', desc)
lines = desc.split("\n", 3)
poses = "hidden"
can_hide_in = 0
show_in_dark = 0
matches = 0
for line in lines:
cmd = line.strip(" ") # remove all whitespace
if cmd.startswith("<") and cmd.endswith(">"):
args = cmd.strip("<>").split("=")
if len(args) < 2:
break
key, value = args
if key == "owner":
if value == "":
value = "hidden"
poses = value
matches += 1
if key == "can_hide_in":
can_hide_in = value == "1"
matches += 1
if key == "show_in_dark":
show_in_dark = int(value)
matches += 1
# Remvoes N lines, where N is how many <> we matched. Can't be more than 3.
while matches > 0:
# Truncates from the start of newline
desc = desc[desc.find("\n")+1:]
matches -= 1
return desc, poses, can_hide_in, show_in_dark

def add_evidence(self, client, name, desc, image, pos="all"):
Expand Down

0 comments on commit 9af0d04

Please sign in to comment.