From: Carl Worth Date: Sat, 8 Jan 2022 09:36:17 +0000 (-0800) Subject: Add a /delete command X-Git-Url: https://git.cworth.org/git?p=turbot;a=commitdiff_plain;h=b7be5feac00a7e3ff5ceadbf7c5ab1bc5e3259d8 Add a /delete command Which performs automated archiving of all channels for an inactive hunt. --- diff --git a/turbot/interaction.py b/turbot/interaction.py index b2d8317..d7e8da6 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -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