From 2d7bc2f34aa32aeafc333663259b18288ec378bc Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Mon, 7 Jun 2021 12:56:09 -0700 Subject: [PATCH] Check that required arguments are present (#1386) * Check that required arguments are present * Correct chat message documentation --- src/GamCommands.txt | 9 +++++---- src/gam/gapi/chat.py | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/GamCommands.txt b/src/GamCommands.txt index 3275d29a..036dfa7c 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -158,6 +158,7 @@ If an item contains spaces, it should be surrounded by ". ::= ::= | ::= + ::= ::= ::= | ::= || @@ -1168,11 +1169,11 @@ gam print browsertokens [todrive] [sortheaders] gam print chatspaces [todrive] -gam print chatmembers space [todrive] -gam create chat space [thread ] +gam print chatmembers space [todrive] +gam create chatmessage space [thread ] (text )|(textfile [charset ]) -gam delete chat name -gam update chat name +gam delete chatmessage name +gam update chatmessage name (text )|(textfile [charset ]) ::= diff --git a/src/gam/gapi/chat.py b/src/gam/gapi/chat.py index f3fc578a..7c474f2c 100644 --- a/src/gam/gapi/chat.py +++ b/src/gam/gapi/chat.py @@ -53,7 +53,7 @@ def print_spaces(): try: spaces = gapi.get_all_pages(chat.spaces(), 'list', 'spaces', throw_reasons=THROW_REASONS) except googleapiclient.errors.HttpError as err: - _chat_error_handler(chat, err) + _chat_error_handler(chat, err) if not spaces: print('Bot not added to any Chat rooms or users yet.') else: @@ -77,6 +77,9 @@ def print_members(): i += 1 else: controlflow.invalid_argument_exit(myarg, "gam print chatmembers") + if not space: + controlflow.system_error_exit(2, + 'space is required.') try: results = gapi.get_all_pages(chat.spaces().members(), 'list', 'memberships', parent=space) except googleapiclient.errors.HttpError as err: @@ -115,6 +118,12 @@ def create_message(): i += 2 else: controlflow.invalid_argument_exit(myarg, "gam create chat") + if not space: + controlflow.system_error_exit(2, + 'space is required.') + if 'text' not in body: + controlflow.system_error_exit(2, + 'text or textfile is required.') if len(body['text']) > 4096: body['text'] = body['text'][:4095] print('WARNING: trimmed message longer than 4k to be 4k in length.') @@ -143,6 +152,9 @@ def delete_message(): i += 2 else: controlflow.invalid_argument_exit(myarg, "gam delete chat") + if not name: + controlflow.system_error_exit(2, + 'name is required.') try: gapi.call(chat.spaces().messages(), 'delete', @@ -171,6 +183,12 @@ def update_message(): i += 2 else: controlflow.invalid_argument_exit(myarg, "gam update chat") + if not name: + controlflow.system_error_exit(2, + 'name is required.') + if 'text' not in body: + controlflow.system_error_exit(2, + 'text or textfile is required.') if len(body['text']) > 4096: body['text'] = body['text'][:4095] print('WARNING: trimmed message longer than 4k to be 4k in length.')