def make_recipe(recipe: Recipe): return [ make_section('*Recipe: {}*'.format( URL_FORMAT.format('recipe', recipe.recipe_id))), DIVIDER, make_section(f'*_Label:_* {recipe.label}\n' f'*_Start Description:_* {recipe.start_description}\n' f'*_Description:_* {recipe.description}') ]
def make_legacy(legacy: Legacy): image = get_image_if_reachable(get_legacy_art(legacy)) image_alt = None if image is not None: image_alt = legacy.legacy_id return [ make_section('*Legacy: {}*'.format( URL_FORMAT.format('legacy', legacy.legacy_id))), DIVIDER, make_section( f'*_Label:_* {legacy.label}\n' f'*_Description:_* {legacy.description}\n' f'*_Start Description:_* {legacy.start_description}', image, image_alt) ]
def make_ending(ending: Ending): image = get_image_if_reachable(get_ending_art(ending)) image_alt = None if image is not None: image_alt = ending.ending_id return [ make_section('*ending: {}*'.format(URL_FORMAT.format('ending', ending.ending_id))), DIVIDER, make_section( f'*_Title:_* {ending.title}\n' f'*_Description:_* {ending.description}', image, image_alt ) ]
def make_deck(deck: Deck): draw_messages = '\n'.join( f'• <https://www.frangiclave.net/element/{dm.element.element_id}/|{dm.element.element_id}>: {dm.message}' for dm in deck.draw_messages) cards = '\n'.join( f'• <https://www.frangiclave.net/element/{card.element_id}/|{card.element_id}>' for card in deck.cards) default_card = f'<https://www.frangiclave.net/element/{deck.default_card.element_id}/|{deck.default_card.element_id}>' if deck.default_card else 'None' return [ make_section('*Deck: {}*'.format( URL_FORMAT.format('deck', deck.deck_id))), DIVIDER, make_section(f'*_Label:_* {deck.label}\n' f'*_Description:_* {deck.description}\n' f'*_Draw Messages:_* \n{draw_messages}\n') ]
def make_verb(verb: Verb): image = get_image_if_reachable(get_verb_art(verb)) image_alt = None if image is not None: image_alt = verb.verb_id return [ make_section('*verb: {}*'.format(URL_FORMAT.format('verb', verb.verb_id))), DIVIDER, make_section( f'*_Label:_* {verb.label}\n' f'*_Description:_* {verb.description}', image, image_alt ) ]
def make_element(element: Element): image = get_image_if_reachable(get_element_art(element)) image_alt = None if image is not None: image_alt = element.element_id decay_to = None if element.decay_to: decay_to = URL_FORMAT.format('element', element.decay_to.element_id) return [ make_section('*Element: {}*'.format( URL_FORMAT.format('element', element.element_id))), DIVIDER, make_section( f'*_Label:_* {element.label}\n' f'*_Description:_* {element.description}', image, image_alt) ]
def _make_result(result: Dict[str, Any]): text = "*{}: {}*\n{}".format( result['type'].capitalize(), URL_FORMAT.format(result['type'], result['id']), '\n'.join('• ' + m for m in result['matches']) ) image = None image_alt = None with get_session() as session: if result['type'] == 'element': element = Element.get_by_element_id(session, result['id']) image = get_element_art(element) elif result['type'] == 'legacy': legacy = Legacy.get_by_legacy_id(session, result['id']) image = get_legacy_art(legacy) elif result['type'] == 'verb': verb = Verb.get_by_verb_id(session, result['id']) image = get_verb_art(verb) elif result['type'] == 'ending': ending = Ending.get_by_ending_id(session, result['id']) image = get_ending_art(ending) image = get_image_if_reachable(image) if image is not None: image_alt = result['id'] return make_section(text, image, image_alt)
def _make_header(num_results: int, keywords: str): text = 'Found *{} results* for *{}*.'.format(num_results, keywords) if num_results > MAX_RESULTS: text += ' Only showing first {} results.'.format(MAX_RESULTS) return make_section(text)