Exemplo n.º 1
0
def test_info_emoji() -> None:
    legal_cards = oracle.legal_cards()
    assert len(legal_cards) > 0
    legal_card = oracle.load_card('island')
    assert emoji.info_emoji(legal_card, no_rotation_hype=True) == ':white_check_mark:'
    illegal_card = oracle.load_card('black lotus')
    assert emoji.info_emoji(illegal_card, no_rotation_hype=True) == ':no_entry_sign:'
    assert emoji.info_emoji(illegal_card, verbose=True, no_rotation_hype=True) == ':no_entry_sign: (not legal in PD)'
Exemplo n.º 2
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)
    mana = mana.replace('|', ' // ')
    legal = ' — ' + emoji.info_emoji(requested_card, verbose=True)
    if disable_emoji:
        legal = ''
    if requested_card.get('mode', None) == '$':
        text = '{name} {legal} — {price}'.format(
            name=requested_card.name,
            price=card_price.card_price_string(requested_card),
            legal=legal)
    else:
        text = '{name} {mana} — {type}{legal}'.format(
            name=requested_card.name,
            mana=mana,
            type=requested_card.type_line,
            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']).total_seconds()
                text += ' (Last confirmed {time} ago.)'.format(
                    time=dtutil.display_time(time_since_confirmed, 1))
    return text
Exemplo n.º 3
0
async def post_cards(
        client: Client,
        cards: List[Card],
        channel: Messageable,
        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=((card_price.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)
Exemplo n.º 4
0
async def single_card_text(client: Client, channel: TextChannel, args: str, author: Member, f: Callable[[Card], str], command: str, show_legality: bool = True) -> None:
    c = await single_card_or_send_error(channel, args, author, command)
    if c is not None:
        name = c.name
        info_emoji = emoji.info_emoji(c, show_legality=show_legality)
        text = emoji.replace_emoji(f(c), client)
        message = f'**{name}** {info_emoji} {text}'
        await send(channel, message)
Exemplo n.º 5
0
 async def single_card_text(self,
                            c: Card,
                            f: Callable,
                            show_legality: bool = True) -> None:
     name = c.name
     info_emoji = emoji.info_emoji(c, show_legality=show_legality)
     text = emoji.replace_emoji(f(c), self.bot)
     message = f'**{name}** {info_emoji} {text}'
     await self.send(message)
Exemplo n.º 6
0
    async def single_card_text(self, c: Card, f: Callable, show_legality: bool = True) -> None:
        not_pd = configuration.get_list('not_pd')
        if str(self.channel.id) in not_pd or (getattr(self.channel, 'guild', None) is not None and str(self.channel.guild.id) in not_pd):
            show_legality = False

        name = c.name
        info_emoji = emoji.info_emoji(c, show_legality=show_legality)
        text = emoji.replace_emoji(f(c), self.bot)
        message = f'**{name}** {info_emoji} {text}'
        await self.send(message)
Exemplo n.º 7
0
def test_info_emoji() -> None:
    r = emoji.info_emoji(Container({'name': 'Island', 'bugs': []}), verbose=False, show_legality=True, no_rotation_hype=True)
    assert r == ':white_check_mark:'
    r = emoji.info_emoji(Container({'name': 'Black Lotus', 'bugs': []}), verbose=True, show_legality=True, no_rotation_hype=True)
    assert r == ':no_entry_sign: (not legal in PD)'
    r = emoji.info_emoji(Container({'name': 'Ice Cauldron', 'bugs': [{}, {}]}), verbose=False, show_legality=False, no_rotation_hype=True)
    assert r == ':beetle:'
    r = emoji.info_emoji(Container({'name': 'Mountain', 'bugs': []}), verbose=False, show_legality=False, no_rotation_hype=True)
    assert r == ''
    r = emoji.info_emoji(Container({'name': 'Plains', 'bugs': [{}]}), verbose=False, show_legality=True, no_rotation_hype=True)
    assert r == ':white_check_mark::beetle:'
    r = emoji.info_emoji(Container({'name': 'Force of Will', 'bugs': [{}]}), verbose=False, show_legality=True, no_rotation_hype=True)
    assert r == ':no_entry_sign::beetle:'