+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
+