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:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user