Skip to content

Commit

Permalink
Add an option to immediately open the table for joining
Browse files Browse the repository at this point in the history
Validate the new `open` option as some style of boolean, applying it last.

Rebased against latest master.
  • Loading branch information
mavit committed Dec 24, 2020
1 parent e725ffa commit 6c66784
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/bga_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,13 @@ async def parse_options(self, options, table_id):
# options will overwrite defaults if they are there
defaults.update(options)
updated_options = defaults

if "open" not in updated_options \
and "restrictgroup" in updated_options:
updated_options["open"] = "true"

url_data = []
final_url_data = []
for option in updated_options:
value = updated_options[option]
option_data = {}
Expand Down Expand Up @@ -275,6 +281,14 @@ async def parse_options(self, options, table_id):
elif option == "lang":
option_data["path"] = "/table/table/restrictToLanguage.html"
option_data["params"] = {"lang": updated_options[option]}
elif option == "open":
if updated_options["open"].lower() in {"1", "on", "true", "y", "yes"}:
option_data["path"] = "/table/table/openTableNow.html"
option_data["params"] = {}
elif updated_options["open"].lower() in {"0", "off", "false", "n", "no"}:
continue
else:
return f"Option `open` should have value `true` or `false`."
elif option.isdigit():
# If this is an HTML option, set it as such
option_data["path"] = "/table/table/changeoption.html"
Expand All @@ -283,6 +297,7 @@ async def parse_options(self, options, table_id):
return f"Option {option} not a valid option."

url_data.append(option_data)
url_data.extend(final_url_data)
return url_data

async def get_group_id(self, group_name):
Expand Down
2 changes: 2 additions & 0 deletions src/docs/bga_options_msg.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ The default is marked with a *
**lang**: ISO639-1 language code like en, es, fr, de. To find yours: en.wikipedia.org/wiki/List_of_ISO_639-1_codes
Default language is none

**open**: If `true`, the table will be immediately opened for joining. Defaults to `true` if and only if `restrictgroup` is set.

_You can also specify options/values like 200:12 if you know what they are by looking at the HTML._

0 comments on commit 6c66784

Please sign in to comment.