From 232527cd3ad4dbed9d847f5c8124b058c989674c Mon Sep 17 00:00:00 2001 From: Max Marrone Date: Sat, 30 Mar 2024 13:02:51 -0400 Subject: [PATCH] wordbot: Recognize words adjacent to punctuation. If there was an unmatched word 'foo', and someone wrote 'foo. bar.', wordbot would not recognize the match because it was only splitting the string on spaces, not punctuation. This treats as a word any contiguous sequence of letters, numbers (just in case) and hyphens (just in case). Signed-off-by: Alek Ratzloff --- plugins/wordbot.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/wordbot.py b/plugins/wordbot.py index 03c4f83..e539047 100644 --- a/plugins/wordbot.py +++ b/plugins/wordbot.py @@ -3,6 +3,7 @@ import itertools import logging from pathlib import Path import random +import re import sqlite3 import time from typing import Set @@ -234,8 +235,8 @@ class Wordbot(Plugin): if not self.db.is_game_active(channel): # Don't try to score words for inactive games return - parts = {word.strip().lower() for word in line.split()} - matches = parts & self.db.unmatched_words(channel) + words_in_line = {re.findall("[a-z0-9-]+", line.lower())} + matches = words_in_line & self.db.unmatched_words(channel) for word in matches: self.send_to( conn,