async def avatar(self, context, *, member: conv.FuzzyMember = None): member = member or context.author embed = colors.embed() embed.title = str(member) embed.set_image(url=str(member.avatar_url).replace('webp', 'png')) embed.timestamp = datetime.now().astimezone() await context.send(embed=embed)
async def define(lang, word, full=False): url = API.format(lang, word) if downloaded.get(word): data = downloaded[word] else: data = await utils.download(url) data = json.loads(data or '{}') downloaded[word] = data embed = colors.embed(title=word, url=GOOGLE_URL + quote(word)) embed.set_author(name=GOOGLE_DICTIONARY) if not isinstance(data, list): embed.description = NO_DEFS embed.set_footer(text=NO_DEFS_FOOTER) return embed for d in data: for meaning in d[MEANINGS]: lines = [] phonetic = d.get(PHONETIC) part_of_speech = meaning.get(PART_OF_SPEECH) title = ' - '.join(filter(None, [phonetic, part_of_speech])) defs = meaning[DEFINITIONS] if not full: defs = [de for de in defs if de.get(DEFINITION)] defs = defs[:3] for i, de in enumerate(defs): if not de: continue numbering = f'{i+1}. ' if len(defs) > 1 else '' new_lines = [] new_lines += [numbering + de.get(DEFINITION, '')] example = de.get(EXAMPLE) if full and example: new_lines += [f'*"{example}"*'] synonyms = de.get(SYNONYMS, []) has_synonyms = len(''.join(synonyms)) if full and has_synonyms: new_lines += [f'**{SYNONYMS.title()}**: ' + ' • '.join(f'`{s}`' for s in synonyms)] new_lines += [''] lines, title = add_field_if_overflown(embed, title, lines, new_lines) lines += new_lines origin = d.get(ORIGIN) if full and origin: origin_line = [f'**{ORIGIN.title()}**: {origin}\n'] lines, title = add_field_if_overflown(embed, title, lines, origin_line) lines += origin_line add_lines_as_field(embed, title, lines) return embed
async def eval(self, context, tick: Optional[is_tick] = False, *, code=None): import math, random oneliner = code def check(m): return m.author == context.author and m.channel == context.channel if not oneliner: await context.send('```>>>```') msg = None while True: if not oneliner: msg = await self.bot.wait_for('message', check=check) code = msg.content if code in EXIT_METHODS: await context.send('```<<<```') break try: asynchronous = code.startswith('await ') code = code.replace('await ', '') try: output = eval(code) except: output = exec(code) if asynchronous: output = await output title = '' except Exception as e: output = e title = 'тЪая╕П **Error**:' if not oneliner and output == None: await msg.add_reaction('тЬЕ') else: if tick: output = f'```{output}```' content = f'{title}\n{output}' if len(content) > 2000: content = content[:2000 - 6] + '...' if tick: content += '```' embed = colors.embed(description=content) await context.send(embed=embed) if oneliner: break
async def whos(self, context, *, member: Optional[conv.FuzzyMember] = None): member = member or context.author response = f'It\'s **{member}**' embed = colors.embed() embed.description = member.mention created_at = timedisplay.to_ict(member.created_at, timedisplay.DAYWEEK_DAY_IN_YEAR) joined_at = timedisplay.to_ict(member.joined_at, timedisplay.DAYWEEK_DAY_IN_YEAR) embed \ .set_thumbnail(url=member.avatar_url) \ .add_field(name='On Discord since', value=created_at, inline=False) \ .add_field(name='Joined on', value=joined_at) await context.send(response, embed=embed)
async def on_message(self, message): context = await self.bot.get_context(message) if not message.guild or message.author == self.bot.user or context.command: return urls = re.findall(JUMP_URL_PATTERN, message.content) for jump_url in urls: quoted_message = await self.message_converter.convert(context, jump_url) author = quoted_message.author author_text = f'{author.display_name} #{quoted_message.channel}' embed = colors.embed(description=quoted_message.content) \ .set_author(name=author_text, icon_url=author.avatar_url) \ .add_field(name='Link', value=f'[Jump]({jump_url})') embed.timestamp = quoted_message.created_at for a in quoted_message.attachments: embed.set_image(url=a.url) await context.send(embed=embed) if quoted_message.embeds: await context.send(embed=quoted_message.embeds[0])
async def send_posts_in_embeds(context, sub, sorting, posts, period): if not isinstance(posts, range): posts = parse_posts(posts) if sorting is not TOP: period = '' rss = await download_rss(sub, sorting, period) sub_url = compile_url(sub, sorting, period, link=SUB_URL) period = PERIODS_TO_DISPLAY.get(period, period).title() vreddit_posts = [] for i in posts: post = get_entry_in_rss(rss, i, sorting) title = ' '.join(filter(None, [sorting.title(), f'#{i+1}', period])) embed = colors.embed(title=post.titles[0], url=post.url, description=post.text) \ .set_author(name=f'{title} on ' + post.sub, url=sub_url, icon_url=post.sub_logo) \ .set_thumbnail(url=post.thumbnail or '') \ .set_image(url=post.image) \ .set_footer(text='Reddit', icon_url=ICON_URL) if len(post.titles) == 2: embed.add_field(name='More Title', value=post.titles[1]) if post.content_url: embed.add_field(name='Link', value=post.content_url_field) msg = await context.send(embed=embed) if is_special_website(post.content_url): extra_msg = await context.send(post.content_url) if VREDDIT in post.content_url: vreddit_posts += [(msg, extra_msg)] for msg, extra_msg in vreddit_posts: while not extra_msg.embeds: await asyncio.sleep(1) extra_msg = await extra_msg.channel.fetch_message(extra_msg.id) continue url = extra_msg.embeds and extra_msg.embeds[0].thumbnail.url if url: embed = msg.embeds[0] embed.set_image(url=url).set_thumbnail(url='') await extra_msg.delete() await msg.edit(embed=embed)
async def inspiro(self, context): await context.trigger_typing() embed = colors.embed(title='InspiroBot', url=INSPIROBOT_URL) quote_image = await get_inspiro_quote() embed.set_image(url=quote_image) await context.send(embed=embed)
async def invite(self, context): worryluv = discord.utils.get(self.bot.emojis, name='worryluv') embed = colors.embed() embed.description = f'{worryluv} [Click here]({INVITE_LINK}) to invite {self.bot.user.name}!' await context.send(embed=embed)