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 <alekratz@gmail.com>
This commit is contained in:
Max Marrone
2024-03-30 13:02:51 -04:00
committed by Alek Ratzloff
parent 3ac312db6d
commit 232527cd3a

View File

@@ -3,6 +3,7 @@ import itertools
import logging import logging
from pathlib import Path from pathlib import Path
import random import random
import re
import sqlite3 import sqlite3
import time import time
from typing import Set from typing import Set
@@ -234,8 +235,8 @@ class Wordbot(Plugin):
if not self.db.is_game_active(channel): if not self.db.is_game_active(channel):
# Don't try to score words for inactive games # Don't try to score words for inactive games
return return
parts = {word.strip().lower() for word in line.split()} words_in_line = {re.findall("[a-z0-9-]+", line.lower())}
matches = parts & self.db.unmatched_words(channel) matches = words_in_line & self.db.unmatched_words(channel)
for word in matches: for word in matches:
self.send_to( self.send_to(
conn, conn,