- # if the action is default and there is no mark, add one
- if action == actions[default_punctuation] and not message.endswith(default_punctuation):
- message += default_punctuation
+ # add punctuation if needed
+ if not action:
+ action = actions[default_punctuation]
+ if message and not message[-1] in punctuation:
+ message += default_punctuation
+
+ # decapitalize the first letter to improve matching
+ if message and message[0] in uppercase:
+ message = message[0].lower() + message[1:]
+
+ # iterate over all words in message, replacing typos
+ typos = universe.categories["internal"]["language"].getdict("typos")
+ words = message.split()
+ for index in range(len(words)):
+ word = words[index]
+ bare_word = word.strip(punctuation)
+ if bare_word in typos.keys():
+ words[index] = word.replace(bare_word, typos[bare_word])
+ message = " ".join(words)