aboutsummaryrefslogtreecommitdiff
path: root/markov/markov.py
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2024-03-20 03:14:38 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2024-03-20 03:14:38 +0000
commit08069e8d35e10a85087c1938fffb4f5a8c625e14 (patch)
tree7856852dd96d356aafcfa4536218d4df897ecb67 /markov/markov.py
parent16aeaa50db79e3c17194128a93d22370bf5daa33 (diff)
downloadaps-cogs-08069e8d35e10a85087c1938fffb4f5a8c625e14.tar
aps-cogs-08069e8d35e10a85087c1938fffb4f5a8c625e14.tar.gz
aps-cogs-08069e8d35e10a85087c1938fffb4f5a8c625e14.zip
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.
Diffstat (limited to 'markov/markov.py')
-rw-r--r--markov/markov.py8
1 files changed, 4 insertions, 4 deletions
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