From 08069e8d35e10a85087c1938fffb4f5a8c625e14 Mon Sep 17 00:00:00 2001 From: Arjun Satarkar Date: Tue, 19 Mar 2024 23:14:38 -0400 Subject: markov: fix bug where append_token could clobber previous token Specifically if we had an open paren followed by some other punctuation, the open paren would disappear. Probably this didn't exist before the addition of parens as valid tokens. --- markov/markov.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'markov') diff --git a/markov/markov.py b/markov/markov.py index 73ac08e..d7cf14b 100644 --- a/markov/markov.py +++ b/markov/markov.py @@ -164,12 +164,12 @@ class Markov(commands.Cog): def append_token(self, text, token): # NOTE: if changing PUNCTUATION, also change the regex in process_message() with the corresponding note PUNCTUATION = r".,!?/;()" - if token == "/": - text = text[:-1] + token - elif token == "(": + if token == "(": text += token + elif token == "/": + text = text.removesuffix(" ") + token elif token in PUNCTUATION: - text = text[:-1] + token + " " + text = text.removesuffix(" ") + token + " " else: text += token + " " return text -- cgit v1.2.3-57-g22cb