diff --git a/.gitignore b/.gitignore index 876898e..011c23a 100644 --- a/.gitignore +++ b/.gitignore @@ -59,4 +59,4 @@ docs/_build/ target/ venv/ -account.ini +config.ini diff --git a/README.md b/README.md index 7ccf485..48315be 100644 --- a/README.md +++ b/README.md @@ -14,15 +14,16 @@ deps: . venv/bin/activate pip install -r requirements.txt -1. adjust config.ini -1. start the bot +2. `cp config.ini{.sample,}` +3. edit config.ini +4. start the bot venv/bin/python3 tracer.py ### daemonization -1. adjust tracer.service 1. `mkdir -p ~/.config/systemd/user` 1. `cp tracer.service ~/.config/systemd/user/` +1. adjust ~/.config/systemd/user/tracer.service as needed 1. `systemctl --user daemon-reload` 1. `systemctl --user enable --now tracer` diff --git a/account.ini.sample b/account.ini.sample deleted file mode 100644 index 7dcf1af..0000000 --- a/account.ini.sample +++ /dev/null @@ -1,4 +0,0 @@ -[nickserv] -username = bensbots -password = my super secret password - diff --git a/config.ini b/config.ini.sample similarity index 60% rename from config.ini rename to config.ini.sample index d4386bb..feeafd2 100644 --- a/config.ini +++ b/config.ini.sample @@ -5,3 +5,6 @@ nick = tracer port = 6667 tls = false +[sasl] +username = tracer +password = my super secret password diff --git a/requirements.txt b/requirements.txt index 7776149..0f3ced4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ tracery==0.1.1 -ircrobots==0.3.7 +ircrobots==0.6.1 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() diff --git a/tracer.service b/tracer.service index 882929b..6d4225a 100644 --- a/tracer.service +++ b/tracer.service @@ -5,7 +5,7 @@ After=tracer.service [Service] Type=simple WorkingDirectory=/home/ben/workspace/tracer -ExecStart=/usr/bin/python3 -u tracer.py +ExecStart=/home/ben/workspace/tracer/venv/bin/python3 -u tracer.py Restart=always RestartSec=5 StartLimitInterval=60s @@ -13,4 +13,3 @@ StartLimitBurst=3 [Install] WantedBy=default.target -