def emoji(self, event, emoji): if not EMOJI_RE.match(emoji): raise CommandFail('Unknown emoji: `{}`'.format(emoji)) fields = [] name, eid = EMOJI_RE.findall(emoji)[0] fields.append('**ID:** {}'.format(eid)) fields.append('**Name:** {}'.format(S(name))) guild = self.state.guilds.find_one(lambda v: eid in v.emojis) if guild: fields.append('**Guild:** {} ({})'.format(S(guild.name), guild.id)) url = 'https://cdn.discordapp.com/emojis/{}.png?v=1'.format(eid) r = requests.get(url) r.raise_for_status() return event.msg.reply('\n'.join(fields), attachments=[('emoji.png', r.content)])
def emoji(self, event, emoji): if not EMOJI_RE.match(emoji): return event.msg.reply(u'Unknown emoji: `{}`'.format(S(emoji))) fields = [] name, eid = EMOJI_RE.findall(emoji)[0] fields.append('**ID:** {}'.format(eid)) fields.append('**Name:** {}'.format(S(name))) guild = self.state.guilds.find_one(lambda v: eid in v.emojis) if guild: fields.append('**Guild:** {} ({})'.format(S(guild.name), guild.id)) anim = emoji.startswith('<a:') fields.append('**Animated:** {}'.format('Yes' if anim else 'No')) ext = 'gif' if anim else 'png' url = 'https://discordapp.com/api/emojis/{}.{}'.format(eid, ext) r = requests.get(url) r.raise_for_status() return event.msg.reply('\n'.join(fields), attachments=[('emoji.'+ext, r.content)])
def jumbo(self, event, emojis): urls = [] names = [] for emoji in emojis.split(' ')[:5]: if EMOJI_RE.match(emoji): _, eid = EMOJI_RE.findall(emoji)[0] urls.append( 'https://discordapp.com/api/emojis/{}.png'.format(eid)) names.append(_) else: urls.append(get_emoji_url(emoji)) names.append('emoji') width, height, images = 0, 0, [] for r in Pool(6).imap(requests.get, urls): try: r.raise_for_status() except requests.HTTPError: return img = Image.open(BytesIO(r.content)) height = img.height if img.height > height else height width += img.width + 10 images.append(img) image = Image.new('RGBA', (width, height)) width_offset = 0 for img in images: image.paste(img, (width_offset, 0)) width_offset += img.width + 10 combined = BytesIO() image.save(combined, 'png', quality=55) combined.seek(0) return event.msg.reply('', attachments=[('{}.png'.format('-'.join(names)), combined)])
def jumbo(self, event, emojis): emojis = emojis.split(' ') if len(emojis) == 1: url = ext = '' emoji = emojis[0] if EMOJI_RE.match(emoji): _, eid = EMOJI_RE.findall(emoji)[0] ext = 'gif' if emoji.startswith('<a:') else 'png' url = 'https://cdn.discordapp.com/emojis/{}.{}?v=1'.format( eid, ext) else: ext = 'png' url = self.get_emoji_url(emoji) if not url: raise CommandFail('provided emoji is invalid') r = requests.get(url) try: r.raise_for_status() except requests.HTTPError: raise CommandFail('provided emoji is invalid') return event.msg.reply('', attachments=[('emoji.' + ext, r.content)]) else: urls = [] for emoji in emojis[:5]: if EMOJI_RE.match(emoji): _, eid = EMOJI_RE.findall(emoji)[0] urls.append( 'https://cdn.discordapp.com/emojis/{}.png?v=1'.format( eid)) else: url = self.get_emoji_url(emoji) urls.append(url) if url else None width, height, images = 0, 0, [] for r in Pool(6).imap(requests.get, urls): try: r.raise_for_status() except requests.HTTPError: continue img = Image.open(BytesIO(r.content)) height = img.height if img.height > height else height width += img.width + 10 images.append(img) if not images: raise CommandFail('provided emojis are invalid') image = Image.new('RGBA', (width, height)) width_offset = 0 for img in images: image.paste(img, (width_offset, 0)) width_offset += img.width + 10 combined = BytesIO() image.save(combined, 'png', quality=55) combined.seek(0) return event.msg.reply('', attachments=[('emoji.png', combined)])