]> git.cworth.org Git - turbot/commitdiff
Add a /delete command
authorCarl Worth <cworth@cworth.org>
Sat, 8 Jan 2022 09:36:17 +0000 (01:36 -0800)
committerCarl Worth <cworth@cworth.org>
Sat, 8 Jan 2022 09:50:32 +0000 (01:50 -0800)
Which performs automated archiving of all channels for an inactive hunt.

turbot/interaction.py

index b2d83170d4a4a266083cf79394a747b94d4bce95..d7e8da6ff905bd086046ce499e82e47be319192a 100644 (file)
@@ -1214,6 +1214,50 @@ def solved(turb, body, args):
 
 commands["/solved"] = solved
 
+def delete(turb, body, args):
+    """Implementation of the /delete command
+
+    The argument to this command is the ID of a hunt.
+
+    The command will report an error if the specified hunt is active.
+
+    If the hunt is inactive, this command will archive all channels
+    from the hunt.
+    """
+
+    if not args:
+        return bot_reply("Error, no hunt provided. Usage: `/delete HUNT_ID`")
+
+    hunt_id = args
+    hunt = find_hunt_for_hunt_id(turb, hunt_id)
+
+    if not hunt:
+        return bot_reply("Error, no hunt named \"{}\" exists.".format(hunt_id))
+
+    if hunt['active']:
+        return bot_reply(
+            "Error, refusing to delete active hunt \"{}\".".format(hunt_id)
+        )
+
+    if hunt['hunt_id'] != hunt_id:
+        return bot_reply(
+            "Error, expected hunt ID of \"{}\" but found \"{}\".".format(
+                hunt_id, hunt['hunt_id']
+            )
+        )
+
+    puzzles = hunt_puzzles_for_hunt_id(turb, hunt_id)
+
+    for puzzle in puzzles:
+        channel_id = puzzle['channel_id']
+        turb.slack_client.conversations_archive(channel=channel_id)
+
+    turb.slack_client.conversations_archive(channel=hunt['channel_id'])
+
+    return lambda_ok
+
+commands["/delete"] = delete
+
 def hunt(turb, body, args):
     """Implementation of the /hunt command