From 1cfe6d6ce6ca9adc502683e38a46012798b623a6 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 11 Jan 2021 12:53:34 -0800 Subject: [PATCH] Implement a new "/help me" command that suggests something to try Thanks to Acme for the original "Have you tried" list as obtained from: http://web.mit.edu/puzzle/www/resources.html as: http://web.mit.edu/puzzle/www/resources/haveyoutried.pdf --- turbot/have_you_tried.py | 105 +++++++++++++++++++++++++++++++++++++++ turbot/help.py | 1 + turbot/interaction.py | 34 +++++++++---- 3 files changed, 130 insertions(+), 10 deletions(-) create mode 100644 turbot/have_you_tried.py diff --git a/turbot/have_you_tried.py b/turbot/have_you_tried.py new file mode 100644 index 0000000..4f0619b --- /dev/null +++ b/turbot/have_you_tried.py @@ -0,0 +1,105 @@ +import random + +things_to_try = [ + + # For starters + "reading the title and the blurb", + "typing it into a search engine", + ("pursuing even a train of thought that doesn’t seem " + + "to give a cogent answer at first"), + "looking at the list of helpful websites", + "looking at the binder of useful stuff", + + # Letters and words + "alphabetizing", + "using the leftover letters to spell something", + "rearranging the letters (aka “anagramming” or “transposing”)", + "looking for unusual letter frequencies", + "determining if it is a Rot 13/Caesar shift in general", + "shifting from letters to numbers", + "treating letters as protein sequences", + "treating letters as call letters", + "turning it into a cryptic crossword clue", + "seeing if these words relate to song lyrics", + "seeing if there are any acronyms of phrases", + ("diagonalizing (taking the first letter of the first answer, " + + "the second letter of the second. . .)"), + "looking at a computer keyboard", + "a pun", + + # Numbers + "graphing it functionally", + "graphing it parametrically", + "checking to see if your numbers are in the right base (including hex)", + "shifting from numbers to letters", + "using it as a phone number", + "using it as an IP address", + "matching numbers to MIT buildings", + "matching numbers to MIT courses", + "treating numbers as dates", + "treating numbers as atomic weights, numbers, etc.", + "treating numbers as latitude/longitude or GPS coordinates", + "treating numbers as radio stations", + "treating numbers as ASCII numbers", + "treating numbers as PLU numbers", + "treating numbers as ISBN numbers", + "seeing if there are any strange sequences", + "seeing if prime numbers are involved", + "seeing if fundamental constants are involved", + "asking what other numbers are close to the one you have", + + # Thirteen ways of looking at a puzzle + "looking at it in a mirror", + "squinting at it from far away", + "tilting it", + "looking at it upside down", + "looking through it", + "rewriting it neatly", + "rewriting it on graph paper", + "saying it out loud to someone else", + "putting yourself in the constructor’s shoes", + "making it 3D", + "cutting it up", + "folding it", + "connecting the dots", + + # What is it", + "looking at a song/poem/book/movie/TV show", + "Braille", + "Morse code", + "overlaying it on a map of MIT", + "getting on the T", + "checking it for pop culture references with Tanis, Jenn, Denis or James", + "using the Library of Congress or Dewey decimal system", + ("asking whether it has anything to do personally with the " + + "constructing team"), + "Palm graffiti", + "running it by someone who goes to MIT", + + # Zen + "trusting your instincts", + "trusting someone else’s instincts", + "asking “what’s weird about this?”", + "taking a step back", + "asking for fresh brains", + "checking your work", + "asking someone else to check your work", + "explaining your work to someone else", + "doing what you’ve already done again to the output", + "consulting the list of expertise", + "leaving the room", + "asking people if it looks like anything they recognize", + "thinking about what’s missing", + "asking yourself whether you’ve used all the information", + "keeping even a strange-looking result", + "brute force", + "not thinking about it", + "splitting up tasks to solve in a group", + "talking to a hunt veteran", + "talking to a hunt newbie", + "asking “what’s the pattern”", + "rereading the instructions", +] + +def have_you_tried(): + return "Have you tried {}?".format(random.choice(things_to_try)) diff --git a/turbot/help.py b/turbot/help.py index dbecfe3..9a4d9fd 100644 --- a/turbot/help.py +++ b/turbot/help.py @@ -25,6 +25,7 @@ Type `/help ` for more details on any command below. `/puzzle`: Display state of current puzzle (puzzle channel) *Solving support* (from any channel) + `/help me`: Get a suggestion of something to try `/rot [*|COUNT] `: Perform a Caesar shift on text """ diff --git a/turbot/interaction.py b/turbot/interaction.py index 53f45a7..f784a02 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -18,6 +18,7 @@ from turbot.puzzle import ( ) from turbot.round import round_quoted_puzzles_titles_answers from turbot.help import turbot_help +from turbot.have_you_tried import have_you_tried import turbot.rot import turbot.sheets import turbot.slack @@ -1334,21 +1335,34 @@ def help_command(turb, body, args): Displays help on how to use Turbot. """ + channel_name = body['channel_name'][0] channel_id = body['channel_id'][0] response_url = body['response_url'][0] + # Process "/help me" first. It calls out to have_you_tried rather + # than going through our help system. + # + # Also, it reports in the current channel, (where all other help + # output is reported privately to the invoking user). + if args == "me": + to_try = have_you_tried() + + # If this is a direct message then there's not a usable channel_id + # and we have to use the response_url instead + if channel_name == "directmessage": + requests.post(response_url, + json = {"text": to_try}, + headers = {"Content-type": "application/json"}) + else: + turb.slack_client.chat_postMessage( + channel=channel_id, text=to_try) + return lambda_ok + help_string = turbot_help(args) - # The "/help me" command is special in that it reports in the - # current channel, (where all other commands report privately to - # the invoking user). - if args == "me": - turb.slack_client.chat_postMessage( - channel=channel_id, text=help_string) - else: - requests.post(response_url, - json = {"text": help_string}, - headers = {"Content-type": "application/json"}) + requests.post(response_url, + json = {"text": help_string}, + headers = {"Content-type": "application/json"}) return lambda_ok -- 2.43.0