async def lastimage(self, ctx): url = await last_image(ctx) if url is None: return await ctx.send('Unable to find an image') e = discord.Embed(colour=bright_color()) e.set_image(url=url) await ctx.send(embed=e)
async def translate(self, ctx, *, text: commands.clean_content=None): """Translates a message to English using Google translate. If no message is given, I will try and find the last message with text""" if text is None: async for message in ctx.channel.history(limit=25, before=ctx.message): if message.content: text = message.content break if text is None: return await ctx.send('Unable to find text to translate!') loop = self.bot.loop try: res = await loop.run_in_executor(None, self.translator.translate, text) except Exception as e: return await ctx.send(f'An error occurred: {e.__class__.__name__}: {e}') embed = discord.Embed(title='Translated', colour=bright_color()) src = googletrans.LANGUAGES.get(res.src, '(auto-detected)').title() dest = googletrans.LANGUAGES.get(res.dest, 'Unknown').title() original = res.origin if len(res.origin) < 1024 else f'[Text too long to send, uploaded instead]({await upload_hastebin(ctx, res.origin)})' translated = res.text if len(res.text) < 1024 else f'[Text too long to send, uploaded instead]({await upload_hastebin(ctx, res.text)})' embed.add_field(name=f'From {src}', value=original, inline=False) embed.add_field(name=f'To {dest}', value=translated, inline=False) if len(res.origin) > 1024 or len(res.text) > 1024: embed.description = 'Text too long to send, uploaded instead' await ctx.send(embed=embed)
async def userinfo(self, ctx, *, user: Union[CaseInsensitiveMember, CachedUserID] = None): user = user or ctx.author if user.color is discord.Color.default(): color = bright_color() else: color = user.color e = discord.Embed(title='User Info', color=color) e.set_author(icon_url=user.display_avatar.url, name=user) e.add_field(name='ID', value=user.id) if isinstance(user, discord.Member) and user.nick: e.add_field(name='Nick', value=user.nick) e.add_field(name='Severs Shared', value=sum(g.get_member(user.id) is not None for g in self.bot.guilds)) e.add_field(name='Created', value=self.fmt_dt(user.created_at)) if isinstance(user, discord.Member): e.add_field(name='First Joined**', value=self.fmt_dt(await self.get_join_date(user))) e.add_field(name='Last Joined', value=self.fmt_dt(user.joined_at)) roles = ['@everyone'] roles.extend(r.mention for r in user.roles[1:]) e.add_field(name='Roles', value=', '.join(roles)) e.set_footer(text='**I can only get the earliest join date since I was added to the server') nicks = await self.get_nicknames(user) if nicks: e.add_field(name='Previous Nicknames', value=nicks) e.add_field(name='Previous names', value=(await self.get_usernames(user) or str(user))) await ctx.send(embed=e)
async def guild_info(self, ctx): guild = ctx.guild text_channels = len(guild.text_channels) voice_channels = len(guild.voice_channels) if len(guild.roles) > 30: roles = [role.mention for role in reversed(guild.roles[-30:])] roles = ", ".join(roles) show_roles = f'Top 30/{len(guild.roles)} roles: {roles}, `...`' else: roles = [role.mention for role in reversed(guild.roles[1:])] roles = ", ".join(roles) show_roles = f'{len(guild.roles)} roles: {roles}, @everyone' e = discord.Embed(title='Server Info', color=bright_color()) e.set_author(icon_url=guild.icon, name=guild.name) e.add_field(name='ID', value=guild.id) e.add_field(name='Owner', value=guild.owner) e.add_field(name='Region', value=guild.region) e.add_field(name='Members', value=guild.member_count) e.add_field(name='Channels', value=f'{text_channels} Text | {voice_channels} Voice') e.add_field(name='Created', value=self.fmt_dt(guild.created_at)) e.add_field(name='Roles', value=show_roles) await ctx.send(embed=e)
async def wolframalpha(self, ctx, *, query): wolfram_payload = { 'appid': WOLFRAM_ALPHA_APPID, 'i': query, 'layout': 'labelbar', 'background': 'black', 'foreground': 'white', 'width': '800', 'fontsize': '22', 'units': 'metric', } await ctx.trigger_typing() async with self.bot.session.get(WOLFRAM_API, params=wolfram_payload) as resp: if resp.status == 501: return await ctx.reply('Invalid query') data = io.BytesIO(await resp.read()) e = discord.Embed(color=bright_color(), timestamp=datetime.utcnow()) e.set_image(url='attachment://response.png') e.set_footer( text=f'Query: {query[:30] + "..." if len(query)>30 else query}') await ctx.reply(embed=e, file=discord.File(data, filename='response.png'), mention_author=False) await ctx.tick()
async def member_count(self, ctx): """Returns the member count of the guild""" statuses = Counter(m.status for m in ctx.guild.members) bots = Counter(m.bot for m in ctx.guild.members) formatted_statuses = f'<:status_online:602811779948740627> {statuses.get(discord.Status.online, 0)}\n' \ f'<:status_offline:602811780053336069> {statuses.get(discord.Status.offline, 0)}\n' \ f'<:status_idle:602811780129095701> {statuses.get(discord.Status.idle, 0)}\n' \ f'<:status_dnd:602811779931701259> {statuses.get(discord.Status.dnd, 0)}' e = discord.Embed(color=bright_color(), timestamp=datetime.utcnow()) e.set_author(name=f'{ctx.guild}\'s member count', icon_url=ctx.guild.icon) e.add_field(name='Total', value=ctx.guild.member_count) e.add_field(name='Humans', value=bots.get(False, 0)) e.add_field(name='Bots', value=bots.get(True, 0)) e.add_field(name='Status', value=formatted_statuses) await ctx.send(embed=e)
async def upscale(self, ctx, url=None): url = url or await last_image(ctx) if url is None: return await ctx.send('Unable to find an image') if not await is_image(ctx, url): return await ctx.send('That is not a valid image url') data = { 'image': url } async with self.bot.session.post(API_URL, data=data, headers=HEADERS) as resp: jdata = await resp.json() img_url = jdata.get('output_url') if img_url is None: return await ctx.send('Failed') e = discord.Embed(colour=bright_color()) e.set_image(url=img_url) e.set_author(name='Upscale', url=img_url) await ctx.send(embed=e)
async def serverinfo(self, ctx): guild = ctx.guild text_channels = len(guild.text_channels) voice_channels = len(guild.voice_channels) roles = ['@everyone'] roles.extend([role.mention for role in guild.roles[1:]]) roles = ", ".join(roles) e = discord.Embed(title='Server Info', color=bright_color()) e.set_author(icon_url=guild.icon_url, name=guild.name) e.add_field(name='ID', value=guild.id) e.add_field(name='Owner', value=guild.owner) e.add_field(name='Region', value=guild.region) e.add_field(name='Members', value=guild.member_count) e.add_field(name='Channels', value=f'{text_channels} Text | {voice_channels} Voice') e.add_field(name='Created', value=human_timedelta(guild.created_at)) e.add_field(name='Roles', value=roles) await ctx.send(embed=e)
async def upscale(self, ctx, url=None): url = url or await last_image(ctx) if url is None: return await ctx.send('Unable to find an image') if not await is_image(ctx, url): return await ctx.send('That is not a valid image url') data = { 'image': url } r = requests.post(API_URL,data=data,headers=HEADERS) upscaled_image = r.json() img_url = upscaled_image['output_url'] if img_url is None: return await ctx.send('Failed') e = discord.Embed(colour=bright_color()) e.set_image(url=img_url) e.set_author(name='Upscaled Image', url=img_url) await ctx.send(embed=e)