async def post_cards(self, cards, channel, replying_to=None, additional_text=''): await self.client.send_typing(channel) not_pd = configuration.get('not_pd').split(',') disable_emoji = False if channel.id in not_pd: # or (channel.server and channel.server.id in not_pd): disable_emoji = True if len(cards) == 0: if replying_to is not None: text = '{author}: No matches.'.format(author=replying_to.mention) else: text = 'No matches.' await self.client.send_message(channel, text) return cards = command.uniqify_cards(cards) more_text = '' if len(cards) > 10: more_text = ' and ' + str(len(cards) - 4) + ' more.' cards = cards[:4] if len(cards) == 1: card = cards[0] mana = emoji.replace_emoji(''.join(card.mana_cost or []), self.client) legal = ' — ' + emoji.legal_emoji(card, True) if disable_emoji: legal = '' text = '{name} {mana} — {type}{legal}'.format(name=card.name, mana=mana, type=card.type, legal=legal) if card.bug_desc is not None: text += '\n:beetle:{rank} bug: {bug}'.format(bug=card.bug_desc, rank=card.bug_class) now_ts = dtutil.dt2ts(dtutil.now()) if card.bug_last_confirmed < now_ts - 60 * 60 * 24 * 60: text += ' (Last confirmed {time} ago.)'.format(time=dtutil.display_time(now_ts - card.bug_last_confirmed, 1)) else: text = ', '.join('{name} {legal}'.format(name=card.name, legal=(emoji.legal_emoji(card)) if not disable_emoji else '') for card in cards) text += more_text if len(cards) > 10: 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, self.client) else: text += 'No image available.' text += '\n' + additional_text if image_file is None: await self.client.send_message(channel, text) else: message = await self.client.send_file(channel, image_file, content=text) if message and message.attachments and message.attachments[0]['size'] == 0: print('Message size is zero so resending') await self.client.delete_message(message) await self.client.send_file(channel, image_file, content=text)
async def spoiler(self, client: Client, channel: Channel, args: str, author: Member, **_: Dict[str, Any]) -> None: """`!spoiler {cardname}`: Request a card from an upcoming set.""" if len(args) == 0: return await client.send_message( channel, '{author}: Please specify a card name.'.format( author=author.mention)) sfcard = fetcher.internal.fetch_json( 'https://api.scryfall.com/cards/named?fuzzy={name}'.format( name=args)) if sfcard['object'] == 'error': return await client.send_message( channel, '{author}: {details}'.format(author=author.mention, details=sfcard['details'])) imagename = '{set}_{number}'.format(set=sfcard['set'], number=sfcard['collector_number']) imagepath = '{image_dir}/{imagename}.jpg'.format( image_dir=configuration.get('image_dir'), imagename=imagename) if sfcard.get('card_faces'): c = sfcard['card_faces'][0] else: c = sfcard fetcher.internal.store(c['image_uris']['normal'], imagepath) text = emoji.replace_emoji( '{name} {mana}'.format(name=sfcard['name'], mana=c['mana_cost']), client) await client.send_file(channel, imagepath, content=text) oracle.scryfall_import(sfcard['name'])
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
async def single_card_text(client: Client, channel: Channel, args: str, author: Member, f: Callable, command: str) -> None: c = await single_card_or_send_error(client, channel, args, author, command) if c is not None: legal_emoji = emoji.legal_emoji(c) text = emoji.replace_emoji(f(c), client) message = '**{name}** {legal_emoji} {text}'.format(name=c.name, legal_emoji=legal_emoji, text=text) await client.send_message(channel, message)
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)
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)
async def single_card_text(bot, channel, args, author, f, command): c = await single_card_or_send_error(bot, channel, args, author, command) if c is not None: legal_emoji = emoji.legal_emoji(c) text = emoji.replace_emoji(f(c), bot.client) message = '**{name}** {legal_emoji} {text}'.format( name=c.name, legal_emoji=legal_emoji, text=text) await bot.client.send_message(channel, message)
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)
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)
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)
async def single_card_text(bot, channel, args, author, f): cards = list(oracle.cards_from_query(args)) if len(cards) > 1: await bot.client.send_message(channel, '{author}: Ambiguous name.'.format(author=author.mention)) elif len(cards) == 1: legal_emjoi = emoji.legal_emoji(cards[0]) text = emoji.replace_emoji(f(cards[0]), bot.client) message = '**{name}** {legal_emjoi} {text}'.format(name=cards[0].name, legal_emjoi=legal_emjoi, text=text) await bot.client.send_message(channel, message) else: await bot.client.send_message(channel, '{author}: No matches.'.format(author=author.mention))
async def spoiler(ctx: MtgContext, *, args: str) -> None: """Request a card from an upcoming set.""" if len(args) == 0: await ctx.send('{author}: Please specify a card name.'.format(author=ctx.author.mention)) return sfcard = fetch_tools.fetch_json('https://api.scryfall.com/cards/named?fuzzy={name}'.format(name=args)) if sfcard['object'] == 'error': await ctx.send('{author}: {details}'.format(author=ctx.author.mention, details=sfcard['details'])) return imagename = '{set}_{number}'.format( set=sfcard['set'], number=sfcard['collector_number']) imagepath = '{image_dir}/{imagename}.jpg'.format(image_dir=configuration.get('image_dir'), imagename=imagename) if sfcard.get('card_faces') and sfcard.get('layout', '') != 'split': c = sfcard['card_faces'][0] else: c = sfcard fetch_tools.store(c['image_uris']['normal'], imagepath) text = emoji.replace_emoji('{name} {mana}'.format(name=sfcard['name'], mana=c['mana_cost']), ctx.bot) await ctx.send(file=File(imagepath), content=text) await oracle.scryfall_import_async(sfcard['name'])
async def echo(self, client: Client, channel: Channel, args: str, **_: Dict[str, Any]) -> None: """Repeat after me…""" s = emoji.replace_emoji(args, client) await client.send_message(channel, s)
async def echo(self, bot, channel, args): """Repeat after me…""" s = emoji.replace_emoji(args, bot.client) await bot.client.send_message(channel, s)
async def echo(ctx: MtgContext, *, args: str) -> None: """Repeat after me…""" s = emoji.replace_emoji(args, ctx.bot) if not s: s = "I'm afraid I can't do that, Dave" await ctx.send(s)
async def echo(self, bot, channel, args): """Repeat after me...""" s = emoji.replace_emoji(args, bot.client) print('Echoing {s}'.format(s=s)) await bot.client.send_message(channel, s)