diff options
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/info/information.py | 40 | 
1 files changed, 24 insertions, 16 deletions
diff --git a/bot/exts/info/information.py b/bot/exts/info/information.py index 2d9cab94b..5aaf85e5a 100644 --- a/bot/exts/info/information.py +++ b/bot/exts/info/information.py @@ -6,12 +6,13 @@ from collections import Counter, defaultdict  from string import Template  from typing import Any, Mapping, Optional, Tuple, Union -from discord import ChannelType, Colour, Embed, Guild, Member, Message, Role, Status, utils +from discord import ChannelType, Colour, Embed, Guild, Message, Role, Status, utils  from discord.abc import GuildChannel  from discord.ext.commands import BucketType, Cog, Context, Paginator, command, group, has_any_role  from bot import constants  from bot.bot import Bot +from bot.converters import FetchedMember  from bot.decorators import in_whitelist  from bot.pagination import LinePaginator  from bot.utils.channel import is_mod_channel @@ -192,7 +193,7 @@ class Information(Cog):          await ctx.send(embed=embed)      @command(name="user", aliases=["user_info", "member", "member_info"]) -    async def user_info(self, ctx: Context, user: Member = None) -> None: +    async def user_info(self, ctx: Context, user: FetchedMember = None) -> None:          """Returns info about a user."""          if user is None:              user = ctx.author @@ -207,12 +208,14 @@ class Information(Cog):              embed = await self.create_user_embed(ctx, user)              await ctx.send(embed=embed) -    async def create_user_embed(self, ctx: Context, user: Member) -> Embed: +    async def create_user_embed(self, ctx: Context, user: FetchedMember) -> Embed:          """Creates an embed containing information on the `user`.""" +        on_server = bool(ctx.guild.get_member(user.id)) +          created = time_since(user.created_at, max_units=3)          name = str(user) -        if user.nick: +        if on_server and user.nick:              name = f"{user.nick} ({name})"          badges = [] @@ -221,8 +224,16 @@ class Information(Cog):              if is_set and (emoji := getattr(constants.Emojis, f"badge_{badge}", None)):                  badges.append(emoji) -        joined = time_since(user.joined_at, max_units=3) -        roles = ", ".join(role.mention for role in user.roles[1:]) +        if on_server: +            joined = time_since(user.joined_at, max_units=3) +            roles = ", ".join(role.mention for role in user.roles[1:]) +            membership = textwrap.dedent(f""" +                             Joined: {joined} +                             Roles: {roles or None} +                         """).strip() +        else: +            roles = None +            membership = "The user is not a member of the server"          fields = [              ( @@ -235,10 +246,7 @@ class Information(Cog):              ),              (                  "Member information", -                textwrap.dedent(f""" -                    Joined: {joined} -                    Roles: {roles or None} -                """).strip() +                membership              ),          ] @@ -263,13 +271,13 @@ class Information(Cog):          return embed -    async def basic_user_infraction_counts(self, member: Member) -> Tuple[str, str]: +    async def basic_user_infraction_counts(self, user: FetchedMember) -> Tuple[str, str]:          """Gets the total and active infraction counts for the given `member`."""          infractions = await self.bot.api_client.get(              'bot/infractions',              params={                  'hidden': 'False', -                'user__id': str(member.id) +                'user__id': str(user.id)              }          ) @@ -280,7 +288,7 @@ class Information(Cog):          return "Infractions", infraction_output -    async def expanded_user_infraction_counts(self, member: Member) -> Tuple[str, str]: +    async def expanded_user_infraction_counts(self, user: FetchedMember) -> Tuple[str, str]:          """          Gets expanded infraction counts for the given `member`. @@ -290,7 +298,7 @@ class Information(Cog):          infractions = await self.bot.api_client.get(              'bot/infractions',              params={ -                'user__id': str(member.id) +                'user__id': str(user.id)              }          ) @@ -321,12 +329,12 @@ class Information(Cog):          return "Infractions", "\n".join(infraction_output) -    async def user_nomination_counts(self, member: Member) -> Tuple[str, str]: +    async def user_nomination_counts(self, user: FetchedMember) -> Tuple[str, str]:          """Gets the active and historical nomination counts for the given `member`."""          nominations = await self.bot.api_client.get(              'bot/nominations',              params={ -                'user__id': str(member.id) +                'user__id': str(user.id)              }          )  |