Carl Worth [Fri, 1 Jan 2021 18:42:14 +0000 (10:42 -0800)]
Make /solved clear the state string for a puzzle
In the last test we run, we often saw stale state messages about a
puzzle being half-solve, etc. when it was actually already completely
solved. Instead of putting another chore onto solvers to have them
manually clear the state string after solving a puzzle, here we do
that automatically.
This completes another low-hanging fruit item from the TODO list.
Carl Worth [Fri, 1 Jan 2021 06:04:57 +0000 (22:04 -0800)]
Update TODO now that initial round selection is available
One TODO item is clearly complete here: The new multi-select field in
the modal form when creating a puzzle. That's working well enough that
I don't think we need the separate /round command so I'm dropping that
from the TODO.
Two little things are needed to really make round support complete:
* Display/grouping of rounds in the Turbot home view
* Select same rounds (by default) when creating a new puzzle in the
same channel of an existing channel
Carl Worth [Fri, 1 Jan 2021 01:00:33 +0000 (17:00 -0800)]
Add a multi-select round field to puzzle creation
Actually, there are two round fields. The first is a free-form text
field for a comma-separated list of rounds. Each of these rounds will
be added to the database as an item with only two attributes:
hunt_id: <HUNT_ID>
SK: round-<ROUND>
The other field is a multi-select field populated with the names of
all rounds that already exist in the hunt. This makes for easy
selection without having to worry about typing in names identical with
what others typed previously.
Carl Worth [Fri, 1 Jan 2021 01:53:29 +0000 (17:53 -0800)]
Add a handler for multi_static_select input
The documentation of the multi_static_select input block wasn't clear
that it would trigger a call to an event handler, but apparently it does.
We don't currently impose any restrictions on what a user selects,
(any combination of rounds is valid), so we simply return a lamba_ok
value for any selection. This prevents the user from seeing a warning
sign in the dialog (where hovering over it would say that the callback
returned 502).
Carl Worth [Thu, 31 Dec 2020 23:12:59 +0000 (15:12 -0800)]
Make the error message from /state a little more explicit
Specifically, make it clear that it was /state that caused the error.
(This is useful because the /state command doesn't get insterted into
the channel history but the error response does. So repeating this in
the error message can make things more clear if the conversation is
referred to by the user later.)
Carl Worth [Thu, 31 Dec 2020 22:43:07 +0000 (14:43 -0800)]
Rework code to map channel IDs to hunt or puzzle objects from the database
The old functions were named things like channel_is_puzzle,
channel_is_hunt, and fund_hunt_for_channel. These were still expecting
the old multi-table database schema so they were broken, (as was all
functionality built on top of them such as the /state and /solved
commands).
The new functions are built on the all-one-table database schema, so
should actually work again. They also have a cleaner interface in that
they only rely only on channel ID (and never put any special stock in
the channel name). Instead of doing magic with the channel name, the
code looks up the hunt_id from the database entry for a puzzle as
needed.
The new functions are named puzzle_for_channel and hunt_for_channel
and are implemented on top of a common, internal function:
db_entry_for_channel.
Carl Worth [Thu, 31 Dec 2020 22:02:36 +0000 (14:02 -0800)]
Update TODO for removed auto-invitation of users to puzzle channels
In recent commits we changed from auto-inviting all users to all new
puzzle channels to instead notify the main hunt channel whenever a new
puzzle channel becomes available.
Carl Worth [Thu, 31 Dec 2020 20:05:13 +0000 (12:05 -0800)]
Rename primary-key attribute from PK to hunt_id
I was just about to add a separate attribut to every item in the
database named hunt_id when I realized that that was totally redundant
with our existing PK attribute (whose values were simply the hunt_id
prefixed by "hunt-" in all cases).
Since we're not using the PK field in any generalized sense, (that is,
it's _always_ populated with the hunt_id value), it's much simpler and
more efficient to just name it "hunt_id" and store the hunt_id valeu
ther directly (without any prefix).
Carl Worth [Thu, 31 Dec 2020 19:52:43 +0000 (11:52 -0800)]
Rename hunt_id_index to is_hunt_index
Backed, of course, by a new is_hunt attribute.
The rationale here is that the whole point of this index is to be a
sparse attribute so that the code can efficiently query all existing
hunts. But meanwhile, it's useful for puzzles to have a "hunt_id"
attribute, which would confict with the goal of having "hunt_id" be
sparse and populated only for hunts and not puzzles.
So the fix here is to make hunt_id universal, and instead have a
separate "is_hunt" attribute which is the sparse one, (and will
clearly never be populated for a puzzle).
Carl Worth [Thu, 31 Dec 2020 18:29:54 +0000 (11:29 -0700)]
Don't put an attribute into the database for 'url' that is left blank
The URL field, (for either a hunt or a puzzle), is an optional
parameter, (the user creating the hunt or puzzle may or may not
provide a URL). Immediately prior to this commit, if a user left the
URL field blank, the submission handler was receiving a value of None
and inserting that as an attribute in the database.
This was problematic as subsequent code, (such as sheet creation),
would be prepared for an item to have no url key at all, but was not
prepared for the key to be present but for the value to be empty.
We fix this in this commit by explicitly _not_ inserting a None value
for url as an attribute in the database item, (instead, not supplying
a url attribute at all).
Carl Worth [Thu, 31 Dec 2020 17:31:24 +0000 (10:31 -0700)]
Convert /puzzle puzzle creation to all-one-table database schema
So we put the hunt ID into the PK field and the puzzle ID into the SK field,
(allowing puzzle items to be distinguished from hunt items in the table).
While doing this, we also disable the feature of inviting all hunt
users to the new puzzle. This is both because that code hasn't been
ported to the new schema, and also because that feature is planned to
be eliminated anyway.
Carl Worth [Thu, 31 Dec 2020 17:22:04 +0000 (10:22 -0700)]
Home: Update query for finding puzzles to new all-one-table schema
Previously, we looked in a separate per-hunt table to find the puzzles
for a hunt. Now, instead, we look in the single "turbot" table and
find puzzles for a hunt by looking for items whose PK is
"hunt-<HUNT_ID>" and whose SK starts with "puzzle-".
Carl Worth [Thu, 31 Dec 2020 17:14:17 +0000 (10:14 -0700)]
Turbot home: Use recently added hunt_id_index to find existing hunts
This fixes the home view to correctly use the new single-table schema to
find the list of available hunts. This view is now working to display
the names of active hunts a user belongs to.
(No puzzles are listed yet. That part of the home view still needs to be
brought up to date with the latest schema.)
Carl Worth [Wed, 30 Dec 2020 20:17:43 +0000 (13:17 -0700)]
Add a "make flake" recipe and clean up some style bugs flake8 noticed
We also ignore some rules about whether or not there's a space on
either side of some operators, since I fundmanetally disagree with
flake8 on some of these.
Carl Worth [Tue, 29 Dec 2020 23:33:37 +0000 (16:33 -0700)]
Beginning of transition to single-table database schema
This is aiming for a one-big-table approach, (which is the DynamoDB
best practice), instead of having one table for hunts and then a
separate per-hunt table for puzzles.
This new approach will be more flexible as we start adding database
items for rounds, etc. In the old approach, rounds would likely have
become yet another hunt-specific table, and the number of per-hunt
tables would have started to become rather messy.
With this new schema, rounds can instead be just another item, where
hunts, rounds, and puzzles can all be intermingled as items in the
same table.
To get this all to work, we are creating secondary indexes for
querying items from the database via attributes other than the primary
key, (for example a "channel_id" index).
As of this commit, the "New Hunt" button works in that it:
* Creates the turbot DynamoDB table if it doesn't exist
* Inserts a new item into the table for the hunt itself (active=False)
* Marks the sheet_url of the item as "pending"
* Creates a new channel for the hunt
* Responds to the channel_created event
* Creates a Google sheet for the hunt
* Stores the sheet_url in the database
* Marks the hunt as active=True in the database
* Reports to the Slack channel that things are working
So that much is working, but everything else has yet to be converted
to the new schema. So things that don't yet work include at least:
* The turbot "Home" view doesn't yet display anything
Carl Worth [Sun, 27 Dec 2020 20:34:58 +0000 (12:34 -0800)]
Add (and use) a new function find_hunt_for_hunt_id
The code to call get_table_item with a hunt_id was broken, (since in
the schema, hunt_id is not the key, only channel_id is), so instead we
need to scan the table looking for a matching hunt_id. We already had
code to do this is find_hunt_for_channel, so here we factor that out
into a new function, find_hunt_for_hunt_id and call it instead of
get_table_item.
Carl Worth [Sun, 27 Dec 2020 20:11:59 +0000 (12:11 -0800)]
Add hunt_id to the puzzle table (instead of orig_channel_name)
A recent commit (to announce /solved in the main hunt channel)
expected to find hunt_id in this table, but it wasn't there. So we add
it in this commit. And while adding it, we drop the orig_channel_name
field, (which embedded both hunt_id and channel_id into a single field
in the database so would have made renaming of the hunt_id rather
awkward).
Carl Worth [Sun, 27 Dec 2020 19:25:03 +0000 (11:25 -0800)]
Rework find_hunt_for_channel to return a hunt dictionary
It's going to be most convenient to return hunt and puzzle dictionaries
that contain all entries from the database, (rather than a hard-coded
tuple which is likely to not contain every piece of data we'll eventually
want to have).
Carl Worth [Fri, 23 Oct 2020 21:29:06 +0000 (14:29 -0700)]
Use blocks to send the welcome message
This approach has the benefit of allowing separate sections, (I tried
doing this with newlines in the 'text' parameter but they were getting
swallowed by Slack).
Carl Worth [Fri, 23 Oct 2020 12:54:27 +0000 (05:54 -0700)]
Cache SSM parameter values into environment variables
The goal here is to reduce SSM parameter reads/writes. Hopefully, as
AWS reuses a container for multiple calls to our Lambda function,
these values can be read from the environment instead of needing to
reach out to AWS.
The reason we want to reduce calls to SSM functions in that AWS Free
Tier gives us only 20,000 KMS requests compared to 1,000,000 AWS
Lambda requests.
Carl Worth [Thu, 22 Oct 2020 12:15:04 +0000 (05:15 -0700)]
Use absolute URLs to link to channels
This way we can just make the puzzle name a link rather than having
the noise of the channel name present in the view too, (which doesn't
actually add anything).
Carl Worth [Thu, 22 Oct 2020 10:36:51 +0000 (03:36 -0700)]
Drop the hunt_channel_id from the metadata passed in the puzzle modal
We've now got another handoff, from the puzzle modal's submission
handler to a separate channel_created event before the hunt's
channel_id is needed. And by then we've lost the context of this
private_metadata, (so the current code scans through the database
'hunts' table to find the ID). Given all that, we can drop this unused
field from the metadata.
Carl Worth [Thu, 22 Oct 2020 07:50:09 +0000 (00:50 -0700)]
Defer all sheet creation until after the channel is created
Specifically, we no longer attempt to do sheet creation in the handler
for the interaction of the user submitting a modal dialog. The reason
that was a a bad idea is that the sheet creation can take several
seconds, (including time to copy data from a template sheet, etc.),
while Slack will timeout after merely 3 seconds of a user submission
and report an error.
This way, we can promptly validate the user's input (giving them a
clean error on the form if necessary), then simply create the channel
in the handler and primomptly return (so Slack doesn't timeout).
Then, separately, we now have a listener setup for the channel_created
event and in _that_ handler we do all the sheet creation necessary. We
have all the time we want here since channel_created is just an event
without a user waiting for a response, so Slack doesn't impose a
3-second timeout on us.
Carl Worth [Thu, 22 Oct 2020 09:37:04 +0000 (02:37 -0700)]
Create the hunts table if it doesn't already exist
I just realized I was probably missing a necessary index on the hunts
table, meaning I need to destroy it ad recreate it. But I don't want
to do that manually without any code to capture what I did.
And if I'm going to write code, I might as well have that code called
implcitly as needed. So that's what's present here, the code necessary
to create the hunts table if it doesn't already exist.
Carl Worth [Wed, 21 Oct 2020 23:12:42 +0000 (16:12 -0700)]
Implement a new `/puzzle` slash command to create a puzzle
This command doesn't (yet) accept any arguments. Instead, it pops up a
modal dialog to prompt for the puzzle name, ID, and URL.
The command also only works from a top-level hunt channel.
Some things that would be nice improvements here:
* Auto-fill the puzzle ID based on the puzzle name without
punctuation and spaces replaced with underscores.
* Allow the command to work from the channel of any puzzle in the
hunt
* Fix the bug that the modal dialog reports an error even when
things work correctly, (the problem is that the lambda is taking
more than the maximum 3 seconds that Slack is willing to wait for
a response).
Carl Worth [Wed, 21 Oct 2020 23:00:20 +0000 (16:00 -0700)]
Combine actions.py and commands.py into interaction.py
We're about to create a new slash command that fires up a modal, and
the response to that modal will be an action. So we want the
implementation of that slash command (which creates the view for the
modal) to be in the same file as the handler for the action.
So we combine these together for now.
If this file become unwieldy later, we can re-separate things based on
functional groups, (interactions related to hunts, puzzles, word-play
utilities, etc.), but always keeping the view creators and the
view-submission handlers together for any given view.
Carl Worth [Wed, 21 Oct 2020 20:38:40 +0000 (13:38 -0700)]
Drop unused initialization of submission_handlers dictionary
We don't use this dictionary with any statically-initialized keys,
(such as "new_hunt" as we have it here). Instead, this dictionary is
populated dynamically with keys that are view IDs. So we can just drop
this initialization here and everything continues to work as is.
Carl Worth [Wed, 21 Oct 2020 18:57:45 +0000 (11:57 -0700)]
Make text optional for slash commands
We're planning a new approach which is to make it so that a slash
command with no argument string pops up a modal dialog. For this to
work, we have to allow for a body that includes no 'text' key.
Carl Worth [Wed, 21 Oct 2020 18:46:09 +0000 (11:46 -0700)]
Dont' allow hunt_id to contain a hyphen
We're planning to use a hyphen in the puzzles' channel names to
separate the hunt_id from the rest of the puzzle's channel name, so
the hunt_id itself must not contain any hyphen.
Carl Worth [Wed, 21 Oct 2020 18:40:38 +0000 (11:40 -0700)]
Rename 'slug' field in hunt table to 'hunt_id'
We were already using the name "Hunt ID" in all user-visibile
interfaces, so there was no good justification for having a totally
different name internally.
Carl Worth [Wed, 21 Oct 2020 16:39:54 +0000 (09:39 -0700)]
Add a stub function for hanlding a shortcut invocation
We're not currently pursuing this option, (because the global shortcuts
are annoyingly truly global---they would be a lot more useful it the
payload included the ID of the current channel from where they were
invoked). But here's the stub in case we ever want to start using these
in the future.
Carl Worth [Tue, 20 Oct 2020 01:48:08 +0000 (18:48 -0700)]
Correct the code storing the picked base64 token
Using 'str()' here was incorrect. That did go from a bytes value to a
string, but it did it by adding "b'" to the beginning and "'" to the
end, breaking the parsing of the base64 value.
Here, instead, we use the decode('us-ascii') method on the bytes value.
Carl Worth [Mon, 19 Oct 2020 21:43:40 +0000 (14:43 -0700)]
Create a sheet for the hunt when creating a new hunt
I don't know how much we'll need this, but here it is for consistency.
This commit adds support for the Google sheets API (accessed via a
pickled token from an encrypted SSM parameter). This will be very
handy in the future when creating sheets for each puzzle channel, etc.