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 6ec2e77..7d3c2dc 100644 --- a/sopel_modules/rat_board.py +++ b/sopel_modules/rat_board.py @@ -1648,9 +1648,19 @@ 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!') + try: + addNamesFromV2Response(result['included']) + except KeyError: + pass + + rescue = Rescue.load(convertV2DataToV1(result['data'][0], single=True)) + 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.')