Allow fltering of quotes

This commit is contained in:
Firepup Sixfifty 2023-11-17 20:24:36 -06:00
parent 9e0bbf1782
commit ed24794a40
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA

View file

@ -2,7 +2,7 @@ from subprocess import run, PIPE
import config as conf import config as conf
import random as r import random as r
from typing import Any, Callable from typing import Any, Callable
import bare import bare, re
def goat(bot: bare.bot, chan: str, name: str, message: str) -> None: def goat(bot: bare.bot, chan: str, name: str, message: str) -> None:
@ -98,9 +98,16 @@ def goatOff(bot: bare.bot, chan: str, name: str, message: str) -> None:
def quote(bot: bare.bot, chan: str, name: str, message: str) -> None: def quote(bot: bare.bot, chan: str, name: str, message: str) -> None:
qfilter = ".*"
query = "null"
if " " in message:
query = message.split(" ", 1)[1]
qfilter = f".*{query}.*"
r.seed() r.seed()
mm = open("mastermessages.txt", "r") mm = open("mastermessages.txt", "r")
q = mm.readlines() q = list(filter(lambda x: re.match(qfilter, x), mm.readlines()))
if q == []:
q = [f'No results for "{query}" ']
sel = conf.decode_escapes( sel = conf.decode_escapes(
str(r.sample(q, 1)).strip("[]'").replace("\\n", "").strip('"') str(r.sample(q, 1)).strip("[]'").replace("\\n", "").strip('"')
) )