about summary refs log tree commit diff
path: root/tracer.py
diff options
context:
space:
mode:
Diffstat (limited to 'tracer.py')
-rw-r--r--tracer.py69
1 files changed, 36 insertions, 33 deletions
diff --git a/tracer.py b/tracer.py
index 4c1f6ad..d625078 100644
--- a/tracer.py
+++ b/tracer.py
@@ -14,21 +14,21 @@ import random
 import traceback
 import tracery
 
-HELPTEXT = "helo i'm a tracery bot that makes cool things from tracery grammars in your ~/.tracery. see http://tracery.io for more info"
-REPOLINK = "https://tildegit.org/ben/tracer"
+HELP_TEXT = "helo i'm a tracery bot that makes cool things from tracery grammars in your ~/.tracery. see " \
+            "https://tracery.io for more info "
+REPO_LINK = "https://tildegit.org/ben/tracer"
 
 DB = {}
 
 # read configuration
-config = configparser.ConfigParser(
-    converters={"list": lambda x: [i.strip() for i in x.split(",")]}
-)
-config.read("config.ini")
-config = config["irc"]
+if not os.path.isfile("config.ini"):
+    print("you must create a config.ini file")
+    exit(1)
 
-account = configparser.ConfigParser()
-account.read("account.ini")
-account = account["nickserv"]
+parser = configparser.ConfigParser()
+parser.read("config.ini")
+config = parser["irc"]
+account = parser["sasl"]
 
 
 def grammar(rules):
@@ -101,29 +101,30 @@ def fuse(argv):
 
 
 def think(line):
-    words = line.params[1].split(" ")
-    if words[0] == "!!list":
+    command, *words = line.params[1].split(" ")
+
+    if command == "!!list":
         return " ".join(DB)
-    elif words[0] == "!!source":
-        return REPOLINK
-    elif words[0] in ["!!help", "!botlist"]:
-        return HELPTEXT
-    elif words[0] == "!!fuse":
+    elif command == "!!source":
+        return REPO_LINK
+    elif command in ["!!help", "!botlist"]:
+        return HELP_TEXT
+    elif command == "!!fuse":
         if "|" in words:
             w = words.index("|")
-            res = fuse(words[1:w])
+            res = fuse(words[:w])
             if res:
-                return " ".join(words[w + 1 :]) + " " + res
+                return " ".join(words[w + 1:]) + " " + res
         else:
-            res = fuse(words[1:])
+            res = fuse(words)
             if res:
                 return res
-    elif words[0].startswith("!!"):
-        res = generate(words[0][2:])
+    elif command.startswith("!!"):
+        res = generate(command[2:])
         if res:
             if "|" in words:
                 w = words.index("|")
-                return " ".join(words[w + 1 :]) + " " + res
+                return " ".join(words[w + 1:]) + " " + res
             else:
                 return res
 
@@ -134,22 +135,23 @@ class Server(BaseServer):
 
     async def line_read(self, line: Line):
         print(f"{self.name} < {line.format()}")
+
         if line.command == "001":
-            await self.send(build("JOIN", [",".join(config.getlist("channels"))]))
             await self.send(build("MODE", [self.nickname, "+B"]))
 
         if line.command == "INVITE":
             await self.send(build("JOIN", [line.params[1]]))
 
         if (
-            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")
-            and not "inspircd.org/bot" in line.tags
+                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 line.hostmask is not None
+                and not self.casefold(line.hostmask.nickname) == self.nickname_lower
+                and not ("batch" in line.tags and line.tags["batch"] == "1")
+                and "inspircd.org/bot" not in line.tags
+                and line.params[1].startswith("!")
         ):
             try:
                 response = think(line)
@@ -173,9 +175,10 @@ async def main():
         port=config.getint("port"),
         tls=config.getboolean("tls"),
         sasl=SASLUserPass(account["username"], account["password"]),
+        autojoin=[config["channels"]]
     )
     bot = Bot()
-    await bot.add_server("tilde", params)
+    await bot.add_server(config["server"], params)
     await bot.run()