]> git.cworth.org Git - turbot/commitdiff
Rename sheets with 'SOLVED - ' prefix when /solved
authorjustin melvin <jmelvinprime@gmail.com>
Sat, 28 Nov 2020 04:34:20 +0000 (20:34 -0800)
committerjustin melvin <jmelvinprime@gmail.com>
Sat, 28 Nov 2020 04:34:20 +0000 (20:34 -0800)
turbot/interaction.py
turbot/sheets.py

index ab35a395bbdc6fe1020b3d84611865a6bf6db69b..5f8af0267ca07e6ac103132748c7682682d88188 100644 (file)
@@ -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
index 047f793b0c22c805615b215a5f803d81dec56e65..622e8c8793424215f3b976f87fc3953f8887b608 100644 (file)
@@ -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