about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2021-02-24 15:14:06 -0500
committerBen Harris <ben@tilde.team>2021-02-24 15:14:06 -0500
commit865f9b8b46ed76e733b01da73044e3ef41789fb3 (patch)
treed54efedc3ba4331fb054bf0cfae2ca3bfe926421
parent1a7b63055b7a879bd5a4c6f5d18f24e51a5a051e (diff)
move parameter count check
-rw-r--r--tracer.py55
1 files 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()