async def command_stats(self, ctx, *, command: str = None): """Shows commands statistics.""" if command: async with self.bot.pgpool.acquire() as conn: record = await get_statistics(conn, command) if not record: return await ctx.send( 'There are no statistics for that command.') embed = discord.Embed(title=f'Statistics for `{command}`') embed.add_field( name='Times used', value=utils.commas(record['times_used'])) embed.add_field( name='Last used', value=utils.ago(record['last_used'])) return await ctx.send(embed=embed) select = 'SELECT * FROM command_statistics ORDER BY times_used DESC LIMIT 5' async with self.bot.pgpool.acquire() as conn: records = await conn.fetch(select) medals = [':first_place:', ':second_place:', ':third_place:'] embed = discord.Embed(title='Most used commands') async with self.bot.pgpool.acquire() as conn: lu = utils.ago(await last_used(conn)) embed.set_footer(text=f'Last command usage was {lu}') for index, record in enumerate(records): medal = medals[index] if index < 3 else '' td = utils.ago(record['last_used']) used = 'Used {} time(s) (last used {})'.format( utils.commas(record['times_used']), td) embed.add_field( name=medal + record['command_name'], value=used, inline=False) await ctx.send(embed=embed)
async def gb_status(self, ctx, who: converters.RawMember): """ Checks on global ban status. """ is_banned = await ctx.bot.is_global_banned(who) is_banned_cached = (await ctx.bot.redis.get(f'cache:globalbans:{who.id}') ).decode() == 'banned' async with ctx.acquire() as conn: actual_ban = await conn.fetchrow( 'SELECT * FROM globalbans WHERE user_id = $1', who.id) embed = discord.Embed(color=( discord.Color.red() if is_banned else discord.Color.green())) embed.set_author(name=who, icon_url=who.avatar_url_as(format='png')) embed.add_field(name='Ban cached', value='Yes' if is_banned_cached else 'No') embed.add_field(name='Actually banned', value='Yes' if actual_ban is not None else 'No') if actual_ban: embed.description = f'**Banned for:** {actual_ban["reason"]}' embed.add_field(name='Banned', value=utils.ago(actual_ban["created_at"])) await ctx.send(embed=embed)
def _make_joined_embed(self, member): embed = utils.make_profile_embed(member) joined_dif = utils.ago(member.created_at) embed.add_field( name='Joined Discord', value= f'{joined_dif}\n{utils.standard_datetime(member.created_at)} UTC') return embed
async def check(self, time, member: Member): try: minimum_required = int(time) seconds_on_discord = (datetime.datetime.utcnow() - member.created_at).total_seconds() ago = utils.ago(member.created_at) if seconds_on_discord < minimum_required: raise Block( f'Failed minimum creation time check ({seconds_on_discord} < {minimum_required}' f', created {ago})') except ValueError: raise Report( 'Invalid minimum creation time, must be a valid number.')
async def joined(self, ctx, target: discord.Member = None): """ Shows when someone joined this server and Discord. If no arguments were passed, your information is shown. """ if target is None: target = ctx.message.author embed = self._make_joined_embed(target) joined_dif = utils.ago(target.joined_at) embed.add_field( name='Joined this Server', value= f'{joined_dif}\n{utils.standard_datetime(target.joined_at)} UTC', inline=False) await ctx.send(embed=embed)
async def block(reason: str): """ Bounces a user from this guild.""" params = { 'member.username': member.name, 'member.mention': member.mention, 'member.tag': member, 'member.id': member.id, 'reason': reason, } # person got bounced, send bounce message if 'bounce_message' in settings: try: formatted = user_format(settings['bounce_message'], params) await member.send(formatted) except discord.HTTPException: pass try: # adios await member.kick( reason=f'Gatekeeper check(s) failed ({reason})') except discord.Forbidden: await report( f"\N{CROSS MARK} Couldn't kick {describe(member)}, no permissions." ) else: # report embed = Embed(color=discord.Color.red(), title=f'Bounced {describe(member)}') embed.add_field(name='Account creation', value=utils.ago(member.created_at)) embed.add_field(name='Reason', value=reason) embed.set_footer(text=utils.now()) embed.set_thumbnail(url=member.avatar_url) await report(embed=embed)