Пример #1
0
def single_card_text_internal(client: Client, requested_card: Card,
                              disable_emoji: bool) -> str:
    mana = emoji.replace_emoji(''.join(requested_card.mana_cost or []), client)
    legal = ' — ' + emoji.legal_emoji(requested_card, True)
    if disable_emoji:
        legal = ''
    if requested_card.get('mode', None) == '$':
        text = '{name} {legal} — {price}'.format(
            name=requested_card.name,
            price=fetcher.card_price_string(requested_card),
            legal=legal)
    else:
        text = '{name} {mana} — {type}{legal}'.format(name=requested_card.name,
                                                      mana=mana,
                                                      type=requested_card.type,
                                                      legal=legal)
    if requested_card.bugs:
        for bug in requested_card.bugs:
            text += '\n:beetle:{rank} bug: {bug}'.format(
                bug=bug['description'], rank=bug['classification'])
            if bug['last_confirmed'] < (dtutil.now() -
                                        datetime.timedelta(days=60)):
                time_since_confirmed = (dtutil.now() -
                                        bug['last_confirmed']).seconds
                text += ' (Last confirmed {time} ago.)'.format(
                    time=dtutil.display_time(time_since_confirmed, 1))
    return text
Пример #2
0
async def post_cards(client: Client,
                     cards: List[Card],
                     channel: TextChannel,
                     replying_to: Optional[Member] = None,
                     additional_text: str = '') -> None:
    if len(cards) == 0:
        await post_no_cards(channel, replying_to)
        return
    not_pd = configuration.get_list('not_pd')
    disable_emoji = str(
        channel.id) in not_pd or (getattr(channel, 'guild', None) is not None
                                  and str(channel.guild.id) in not_pd)
    cards = uniqify_cards(cards)
    if len(cards) > MAX_CARDS_SHOWN:
        cards = cards[:DEFAULT_CARDS_SHOWN]
    if len(cards) == 1:
        text = single_card_text_internal(client, cards[0], disable_emoji)
    else:
        text = ', '.join('{name} {legal} {price}'.format(
            name=card.name,
            legal=((emoji.info_emoji(card)) if not disable_emoji else ''),
            price=((fetcher.card_price_string(card, True)
                    ) if card.get('mode', None) == '$' else ''))
                         for card in cards)
    if len(cards) > MAX_CARDS_SHOWN:
        image_file = None
    else:
        with channel.typing():
            image_file = await image_fetcher.download_image_async(cards)
    if image_file is None:
        text += '\n\n'
        if len(cards) == 1:
            text += emoji.replace_emoji(cards[0].oracle_text, client)
        else:
            text += 'No image available.'
    text += additional_text
    if image_file is None:
        await send(channel, text)
    else:
        await send_image_with_retry(channel, image_file, text)
Пример #3
0
async def post_cards(client: Client,
                     cards: List[Card],
                     channel: Channel,
                     replying_to: Optional[Member] = None,
                     additional_text: str = '') -> None:
    await client.send_typing(channel)
    if len(cards) == 0:
        await post_no_cards(client, channel, replying_to)
        return
    disable_emoji = channel.id in configuration.get_str('not_pd').split(',')
    cards = uniqify_cards(cards)
    if len(cards) > MAX_CARDS_SHOWN:
        cards = cards[:DEFAULT_CARDS_SHOWN]
    if len(cards) == 1:
        text = single_card_text_internal(client, cards[0], disable_emoji)
    else:
        text = ', '.join('{name} {legal} {price}'.format(
            name=card.name,
            legal=((emoji.legal_emoji(card)) if not disable_emoji else ''),
            price=((fetcher.card_price_string(card, True)
                    ) if card.get('mode', None) == '$' else ''))
                         for card in cards)
    if len(cards) > MAX_CARDS_SHOWN:
        image_file = None
    else:
        image_file = image_fetcher.download_image(cards)
    if image_file is None:
        text += '\n\n'
        if len(cards) == 1:
            text += emoji.replace_emoji(cards[0].text, client)
        else:
            text += 'No image available.'
    text += additional_text
    if image_file is None:
        await client.send_message(channel, text)
    else:
        await send_image_with_retry(client, channel, image_file, text)