Skip to content

Commit fe60e65

Browse files
committed
Prevent information leakage in ?info inside DMs
1 parent 4a86f6b commit fe60e65

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

cogs/meta.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,12 @@ async def info(self, ctx: Context, *, user: Union[discord.Member, discord.User]
466466

467467
user = user or ctx.author
468468
e = discord.Embed()
469-
roles = [role.name.replace('@', '@\u200b') for role in getattr(user, 'roles', [])]
469+
470+
if ctx.guild is not None and isinstance(user, discord.Member):
471+
roles = [role.name.replace('@', '@\u200b') for role in user.roles]
472+
else:
473+
roles = []
474+
470475
e.set_author(name=str(user))
471476

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

477482
e.add_field(name='ID', value=user.id, inline=False)
478-
e.add_field(name='Joined', value=format_date(getattr(user, 'joined_at', None)), inline=False)
483+
484+
if ctx.guild is not None and isinstance(user, discord.Member):
485+
e.add_field(name='Joined', value=format_date(user.joined_at), inline=False)
486+
479487
e.add_field(name='Created', value=format_date(user.created_at), inline=False)
480488

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

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

515523
if badges:
516524
e.description = ''.join(badges)
517525

518-
voice = getattr(user, 'voice', None)
519-
if voice is not None:
520-
vc = voice.channel
526+
if (
527+
ctx.guild is not None
528+
and isinstance(user, discord.Member)
529+
and user.voice is not None
530+
and user.voice.channel is not None
531+
):
532+
vc = user.voice.channel
521533
other_people = len(vc.members) - 1
522534
voice = f'{vc.name} with {other_people} others' if other_people else f'{vc.name} by themselves'
523535
e.add_field(name='Voice', value=voice, inline=False)
@@ -539,7 +551,7 @@ def format_date(dt: Optional[datetime.datetime]):
539551

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

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

545557
await ctx.send(embed=e)

0 commit comments

Comments
 (0)