async def get_item_choices(ctx, filter_by_license=True, homebrew=True): """ Gets a list of items in the current context for the user to choose from. :param ctx: The context. :param filter_by_license: Whether to filter out entities the user cannot access. :param homebrew: Whether to include homebrew entities. """ if filter_by_license: available_items = await available(ctx, compendium.items, 'magic-item') else: available_items = compendium.items if not homebrew: return available_items # personal pack try: pack = await Pack.from_ctx(ctx) custom_items = pack.items pack_id = pack.id except NoActiveBrew: custom_items = [] pack_id = None # server packs choices = list(itertools.chain(available_items, custom_items)) if ctx.guild: async for servpack in Pack.server_active(ctx): if servpack.id != pack_id: choices.extend(servpack.items) return choices
async def pack_server_list(self, ctx): """Shows what packs are currently active on the server.""" desc = "" async for pack in Pack.server_active(ctx, meta_only=True): desc += f"{pack['name']} (<@{pack['owner']}>)\n" await ctx.send( embed=discord.Embed(title="Active Server Packs", description=desc))
async def pack_server_remove(self, ctx, pack_name): """Removes a server pack.""" pack_metas = [p async for p in Pack.server_active(ctx, meta_only=True)] pack_meta = await search_and_select(ctx, pack_metas, pack_name, lambda b: b['name']) pack = await Pack.from_id(ctx, pack_meta['_id']) await pack.toggle_server_active(ctx) await ctx.send(f"Ok, {pack.name} is no longer active on {ctx.guild.name}.")
async def item_lookup(self, ctx, *, name): """Looks up an item.""" try: pack = await Pack.from_ctx(ctx) custom_items = pack.get_search_formatted_items() pack_id = pack.id except NoActiveBrew: custom_items = [] pack_id = None choices = list(itertools.chain(compendium.items, custom_items)) if ctx.guild: async for servpack in Pack.server_active(ctx): if servpack.id != pack_id: choices.extend(servpack.get_search_formatted_items()) # #881 - display nSRD names choices.extend(compendium.nitem_names) result, metadata = await search_and_select(ctx, choices, name, lambda e: e['name'], selectkey=self.nsrd_selectkey, return_metadata=True) metadata['homebrew'] = result.get('source') == 'homebrew' await self.add_training_data("item", name, result['name'], metadata=metadata, srd=result['srd']) if not (metadata['homebrew'] or result['srd']): return await self._non_srd(ctx, result, "item") embed = EmbedWithAuthor(ctx) item = result name = item['name'] proptext = "" if not item.get('source') == 'homebrew': damage = '' extras = '' properties = [] if 'type' in item: type_ = ', '.join( i for i in ([ITEM_TYPES.get(t, 'n/a') for t in item['type'].split(',')] + ["Wondrous Item" if item.get('wondrous') else '']) if i) for iType in item['type'].split(','): if iType in ('M', 'R', 'GUN'): damage = f"{item.get('dmg1', 'n/a')} {DMGTYPES.get(item.get('dmgType'), 'n/a')}" \ if 'dmg1' in item and 'dmgType' in item else '' type_ += f', {item.get("weaponCategory")}' if iType == 'S': damage = f"AC +{item.get('ac', 'n/a')}" if iType == 'LA': damage = f"AC {item.get('ac', 'n/a')} + DEX" if iType == 'MA': damage = f"AC {item.get('ac', 'n/a')} + DEX (Max 2)" if iType == 'HA': damage = f"AC {item.get('ac', 'n/a')}" if iType == 'SHP': # ships for p in ("CREW", "PASS", "CARGO", "DMGT", "SHPREP"): a = PROPS.get(p, 'n/a') proptext += f"**{a.title()}**: {compendium.itemprops[p]}\n" extras = f"Speed: {item.get('speed')}\nCarrying Capacity: {item.get('carryingcapacity')}\n" \ f"Crew {item.get('crew')}, AC {item.get('vehAc')}, HP {item.get('vehHp')}" if 'vehDmgThresh' in item: extras += f", Damage Threshold {item['vehDmgThresh']}" if iType == 'siege weapon': extras = f"Size: {SIZES.get(item.get('size'), 'Unknown')}\n" \ f"AC {item.get('ac')}, HP {item.get('hp')}\n" \ f"Immunities: {item.get('immune')}" else: type_ = ', '.join( i for i in ("Wondrous Item" if item.get('wondrous') else '', item.get('technology')) if i) rarity = str(item.get('rarity')).replace('None', '') if 'tier' in item: if rarity: rarity += f', {item["tier"]}' else: rarity = item['tier'] type_and_rarity = type_ + (f", {rarity}" if rarity else '') value = (item.get('value', 'n/a') + (', ' if 'weight' in item else '')) if 'value' in item else '' weight = (item.get('weight', 'n/a') + (' lb.' if item.get('weight') == '1' else ' lbs.')) \ if 'weight' in item else '' weight_and_value = value + weight for prop in item.get('property', []): if not prop: continue a = b = prop a = PROPS.get(a, 'n/a') if b in compendium.itemprops: proptext += f"**{a.title()}**: {compendium.itemprops[b]}\n" if b == 'V': a += " (" + item.get('dmg2', 'n/a') + ")" if b in ('T', 'A'): a += " (" + item.get('range', 'n/a') + "ft.)" if b == 'RLD': a += " (" + item.get('reload', 'n/a') + " shots)" properties.append(a) properties = ', '.join(properties) damage_and_properties = f"{damage} - {properties}" if properties else damage damage_and_properties = (' --- ' + damage_and_properties) if weight_and_value and damage_and_properties else \ damage_and_properties meta = f"*{type_and_rarity}*\n{weight_and_value}{damage_and_properties}\n{extras}" text = item['desc'] if 'reqAttune' in item: if item['reqAttune'] is True: # can be truthy, but not true embed.add_field(name="Attunement", value=f"Requires Attunement") else: embed.add_field(name="Attunement", value=f"Requires Attunement {item['reqAttune']}", inline=False) embed.set_footer(text=f"Item | {item.get('source', 'Unknown')} {item.get('page', 'Unknown')}") else: meta = item['meta'] text = item['desc'] if 'image' in item: embed.set_thumbnail(url=item['image']) add_homebrew_footer(embed) embed.title = name embed.description = meta # no need to render, has been prerendered if proptext: text = f"{text}\n{proptext}" if len(text) > 5500: text = text[:5500] + "..." add_fields_from_long_text(embed, "Description", text) await Stats.increase_stat(ctx, "items_looked_up_life") await (await self._get_destination(ctx)).send(embed=embed)