From 865f9b8b46ed76e733b01da73044e3ef41789fb3 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 24 Feb 2021 15:14:06 -0500 Subject: [PATCH] move parameter count check --- tracer.py | 55 ++++++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/tracer.py b/tracer.py index b8706ef..4c1f6ad 100644 --- a/tracer.py +++ b/tracer.py @@ -68,8 +68,7 @@ populate() def generate(rule): populate() if rule in DB: - g = random.choice(DB[rule]) - return grammar(load_rules(g)).flatten("#origin#") + return grammar(load_rules(random.choice(DB[rule]))).flatten("#origin#") def listify(col): @@ -103,35 +102,30 @@ def fuse(argv): def think(line): words = line.params[1].split(" ") - - if len(words) > 0: - if words[0] == "!!list": - return " ".join(DB) - elif words[0] == "!!source": - return REPOLINK - elif words[0] in ["!!help", "!botlist"]: - return HELPTEXT - elif words[0] == "!!fuse": + if words[0] == "!!list": + return " ".join(DB) + elif words[0] == "!!source": + return REPOLINK + elif words[0] in ["!!help", "!botlist"]: + return HELPTEXT + elif words[0] == "!!fuse": + if "|" in words: + w = words.index("|") + res = fuse(words[1:w]) + if res: + return " ".join(words[w + 1 :]) + " " + res + else: + res = fuse(words[1:]) + if res: + return res + elif words[0].startswith("!!"): + res = generate(words[0][2:]) + if res: if "|" in words: w = words.index("|") - print(words[1:w]) - res = fuse(words[1:w]) - if res: - return " ".join(words[w + 1 :]) + " " + res + return " ".join(words[w + 1 :]) + " " + res else: - print(words[1:]) - res = fuse(words[1:]) - print(res) - if res: - return res - elif words[0].startswith("!!"): - res = generate(words[0][2:]) - if res: - if "|" in words: - w = words.index("|") - return " ".join(words[w + 1 :]) + " " + res - else: - return res + return res class Server(BaseServer): @@ -151,6 +145,7 @@ class Server(BaseServer): line.command == "PRIVMSG" and self.has_channel(line.params[0]) and self.has_user(line.hostmask.nickname) + and len(line.params[1].split(" ")) > 0 and not line.hostmask is None and not self.casefold(line.hostmask.nickname) == self.nickname_lower and not ("batch" in line.tags and line.tags["batch"] == "1") @@ -172,8 +167,6 @@ class Bot(BaseBot): async def main(): - bot = Bot() - params = ConnectionParams( config["nick"], host=config["server"], @@ -181,7 +174,7 @@ async def main(): tls=config.getboolean("tls"), sasl=SASLUserPass(account["username"], account["password"]), ) - + bot = Bot() await bot.add_server("tilde", params) await bot.run()