From 195e9015a8ee41ebaa5da3abc7faa14549e82686 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Mon, 9 May 2022 15:10:36 -0400 Subject: add author to toots also bumps deps and some various cleanups --- requirements.txt | 6 +++--- tooter.py | 34 ++++++++++++++++++---------------- tooter.service | 2 +- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/requirements.txt b/requirements.txt index a3e9998..7fac7b7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -Mastodon.py==1.5.0 -emoji==0.5.4 -ircrobots==0.3.7 +Mastodon.py==1.5.1 +emoji==1.7.0 +ircrobots==0.6.1 diff --git a/tooter.py b/tooter.py index ba80e2e..8a54a68 100644 --- a/tooter.py +++ b/tooter.py @@ -12,7 +12,7 @@ import json import os import sys -HELPTEXT = "helo i can send toots from irc: @tildeverse@tilde.zone - from @tildeteam from the #team channel)" +HELP_TEXT = "helo i can send toots from irc: @tildeverse@tilde.zone - from @tildeteam from the #team channel)" masto = {} assigned_channels = {} @@ -48,22 +48,23 @@ if len(sys.argv) > 1: def think(line): chan = line.params[0] - words = line.params[1].split(" ") - cmd = words[0].lower() + cmd, *words = line.params[1].split(" ") + cmd = cmd.lower()[1:] - if cmd == "!source": + if cmd == "source": return "https://tildegit.org/ben/tooter" - elif cmd in ["!botlist", "!toothelp"]: - return HELPTEXT - elif cmd == "!toot": + elif cmd in ["botlist", "toothelp"]: + return HELP_TEXT + elif cmd == "toot": if len(words) >= 2: status = emoji.emojize(" ".join(words[1:]), use_aliases=True) + author = line.tags.get("account", line.hostmask.nickname) res = masto[ assigned_channels[chan] if chan in assigned_channels else "tildeverse" - ].toot(status) + ].toot(f"{status}\n~{author}") return "tooted! {}".format(res["url"]) else: - return HELPTEXT + return HELP_TEXT class Server(BaseServer): @@ -80,13 +81,14 @@ class Server(BaseServer): 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") + 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 line.params[1].startswith("!") ): response = think(line) if response is not None: diff --git a/tooter.service b/tooter.service index 3a03672..5aa430d 100644 --- a/tooter.service +++ b/tooter.service @@ -5,7 +5,7 @@ After=tooter.service [Service] Type=simple WorkingDirectory=/home/ben/workspace/tooter -ExecStart=/usr/bin/python3 -u tooter.py +ExecStart=/home/ben/workspace/tooter/venv/bin/python3 -u tooter.py Restart=always RestartSec=5 StartLimitInterval=60s -- cgit 1.4.1