From 48f38d9672306c00f108d705cb1cbc6bff7c330d Mon Sep 17 00:00:00 2001 From: Trysdyn Black Date: Sun, 28 Mar 2021 19:07:41 -0700 Subject: [PATCH] Clean up command hash generation Rather than COMMANDS and its join to CHRACTERS['commands'] be a messy cluster of \n, do some string parsing to make it look much cleaner and more readable. --- main.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index e1124c3..5059d8e 100644 --- a/main.py +++ b/main.py @@ -69,9 +69,25 @@ def parse_COMMANDS(data): # it as the name of the command in the next block. Blorf :) next_command_name = None for c_data in data.split('\n-------\n'): - c_data_lines = c_data.split('\n') + c_data_lines = [c_data_line.strip() for c_data_line in c_data.split('\n')] + if '' in c_data_lines: + c_data_lines.remove('') if next_command_name: - commands[next_command_name] = '\n'.join(c_data_lines[:-1]) + command_string = '; '.join(c_data_lines[:-1]) + + # Clip trailing junk from inconsistent spoiler log generation + # as well as the join above + if command_string.endswith('; '): + command_string = command_string[:-2] + if command_string.endswith('.'): + command_string = command_string[:-1] + + # Clean up a couple of clumsy string cases from the join above + command_string = command_string.replace('.; ', ': ') + command_string = command_string.replace(' ', ' ') + + # Commit the command to the dict + commands[next_command_name] = command_string next_command_name = c_data_lines[-1].lower()