Skip to content

Commit

Permalink
Prevent information leakage in ?info inside DMs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapptz committed Jun 21, 2023
1 parent 4a86f6b commit 3433a4d
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions cogs/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,29 @@ async def avatar(self, ctx: Context, *, user: Union[discord.Member, discord.User
await ctx.send(embed=embed)

@commands.command()
async def info(self, ctx: Context, *, user: Union[discord.Member, discord.User] = None):
async def info(
self,
ctx: Context,
*,
user: Annotated[Union[discord.User, discord.Member], discord.User] = None,
):
"""Shows info about a user."""

user = user or ctx.author

# Update the User to a Member instance if we're in a guild
if ctx.guild is not None:
member = ctx.guild.get_member(user.id)
if member is not None:
user = member

e = discord.Embed()
roles = [role.name.replace('@', '@\u200b') for role in getattr(user, 'roles', [])]

if ctx.guild is not None and isinstance(user, discord.Member):
roles = [role.name.replace('@', '@\u200b') for role in user.roles]
else:
roles = []

e.set_author(name=str(user))

def format_date(dt: Optional[datetime.datetime]):
Expand All @@ -475,7 +492,10 @@ def format_date(dt: Optional[datetime.datetime]):
return f'{time.format_dt(dt, "F")} ({time.format_relative(dt)})'

e.add_field(name='ID', value=user.id, inline=False)
e.add_field(name='Joined', value=format_date(getattr(user, 'joined_at', None)), inline=False)

if ctx.guild is not None and isinstance(user, discord.Member):
e.add_field(name='Joined', value=format_date(user.joined_at), inline=False)

e.add_field(name='Created', value=format_date(user.created_at), inline=False)

badges_to_emoji = {
Expand Down Expand Up @@ -508,16 +528,20 @@ def format_date(dt: Optional[datetime.datetime]):
if ctx.guild is not None and ctx.guild.owner_id == user.id:
badges.append('<:owner:585789630800986114>') # Discord Bots

if isinstance(user, discord.Member) and user.premium_since is not None:
if ctx.guild is not None and isinstance(user, discord.Member) and user.premium_since is not None:
e.add_field(name='Boosted', value=format_date(user.premium_since), inline=False)
badges.append('<:booster:1087022965775925288>') # R. Danny

if badges:
e.description = ''.join(badges)

voice = getattr(user, 'voice', None)
if voice is not None:
vc = voice.channel
if (
ctx.guild is not None
and isinstance(user, discord.Member)
and user.voice is not None
and user.voice.channel is not None
):
vc = user.voice.channel
other_people = len(vc.members) - 1
voice = f'{vc.name} with {other_people} others' if other_people else f'{vc.name} by themselves'
e.add_field(name='Voice', value=voice, inline=False)
Expand All @@ -539,7 +563,7 @@ def format_date(dt: Optional[datetime.datetime]):

e.set_thumbnail(url=user.display_avatar.url)

if isinstance(user, discord.User):
if ctx.guild is not None and isinstance(user, discord.User):
e.set_footer(text='This member is not in this server.')

await ctx.send(embed=e)
Expand Down

0 comments on commit 3433a4d

Please sign in to comment.