From 3401f5046bd5b4a44562b55b1017d6cf0e1e200d Mon Sep 17 00:00:00 2001 From: Maximilian Jonas Haye Date: Sat, 27 Jan 2018 01:31:32 +0100 Subject: [PATCH 1/3] Modify !reopen to not reindex the whole board --- sopel_modules/rat_board.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sopel_modules/rat_board.py b/sopel_modules/rat_board.py index 6ec2e77..847c7ab 100644 --- a/sopel_modules/rat_board.py +++ b/sopel_modules/rat_board.py @@ -1648,9 +1648,14 @@ def cmd_reopen(bot, trigger, id): """ try: result = callapi(bot, 'PUT', data={'status': 'open'}, uri='/rescues/' + str(id), triggernick=str(trigger.nick)) - refresh_cases(bot, force=True) - updateBoardIndexes(bot) - bot.say('Reopened case. Cases refreshed, care for your case numbers!') + rescue = Rescue.load(result['data'][0]) + bot.memory['ratbot']['board'].add(rescue) + + with rescue.change(): + rescue.data.update({"boardIndex": rescue.boardindex}) + + save_case_later(bot, rescue, forceFull=True) + bot.say('Reopened case {case.client_name}. It is now #{case.boardIndex}.'.format(case=rescue)) except ratlib.api.http.APIError: # print('[RatBoard] apierror.') bot.reply('id ' + str(id) + ' does not exist or other API Error.') From 111cb9d71f3e4b9c653ba40ca3c72b652582c5c7 Mon Sep 17 00:00:00 2001 From: Maximilian Jonas Haye Date: Sat, 27 Jan 2018 17:12:15 +0100 Subject: [PATCH 2/3] Update saved rats while were at it and convert data to v1 before making a rescue from it --- sopel_modules/rat_board.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sopel_modules/rat_board.py b/sopel_modules/rat_board.py index 847c7ab..e9beff7 100644 --- a/sopel_modules/rat_board.py +++ b/sopel_modules/rat_board.py @@ -1648,7 +1648,12 @@ def cmd_reopen(bot, trigger, id): """ try: result = callapi(bot, 'PUT', data={'status': 'open'}, uri='/rescues/' + str(id), triggernick=str(trigger.nick)) - rescue = Rescue.load(result['data'][0]) + try: + addNamesFromV2Response(result['included']) + except: + pass + + rescue = Rescue.load(convertV2DataToV1(result['data'])[0]) bot.memory['ratbot']['board'].add(rescue) with rescue.change(): From 3487f3fdcf8706220e14d8dffa1d91efc2466978 Mon Sep 17 00:00:00 2001 From: MHajoha Date: Thu, 1 Feb 2018 11:28:49 +0100 Subject: [PATCH 3/3] Pluck out broad except clause and give addNamesFromV2Response a docstring --- ratlib/api/names.py | 5 +++++ sopel_modules/rat_board.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ratlib/api/names.py b/ratlib/api/names.py index a08d033..c62174a 100644 --- a/ratlib/api/names.py +++ b/ratlib/api/names.py @@ -289,6 +289,11 @@ def getPrivLevel(trigger): return -1 def addNamesFromV2Response(ratdata): + """ + Update our cached rats with new info from the API + :param ratdata: Should usually be `result['included']` of an API call + :raise: KeyError if `ratdata` is faulty + """ for rat in ratdata: if rat['type'] != "rats": continue diff --git a/sopel_modules/rat_board.py b/sopel_modules/rat_board.py index e9beff7..7d3c2dc 100644 --- a/sopel_modules/rat_board.py +++ b/sopel_modules/rat_board.py @@ -1650,10 +1650,10 @@ def cmd_reopen(bot, trigger, id): result = callapi(bot, 'PUT', data={'status': 'open'}, uri='/rescues/' + str(id), triggernick=str(trigger.nick)) try: addNamesFromV2Response(result['included']) - except: + except KeyError: pass - rescue = Rescue.load(convertV2DataToV1(result['data'])[0]) + rescue = Rescue.load(convertV2DataToV1(result['data'][0], single=True)) bot.memory['ratbot']['board'].add(rescue) with rescue.change():