async def spellbook_addall(self, ctx, _class, level: int, spell_list=None): """Adds all spells of a given level from a given class list to the spellbook override. Requires live sheet. If `spell_list` is passed, will add these spells to the list named so in Dicecloud.""" character = await Character.from_ctx(ctx) if not character.live: return await self.bot.say( "This command requires a live Dicecloud sheet. To set up, share your Dicecloud " "sheet with `avrae` with edit permissions, then `!update`.") if not 0 <= level < 10: return await self.bot.say("Invalid spell level.") class_spells = [ sp for sp in c.spells if _class.lower() in [cl.lower() for cl in sp['classes'].split(', ') if not '(' in cl] ] if len(class_spells) == 0: return await self.bot.say("No spells for that class found.") level_spells = [s for s in class_spells if str(level) == s['level']] try: await DicecloudClient.getInstance().sync_add_mass_spells( character, [dicecloud_parse(s) for s in level_spells], spell_list) await character.commit(ctx) except MeteorClient.MeteorClientException: return await self.bot.say( "Error: Failed to connect to Dicecloud. The site may be down.") await self.bot.say( f"{len(level_spells)} spells added to {character.get_name()}'s spell list on Dicecloud." )
async def spellbook_add(self, ctx, *, spell_name): """Adds a spell to the spellbook override. If character is live, will add to sheet as well.""" result = searchSpell(spell_name) if result is None: return await self.bot.say('Spell not found.') strict = result[1] results = result[0] if strict: result = results else: if len(results) == 1: result = results[0] else: result = await get_selection(ctx, [(r, r) for r in results]) if result is None: return await self.bot.say( 'Selection timed out or was cancelled.') spell = getSpell(result) character = await Character.from_ctx(ctx) if character.live: try: await DicecloudClient.getInstance().sync_add_spell( character, dicecloud_parse(spell)) except MeteorClient.MeteorClientException: return await self.bot.say( "Error: Failed to connect to Dicecloud. The site may be down." ) character.add_known_spell(spell) await character.commit(ctx) live = "Spell added to Dicecloud!" if character.live else '' await self.bot.say( f"{spell['name']} added to known spell list!\n{live}")