diff --git a/ircbot/db.py b/ircbot/db.py index 4dc79d1..c00d00d 100644 --- a/ircbot/db.py +++ b/ircbot/db.py @@ -1,11 +1,12 @@ import contextlib +from typing import Any import pymysql @contextlib.contextmanager def cursor(*, user='ocfircbot', password): - conn = pymysql.connect( + conn: Any = pymysql.connect( user=user, password=password, db='ocfircbot', diff --git a/ircbot/plugin/quotes.py b/ircbot/plugin/quotes.py index f03d142..93f6b17 100644 --- a/ircbot/plugin/quotes.py +++ b/ircbot/plugin/quotes.py @@ -1,5 +1,6 @@ """Provide historical OCF quotes.""" from ircbot import db +from ircbot.plugin.space_tooling import insert_space_sentence def register(bot): @@ -12,7 +13,7 @@ def register(bot): def _print_quote(respond, quote): respond( - 'Quote #{}: {}'.format(quote['id'], quote['quote']), + insert_space_sentence('Quote #{}: {}'.format(quote['id'], quote['quote'])), ping=False, ) diff --git a/ircbot/plugin/space_tooling.py b/ircbot/plugin/space_tooling.py new file mode 100644 index 0000000..cf15cdd --- /dev/null +++ b/ircbot/plugin/space_tooling.py @@ -0,0 +1,11 @@ +"""Space tooling for turing.py and quotes.py""" +import re + + +def insert_space(w): + halfway = len(re.sub(r'-slack([^A-Za-z0-9_\-\\\[\]{}^`|]|\Z)', r'\1', w)) // 2 + return w[:halfway] + '\u2060' + w[halfway:] + + +def insert_space_sentence(sentence): + return ' '.join(map(insert_space, sentence.split())) diff --git a/ircbot/plugin/turing.py b/ircbot/plugin/turing.py index 022b8a3..20237a9 100644 --- a/ircbot/plugin/turing.py +++ b/ircbot/plugin/turing.py @@ -4,6 +4,7 @@ import markovify from ircbot import db +from ircbot.plugin.space_tooling import insert_space_sentence final_model = None @@ -30,11 +31,8 @@ def markov(bot, msg): # using "<@keur>" syntax. Additionally, remove any -slack at # the end of a nick, to avoid inserting a space like # abcde|-slack (thus pinging abcde). - def insert_space(w): - halfway = len(re.sub(r'-slack([^A-Za-z0-9_\-\\\[\]{}^`|]|\Z)', r'\1', w)) // 2 - return w[:halfway] + '\u2060' + w[halfway:] msg.respond( - ' '.join(map(insert_space, sentence.split())), + insert_space_sentence(sentence), ping=False, ) else: