From 6af86db03f09d859c8cd6aca044b11c31d5c4adc Mon Sep 17 00:00:00 2001 From: justin melvin Date: Fri, 27 Nov 2020 20:34:20 -0800 Subject: [PATCH] Rename sheets with 'SOLVED - ' prefix when /solved --- turbot/interaction.py | 3 +++ turbot/sheets.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/turbot/interaction.py b/turbot/interaction.py index ab35a39..5f8af02 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -444,6 +444,9 @@ def solved(turb, body, args): # And update the puzzle's description set_channel_topic(turb, puzzle) + # And rename the sheet to prefix with SOLVED - + turb.sheets.renameSheet(turb, puzzle['sheet_url'], 'SOLVED - ' + puzzle['name']) + return lambda_ok commands["/solved"] = solved diff --git a/turbot/sheets.py b/turbot/sheets.py index 047f793..622e8c8 100644 --- a/turbot/sheets.py +++ b/turbot/sheets.py @@ -78,3 +78,21 @@ def sheets_create_for_puzzle(turb, puzzle): }).execute() return new_sheet + +def renameSheet(turb, url, newName): + id = extractIdFromSheetUrl(url) + turb.sheets.batchUpdate(id, + body={ + "updateSheetProperties": { + "properties": { + "sheetId": id, + "title": newName + } + }}).execute() + +def extractIdFromSheetUrl(url): + # Google sheet ids are between the /d/ and /edit in the url, like https://docs.google.com/spreadsheets/d/1dxHBzjenjhCAJQ8lM0skJO2mxlup8aWZm0-LaXeVPrg/edit#gid=0 + startIndex = url.find('/d/') + 3 + endIndex = url.find('/edit') + return url[startIndex : endIndex] + \ No newline at end of file -- 2.43.0