async def gsheet(self, ctx, url: str): """Loads a character sheet from [GSheet v2.0](http://gsheet2.avrae.io) (auto) or [GSheet v1.3](http://gsheet.avrae.io) (manual), resetting all settings. The sheet must be shared with Avrae for this to work. Avrae's google account is `[email protected]`.""" loading = await ctx.send('Loading character data from Google... (This usually takes ~30 sec)') try: url = extract_gsheet_id_from_url(url) except NoValidUrlKeyFound: return await loading.edit(content="This is not a Google Sheets link.") override = await self._confirm_overwrite(ctx, f"google-{url}") if not override: return await ctx.send("Character overwrite unconfirmed. Aborting.") try: parser = GoogleSheet(url, self.gsheet_client) except AssertionError: await self.init_gsheet_client() # hmm. return await loading.edit(content="I am still connecting to Google. Try again in 15-30 seconds.") try: await parser.get_character() except (KeyError, SpreadsheetNotFound): return await loading.edit(content= "Invalid character sheet. Make sure you've shared it with me at " "`[email protected]`!") except HttpError: return await loading.edit(content= "Error: Google returned an error. Please ensure your sheet is shared with " "`[email protected]` and try again in a few minutes.") except Exception as e: return await loading.edit(content='Error: Could not load character sheet.\n' + str(e)) try: sheet = await parser.get_sheet() except Exception as e: traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr) return await loading.edit(content='Error: Invalid character sheet.\n' + str(e)) try: await loading.edit(content= 'Loaded and saved data for {}!'.format(sheet['sheet']['stats']['name'])) except TypeError as e: traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr) return await loading.edit(content= 'Invalid character sheet. Make sure you have shared the sheet so that anyone with the link can view.') char = Character(sheet['sheet'], f"google-{url}").initialize_consumables() await char.commit(ctx) await char.set_active(ctx) try: await ctx.send(embed=char.get_sheet_embed()) except: await ctx.send( "...something went wrong generating your character sheet. Don't worry, your character has been saved. " "This is usually due to an invalid image.")
async def gsheet(self, ctx, url: str, *args): """Loads a character sheet from [GSheet v2.0](http://gsheet2.avrae.io) (auto) or [GSheet v1.4](http://gsheet.avrae.io) (manual), resetting all settings. The sheet must be shared with Avrae for this to work. Avrae's google account is `[email protected]`.""" loading = await ctx.send('Loading character data from Google... (This usually takes ~30 sec)') try: url = extract_gsheet_id_from_url(url) except ExternalImportError: return await loading.edit(content="This is not a Google Sheets link.") override = await self._confirm_overwrite(ctx, f"google-{url}") if not override: return await ctx.send("Character overwrite unconfirmed. Aborting.") parser = GoogleSheet(url) await self._load_sheet(ctx, parser, args, loading)