Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ircbot/db.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
3 changes: 2 additions & 1 deletion ircbot/plugin/quotes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Provide historical OCF quotes."""
from ircbot import db
from ircbot.plugin.space_tooling import insert_space_sentence


def register(bot):
Expand All @@ -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,
)

Expand Down
11 changes: 11 additions & 0 deletions ircbot/plugin/space_tooling.py
Original file line number Diff line number Diff line change
@@ -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()))
6 changes: 2 additions & 4 deletions ircbot/plugin/turing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import markovify

from ircbot import db
from ircbot.plugin.space_tooling import insert_space_sentence

final_model = None

Expand All @@ -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:
Expand Down