X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=sidebyside;f=turbot%2Finteraction.py;fp=turbot%2Finteraction.py;h=d7e8da6ff905bd086046ce499e82e47be319192a;hb=b7be5feac00a7e3ff5ceadbf7c5ab1bc5e3259d8;hp=b2d83170d4a4a266083cf79394a747b94d4bce95;hpb=5f24de7e9cdb24f5bf751e3ce1d6d7333241747f;p=turbot 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