about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2020-05-07 14:39:27 -0400
committerBen Harris <ben@tilde.team>2020-05-07 14:39:27 -0400
commit7ee1f9a7aa62cddf9897e5f64d54723383e2ab84 (patch)
tree0a3409472d3e8a9957cb3d2f4ffb04c4ef89982f
parenta4b5440be5c10a43945d47c2da2eaa10b4c2c75b (diff)
fix crash on empty toot
-rw-r--r--tooter.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/tooter.py b/tooter.py
index 4e98182..117185f 100644
--- a/tooter.py
+++ b/tooter.py
@@ -9,6 +9,7 @@ import re
 import socket
 import sys
 
+HELPTEXT = "helo i can send toots from irc: @tildeverse@tilde.zone - from @tildeteam from the #team channel)"
 
 def masto_from_json(conf):
     conf = json.load(conf)
@@ -38,20 +39,20 @@ def think(line):
     if len(words) > 0 and line.hostmask.nickname != config["botnick"]:
         cmd = words[0].lower()
         if cmd == "!toot":
-            status = emoji.emojize(" ".join(words[1:]), use_aliases=True)
-            if chan == "#team":
-                res = tildeteam.toot(status)
+            if len(words) >= 2:
+                status = emoji.emojize(" ".join(words[1:]), use_aliases=True)
+                if chan == "#team":
+                    res = tildeteam.toot(status)
+                else:
+                    res = tildeverse.toot(status)
+                print(res)
+                send(chan, "tooted! {}".format(res["url"]))
             else:
-                res = tildeverse.toot(status)
-            print(res)
-            send(chan, "tooted! {}".format(res["url"]))
+                send(chan, HELPTEXT)
         elif cmd == "!source":
             send(chan, "https://tildegit.org/ben/tooter")
         elif cmd in ["!botlist", "!toothelp"]:
-            send(
-                chan,
-                "helo i can send toots from irc: @tildeverse@tilde.zone - from @tildeteam from the #team channel)",
-            )
+            send(chan, HELPTEXT)
 
 
 # do setup