diff --git a/plugins/wordbot.py b/plugins/wordbot.py index dd76dc9..71ebc34 100644 --- a/plugins/wordbot.py +++ b/plugins/wordbot.py @@ -1,18 +1,17 @@ import asyncio import itertools import logging -from pathlib import Path import random import re import sqlite3 import time +from pathlib import Path from typing import Set from asyncirc.protocol import IrcProtocol from irclib.parser import Prefix from omnibot.plugin import Plugin - log = logging.getLogger(__name__) @@ -236,13 +235,36 @@ class Wordbot(Plugin): # Don't try to score words for inactive games return words_in_line = set(re.findall(r"[a-z0-9-]+", line.lower())) - matches = words_in_line & self.db.unmatched_words(channel) + matches = list(words_in_line & self.db.unmatched_words(channel)) + if not matches: + return + # "'foo', 'bar', and 'baz'" + words_list = ( + ", ".join([f"'{word}'" for word in matches[:-1]]) + + f" and '{matches[-1]}' are" + ) + + match len(matches): + case 1: + bark = "Congrats!" + words_list = f"'{matches[-1]}' is" + case 2: + bark = "Doubles!" + case 3: + bark = "Hat trick!" + case _: + bark = "Cheater!" + + points = f"{len(matches)} point" + if len(matches) > 1: + points += "s" + + self.send_to( + conn, + channel, + f"{who.nick}: {bark} {words_list} good for {points}.", + ) for word in matches: - self.send_to( - conn, - channel, - f"{who.nick}: Congrats! '{word}' is good for 1 point.", - ) self.db.add_score(channel, who.nick, word, line) async def handle_command(