Ejemplo n.º 1
0
async def public_flags(ctx, user):
    bot = ctx.bot
    badges = {
        'discord_employee': f"{bot.settings['emojis']['badges']['staff']}",
        'discord_partner': f"{bot.settings['emojis']['badges']['partner']}",
        'hs_events': f"{bot.settings['emojis']['badges']['events']}",
        'hs_bravery': f"{bot.settings['emojis']['badges']['bravery']}",
        'hs_brilliance': f"{bot.settings['emojis']['badges']['brilliance']}",
        'hs_balance': f"{bot.settings['emojis']['badges']['balance']}",
        'bug_hunter_lvl1': f"{bot.settings['emojis']['badges']['hunter~1']}",
        'bug_hunter_lvl2': f"{bot.settings['emojis']['badges']['hunter~2']}",
        'verified_dev': f"{bot.settings['emojis']['badges']['developer']}",
        'early_supporter': f"{bot.settings['emojis']['badges']['early']}",
        'verified_bot': f"{bot.settings['emojis']['badges']['verified-bot']}",
        'certified_mod': f"{bot.settings['emojis']['badges']['certified-mod']}"
    }

    badge_list = []
    flag_vals = UserFlags((await
                           ctx.bot.http.get_user(user.id))['public_flags'])
    for i in badges.keys():
        if i in [*flag_vals]:
            badge_list.append(badges[i])

    return " ".join(badge_list)
Ejemplo n.º 2
0
    async def userinfo(self, ctx, *, user: discord.User = None):
        """ Overview about the information of an user """

        user = user or ctx.author
        
        badges = {
            'hs_brilliance': f'{emotes.discord_brilliance}',
            'discord_employee': f'{emotes.discord_staff}',
            'discord_partner': f'{emotes.discord_partner}',
            'hs_events': f'{emotes.discord_events}',
            'bug_hunter_lvl1': f'{emotes.discord_bug1}',
            'hs_bravery': f'{emotes.discord_bravery}',
            'hs_balance': f'{emotes.discord_balance}',
            'early_supporter': f'{emotes.discord_early}',
            'bug_hunter_lvl2': f'{emotes.discord_bug2}',
            'verified_dev': f'{emotes.discord_dev}'
        }
        
        badge_list = []
        flag_vals = UserFlags((await self.bot.http.get_user(user.id))['public_flags'])
        for i in badges.keys():
            if i in [*flag_vals]:
                badge_list.append(badges[i])
        
        ranks = []
        with open('db/badges.json', 'r') as f:
            data = json.load(f)

        try:
            ranks.append(" ".join(data["Users"][f"{user.id}"]['Badges']))
        except KeyError:
            pass

        if user.bot:
            bot = "Yes"
        elif not user.bot:
            bot = "No"
        
        if badge_list:
            discord_badges = '\n**Discord badges:** ' + ' '.join(badge_list)
        elif not badge_list:
            discord_badges = ''
        medias = ""
        for media in await self.bot.db.fetch("SELECT * FROM media WHERE user_id = $1", user.id):
            if media['media_type'] == "twitch":
                medias += f"{emotes.social_twitch} "
            elif media['media_type'] == "youtube":
                medias += f"{emotes.social_youtube} "
            elif media['media_type'] == "reddit":
                medias += f"{emotes.social_reddit} "
            elif media['media_type'] == "twitter":
                medias += f"{emotes.social_twitter} "
            elif media['media_type'] == "github":
                medias += f"{emotes.social_github} "
            elif media['media_type'] == "steam":
                medias += f"{emotes.social_steam} "
            elif media['media_type'] == "snapchat":
                medias += f"{emotes.social_snapchat} "
            medias += f"[{media['media_type'].capitalize()}]({media['media_link']}) \n"
        
        if len(medias) > 1024:
            medias = medias[1020]
            medias += '...'

        usercheck = ctx.guild.get_member(user.id)
        if usercheck:
                
            if usercheck.nick is None:
                nick = "N/A"
            else:
                nick = usercheck.nick

            status = {
            "online": f"{f'{emotes.online_mobile}' if usercheck.is_on_mobile() else f'{emotes.online_status}'}",
            "idle": f"{f'{emotes.idle_mobile}' if usercheck.is_on_mobile() else f'{emotes.idle_status}'}",
            "dnd": f"{f'{emotes.dnd_mobile}' if usercheck.is_on_mobile() else f'{emotes.dnd_status}'}",
            "offline": f"{emotes.offline_status}"
            }

            
            if usercheck.activities:
                ustatus = ""
                for activity in usercheck.activities:
                    if activity.type == discord.ActivityType.streaming:
                        ustatus += f"{emotes.streaming_status}"
            else:
                ustatus = f'{status[str(usercheck.status)]}'

            if not ustatus:
                ustatus = f'{status[str(usercheck.status)]}'
            nicks_opout = await self.bot.db.fetchval("SELECT user_id FROM nicks_op_out WHERE user_id = $1", usercheck.id)
            if nicks_opout is None:
                nicknames = []
                for nicks, in await self.bot.db.fetch(f"SELECT nickname FROM nicknames WHERE user_id = $1 AND guild_id = $2 ORDER BY time DESC", user.id, ctx.guild.id):
                    nicknames.append(nicks)
                    
                nicknamess = ""
                for nickss in nicknames[:5]:
                    nicknamess += f"{nickss}, "
                
                if nicknamess == "":
                    lnicks = "N/A"
                else:
                    lnicks = nicknamess[:-2]
            elif nicks_opout is not None:
                lnicks = 'User is opted out.'
            uroles = []
            for role in usercheck.roles:
                if role.is_default():
                    continue
                uroles.append(role.mention)  

            uroles.reverse()

            if len(uroles) > 10:
                uroles = [f"{', '.join(uroles[:10])} (+{len(usercheck.roles) - 11})"]

            profile = discord.Profile
            
            emb = discord.Embed(color=self.bot.embed_color)
            if ranks:
                emb.title = ''.join(ranks)
            emb.set_author(icon_url=user.avatar_url, name=f"{user}'s information")
            emb.add_field(name="__**General Info:**__", value=f"**Full name:** {user}\n**User ID:** {user.id}\n**Account created:** {user.created_at.__format__('%A %d %B %Y, %H:%M')}\n**Bot:** {bot}\n**Avatar URL:** [Click here]({user.avatar_url}){discord_badges}", inline=False)
            emb.add_field(name="__**Activity Status:**__", value=f"**Status:** {ustatus}\n**Activity status:** {default.member_activity(usercheck)}", inline=False)
            emb.add_field(name="__**Server Info:**__", value=f"**Nickname:** {escape_markdown(nick, as_needed=True)}\n**Latest nicknames:** {escape_markdown(lnicks, as_needed=True)}\n**Joined at:** {default.date(usercheck.joined_at)}\n**Roles: ({len(usercheck.roles) - 1}) **" + ", ".join(uroles), inline=True)    
            if user.is_avatar_animated() == False:
                emb.set_thumbnail(url=user.avatar_url_as(format='png'))
            elif user.is_avatar_animated() == True:
                emb.set_thumbnail(url=user.avatar_url_as(format='gif'))
            else:
                emb.set_thumbnail(url=user.avatar_url)
            if medias:
                emb.add_field(name="Linked medias:", value=medias[:-2])
                
            await ctx.send(embed=emb)

        elif not usercheck:
            emb = discord.Embed(color=self.bot.embed_color)
            if ranks:
                emb.title = ' '.join(ranks)
            emb.set_author(icon_url=user.avatar_url, name=f"{user}'s information")
            emb.add_field(name="__**General Info:**__", value=f"**Full name:** {user}\n**User ID:** {user.id}\n**Account created:** {user.created_at.__format__('%A %d %B %Y, %H:%M')}\n**Bot:** {bot}\n**Avatar URL:** [Click here]({user.avatar_url}){discord_badges}", inline=False)
            if user.is_avatar_animated() == False:
                emb.set_thumbnail(url=user.avatar_url_as(format='png'))
            elif user.is_avatar_animated() == True:
                emb.set_thumbnail(url=user.avatar_url_as(format='gif'))
            else:
                emb.set_thumbnail(url=user.avatar_url)
            if medias:
                emb.add_field(name="Linked medias:", value=medias[:-2])
            await ctx.send(embed=emb)