From cdcdfb899890ea214633163a8c8e8ad1f5faa47d Mon Sep 17 00:00:00 2001 From: Dan Langford <721364+danlangford@users.noreply.github.com> Date: Fri, 19 May 2023 21:55:48 -0600 Subject: [PATCH 1/5] buttonmen-dev/buttonmen#2668 search_game_history, edit_forum_post, load_forum_thread, load_button_data --- tools/api-client/python/lib/bmapi.py | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tools/api-client/python/lib/bmapi.py b/tools/api-client/python/lib/bmapi.py index f9b57f985..fa4008672 100644 --- a/tools/api-client/python/lib/bmapi.py +++ b/tools/api-client/python/lib/bmapi.py @@ -163,6 +163,28 @@ def load_game_data(self, gameId, logEntryLimit=10): } return self._make_request(args) + def load_button_data(self, button): + args = { + 'type': 'loadButtonData', + 'buttonName': button, + } + return self._make_request(args) + + def load_forum_thread(self, thread): + args = { + 'type': 'loadForumThread', + 'threadId': thread, + } + return self._make_request(args) + + def edit_forum_post(self, postId, body): + args = { + 'type': 'editForumPost', + 'postId': postId, + 'body': body, + } + return self._make_request(args) + def create_game(self, pbutton, obutton='', player='', opponent='', description='', max_wins=3, use_prev_game=False, custom_recipe_array=None): if player is None or player == '': player = self.username @@ -267,3 +289,39 @@ def choose_auxiliary_dice(self, gameId, action, dieIdx=None): if dieIdx is not None: args['dieIdx'] = dieIdx return self._make_request(args) + + def search_game_history(self, sortColumn, sortDirection="DESC", + numberOfResults=20, page=1, status=None, playerNameA=None, playerNameB=None, + buttonNameA=None, buttonNameB=None, gameStartMin=None, gameStartMax=None, + lastMoveMin=None, lastMoveMax=None): + """ + {"status":"COMPLETE","sortColumn":"lastMove","sortDirection":"ASC","numberOfResults":"100","page":"1","type":"searchGameHistory","automatedApiCall":false}: + {"playerNameA":"glassonion","buttonNameA":"Bunnies","buttonNameB":"McGinty","playerNameB":"Jota","gameStartMin":1546326000,"gameStartMax":1577775600,"status":"COMPLETE","sortColumn":"lastMove","sortDirection":"ASC","numberOfResults":"100","page":"1","type":"searchGameHistory","automatedApiCall":false}: + """ + args = { + 'type': 'searchGameHistory', + 'sortColumn': sortColumn, + 'sortDirection': sortDirection, + 'numberOfResults': numberOfResults, + 'page': page + } + if status is not None: + args['status'] = status + if playerNameA is not None: + args['playerNameA'] = playerNameA + if playerNameB is not None: + args['playerNameB'] = playerNameB + if buttonNameA is not None: + args['buttonNameA'] = buttonNameA + if buttonNameB is not None: + args['buttonNameB'] = buttonNameB + if gameStartMin is not None: + args['gameStartMin'] = gameStartMin + if gameStartMax is not None: + args['gameStartMax'] = gameStartMax + if lastMoveMin is not None: + args['lastMoveMin'] = lastMoveMin + if lastMoveMax is not None: + args['lastMoveMax'] = lastMoveMax + + return self._make_request(args) From de2606524c1017d3ad4071c0ac5629deefb5cba1 Mon Sep 17 00:00:00 2001 From: Dan Langford <721364+danlangford@users.noreply.github.com> Date: Fri, 19 May 2023 22:06:38 -0600 Subject: [PATCH 2/5] buttonmen-dev/buttonmen#2668 wrap_load_forum_thread wrap_edit_forum_post wrap_search_game_historywrap_load_button_data --- tools/api-client/python/lib/bmutils.py | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tools/api-client/python/lib/bmutils.py b/tools/api-client/python/lib/bmutils.py index 43cc3b4ab..558895c80 100644 --- a/tools/api-client/python/lib/bmutils.py +++ b/tools/api-client/python/lib/bmutils.py @@ -120,12 +120,44 @@ def wrap_react_to_new_game(self, game, accept): raise ValueError("Failed to call reactToNewGame, got: " + retval.message) return retval.data + def wrap_load_forum_thread(self, thread): + retval = self.client.load_forum_thread(thread) + if not retval.status == 'ok': + raise ValueError("Failed to call loadForumThread, got: " + retval.message) + data = retval.data + + return data + + def wrap_edit_forum_post(self, postId, body): + retval = self.client.edit_forum_post(postId, body) + if not retval.status == 'ok': + raise ValueError("Failed to call editForumThread, got: " + retval.message) + data = retval.data + + return data + def wrap_load_completed_games(self): retval = self.client.load_completed_games() if not retval.status == 'ok': raise ValueError("Failed to call loadCompletedGames, got: " + retval.message) return self._wrap_game_list_data(retval.data) + def wrap_search_game_history(self, sortColumn, searchDirection="DESC", + numberOfResults=20, page=1, status=None, playerNameA=None, playerNameB=None, + buttonNameA=None, buttonNameB=None, gameStartMin=None, gameStartMax=None, + lastMoveMin=None, lastMoveMax=None): + retval = self.client.search_game_history( + sortColumn=sortColumn, sortDirection=searchDirection, + numberOfResults=numberOfResults, page=page, status=status, + playerNameA=playerNameA, playerNameB=playerNameB, + buttonNameA=buttonNameA, buttonNameB=buttonNameB, + gameStartMin=gameStartMin, gameStartMax=gameStartMax, + lastMoveMin=lastMoveMin, lastMoveMax=lastMoveMax + ) + if not retval.status == 'ok': + raise ValueError("Failed to call searchGameHistory, got: " + retval.message) + return retval.data + def wrap_create_game(self, pbutton, obutton='', player='', opponent='', description=''): retval = self.client.create_game(pbutton, obutton, player, opponent, description) if not retval.status == 'ok': @@ -172,3 +204,38 @@ def wrap_load_game_data(self, game): data['player'] = data['playerDataArray'][playerIdx] data['opponent'] = data['playerDataArray'][opponentIdx] return data + + def wrap_load_button_data(self, button): + # if we're using a cache directory + if self.cachedir: + # if the cache directory doesn't exist, create it + if not os.path.isdir(self.cachedir): + os.makedirs(self.cachedir) + # set the path to the cache file for this game + cachefile = self.cachedir + "/{}.json".format(urlsafe_b64encode(button.encode('utf-8')).decode('utf-8')) + # if the cache already has a file for this game + if os.path.isfile(cachefile): + # get the game data from the cache + with open(cachefile) as cache_fh: + data = json.load(cache_fh) + # otherwise (the cache didn't already have a file for this game) + else: + # load the game + retval = self.client.load_button_data(button) + # if that didn't work, raise an exception + if not retval.status == 'ok': + raise ValueError("Failed to call loadButtonData, got: " + retval.message) + # if we're still here, we have the game data + data = retval.data[0] + # put the data for this game into the cache + with open(cachefile, 'w') as cache_fh: + json.dump(data, cache_fh, indent=1, sort_keys=True) + # otherwise (we aren't using a cache directory), load the game + else: + retval = self.client.load_button_data(button) + if not retval.status == 'ok': + raise ValueError("Failed to call loadButtonData, got: " + retval.message) + data = retval.data[0] + # either way, at this point we have the button data in 'data', + # and we're done doing anything cache-related + return data From e100d123e1f28e064dc0f7d63064821f29ef71c6 Mon Sep 17 00:00:00 2001 From: Dan Langford <721364+danlangford@users.noreply.github.com> Date: Fri, 19 May 2023 22:13:34 -0600 Subject: [PATCH 3/5] buttonmen-dev/buttonmen#2668 submit_chat --- tools/api-client/python/lib/bmapi.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/api-client/python/lib/bmapi.py b/tools/api-client/python/lib/bmapi.py index fa4008672..fba664a8a 100644 --- a/tools/api-client/python/lib/bmapi.py +++ b/tools/api-client/python/lib/bmapi.py @@ -238,6 +238,14 @@ def submit_die_values(self, gameId, swingArray, optionArray, roundNumber, timest args['optionValueArray'] = optionArray return self._make_request(args) + def submit_chat(self, gameId, chat): + args = { + 'type': 'submitChat', + 'gameId': gameId, + 'chat': chat, + } + return self._make_request(args) + def react_to_new_game(self, gameId, action): args = { 'type': 'reactToNewGame', From 13fef2689847646773acbfb2712440a49d1ea890 Mon Sep 17 00:00:00 2001 From: Dan Langford <721364+danlangford@users.noreply.github.com> Date: Fri, 19 May 2023 22:47:48 -0600 Subject: [PATCH 4/5] buttonmen-dev/buttonmen#2668 wrap_submit_chat --- tools/api-client/python/lib/bmutils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/api-client/python/lib/bmutils.py b/tools/api-client/python/lib/bmutils.py index 558895c80..47ffd6175 100644 --- a/tools/api-client/python/lib/bmutils.py +++ b/tools/api-client/python/lib/bmutils.py @@ -124,17 +124,19 @@ def wrap_load_forum_thread(self, thread): retval = self.client.load_forum_thread(thread) if not retval.status == 'ok': raise ValueError("Failed to call loadForumThread, got: " + retval.message) - data = retval.data - - return data + return retval.data def wrap_edit_forum_post(self, postId, body): retval = self.client.edit_forum_post(postId, body) if not retval.status == 'ok': raise ValueError("Failed to call editForumThread, got: " + retval.message) - data = retval.data + return retval.data - return data + def wrap_submit_chat(self, game, chat): + retval = self.client.submit_chat(game, chat) + if not retval.status == 'ok': + raise ValueError("Failed to call submitChat, got: " + retval.message) + return retval.data def wrap_load_completed_games(self): retval = self.client.load_completed_games() From a1fa52ade63767bdf3f8bb04ea3283b82b1a73aa Mon Sep 17 00:00:00 2001 From: Dan Langford <721364+danlangford@users.noreply.github.com> Date: Fri, 19 May 2023 23:11:23 -0600 Subject: [PATCH 5/5] fixed type in submit_chat call --- tools/api-client/python/lib/bmapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/api-client/python/lib/bmapi.py b/tools/api-client/python/lib/bmapi.py index fba664a8a..17c671f1d 100644 --- a/tools/api-client/python/lib/bmapi.py +++ b/tools/api-client/python/lib/bmapi.py @@ -238,10 +238,10 @@ def submit_die_values(self, gameId, swingArray, optionArray, roundNumber, timest args['optionValueArray'] = optionArray return self._make_request(args) - def submit_chat(self, gameId, chat): + def submit_chat(self, game, chat): args = { 'type': 'submitChat', - 'gameId': gameId, + 'game': game, 'chat': chat, } return self._make_request(args)