async def rinfo(self, ctx, *, role: discord.Role):
     """Get info about role"""
     em = discord.Embed(
         title=chat.escape(role.name, formatting=True),
         color=role.color if role.color.value else discord.Embed.Empty,
     )
     em.add_field(name=_("ID"), value=role.id)
     em.add_field(
         name=_("Permissions"),
         value=
         "[{0}](https://cogs.fixator10.ru/permissions-calculator/?v={0})".
         format(role.permissions.value),
     )
     em.add_field(
         name=_("Exists since"),
         value=get_markdown_timestamp(role.created_at,
                                      TimestampStyle.datetime_long),
     )
     em.add_field(name=_("Color"), value=role.colour)
     em.add_field(name=_("Members"), value=str(len(role.members)))
     em.add_field(name=_("Position"), value=role.position)
     em.add_field(name=_("Managed"), value=bool_emojify(role.managed))
     em.add_field(name=_("Managed by bot"),
                  value=bool_emojify(role.is_bot_managed()))
     em.add_field(name=_("Managed by boosts"),
                  value=bool_emojify(role.is_premium_subscriber()))
     em.add_field(name=_("Managed by integration"),
                  value=bool_emojify(role.is_integration()))
     em.add_field(name=_("Hoist"), value=bool_emojify(role.hoist))
     em.add_field(name=_("Mentionable"),
                  value=bool_emojify(role.mentionable))
     em.add_field(name=_("Mention"),
                  value=role.mention + "\n`" + role.mention + "`")
     em.set_thumbnail(
         url=
         f"https://xenforo.com/community/rgba.php?r={role.colour.r}&g={role.color.g}&b={role.color.b}&a=255"
     )
     await ctx.send(embed=em)
Exemple #2
0
async def activity_embed(ctx, activity: discord.Activity) -> discord.Embed:
    """Make embed with info about activity"""
    # design is not my best side
    if isinstance(activity, discord.CustomActivity):
        em = discord.Embed(title=activity.name, color=await ctx.embed_color())
        if activity.emoji:
            if activity.emoji.is_unicode_emoji():
                emoji_pic = await get_twemoji(activity.emoji.name)
            else:
                emoji_pic = activity.emoji.url
            if activity.name:
                em.set_thumbnail(url=emoji_pic)
            else:
                em.set_image(url=emoji_pic)
        em.set_footer(text=_("Custom status"))
    elif isinstance(activity, discord.Game):
        em = discord.Embed(
            title=_("Playing {}").format(activity.name),
            timestamp=activity.start or discord.Embed.Empty,
            color=await ctx.embed_color(),
        )
        # noinspection PyUnresolvedReferences
        apps = await ctx.cog.bot.http.request(
            discord.http.Route("GET", "/applications/detectable"))
        app = await find_app_by_name(apps, activity.name)
        if app:
            em.set_thumbnail(url=APP_ICON_URL.format(
                app_id=app.get("id", ""),
                icon_hash=app.get("icon", ""),
            ))
        if activity.end:
            em.add_field(
                name=_("This game will end at"),
                value=get_markdown_timestamp(activity.end,
                                             TimestampStyle.time_long),
            )
        if activity.start:
            em.set_footer(text=_("Playing since"))
    elif isinstance(activity, discord.Activity):
        party_size = activity.party.get("size")
        party_size = f" ({party_size[0]}/{party_size[1]})" if party_size else ""
        em = discord.Embed(
            title=
            f"{_(ACTIVITY_TYPES.get(activity.type, activity.type))} {activity.name}",
            description=f"{activity.details and activity.details or ''}\n"
            f"{activity.state and activity.state or ''}{party_size}",
            color=await ctx.embed_color(),
        )
        # noinspection PyUnresolvedReferences
        apps = await ctx.cog.bot.http.request(
            discord.http.Route("GET", "/applications/detectable"))
        app = await find_app_by_name(apps, activity.name)
        if app:
            em.set_thumbnail(url=APP_ICON_URL.format(
                app_id=app.get("id", activity.application_id or ""),
                icon_hash=app.get("icon", ""),
            ))
        if activity.small_image_text:
            em.add_field(
                name=_("Small image text"),
                value=activity.small_image_text,
                inline=False,
            )
        if activity.application_id:
            em.add_field(name=_("Application ID"),
                         value=activity.application_id)
        if activity.start:
            em.add_field(
                name=_("Started at"),
                value=get_markdown_timestamp(activity.start,
                                             TimestampStyle.time_long),
            )
        if activity.end:
            em.add_field(
                name=_("Will end at"),
                value=get_markdown_timestamp(activity.end,
                                             TimestampStyle.time_long),
            )
        if activity.large_image_text:
            em.add_field(
                name=_("Large image text"),
                value=activity.large_image_text,
                inline=False,
            )
        if activity.small_image_url:
            em.set_thumbnail(url=activity.small_image_url)
        if activity.large_image_url:
            em.set_image(url=activity.large_image_url)
    elif isinstance(activity, discord.Streaming):
        em = discord.Embed(
            title=activity.name,
            description=_("Streaming on {}").format(activity.platform),
            url=activity.url,
        )
        if activity.game:
            em.add_field(name=_("Game"), value=activity.game)
    elif isinstance(activity, discord.Spotify):
        em = discord.Embed(
            title=activity.title,
            description=_("by {}\non {}").format(", ".join(activity.artists),
                                                 activity.album),
            color=activity.color,
            timestamp=activity.created_at,
            url=f"https://open.spotify.com/track/{activity.track_id}",
        )
        em.add_field(
            name=_("Started at"),
            value=get_markdown_timestamp(activity.start,
                                         TimestampStyle.time_long),
        )
        em.add_field(name=_("Duration"),
                     value=str(activity.duration)[:-3])  # 0:03:33.877[000]
        em.add_field(
            name=_("Will end at"),
            value=get_markdown_timestamp(activity.end,
                                         TimestampStyle.time_long),
        )
        em.set_image(url=activity.album_cover_url)
        em.set_footer(text=_("Listening since"))
    else:
        em = discord.Embed(
            title=_("Unsupported activity type: {}").format(type(activity)))
    return em
Exemple #3
0
async def emoji_embed(
        ctx, emoji: Union[discord.Emoji,
                          discord.PartialEmoji]) -> discord.Embed:
    """Make embed with info about emoji"""
    em = discord.Embed(
        title=isinstance(emoji, str) and "\n".join(
            map(
                lambda c: unicodedata.name(
                    c, _("[Unable to resolve unicode name]")), emoji))
        or chat.escape(emoji.name, formatting=True),
        color=await ctx.embed_color(),
    )
    if isinstance(emoji, str):
        # em.add_field(name=_("Unicode emoji"), value="✅")
        em.add_field(
            name=_("Unicode character"),
            value="\n".join(
                f"\\{c}" if c not in NON_ESCAPABLE_CHARACTERS else c
                for c in emoji),
        )
        em.add_field(
            name=_("Unicode category"),
            value="\n".join(unicodedata.category(c) for c in emoji),
        )
        em.set_image(url=await get_twemoji(emoji))
    if not isinstance(emoji, str):
        em.add_field(name=_("ID"), value=emoji.id)
        em.add_field(name=_("Animated"), value=bool_emojify(emoji.animated))
        em.set_image(url=emoji.url)
    if isinstance(emoji, discord.Emoji):
        em.add_field(
            name=_("Exists since"),
            value=get_markdown_timestamp(emoji.created_at,
                                         TimestampStyle.datetime_long),
        )
        em.add_field(name=_('":" required'),
                     value=bool_emojify(emoji.require_colons))
        em.add_field(name=_("Managed"), value=bool_emojify(emoji.managed))
        em.add_field(name=_("Server"), value=emoji.guild)
        em.add_field(name=_("Available"), value=bool_emojify(emoji.available))
        em.add_field(name=_("Usable by bot"),
                     value=bool_emojify(emoji.is_usable()))
        if emoji.roles:
            em.add_field(
                name=_("Roles"),
                value=chat.escape("\n".join(x.name for x in emoji.roles),
                                  formatting=True),
                inline=False,
            )
    elif isinstance(emoji, discord.PartialEmoji):
        em.add_field(
            name=_("Exists since"),
            value=get_markdown_timestamp(emoji.created_at,
                                         TimestampStyle.datetime_long),
        )
        em.add_field(name=_("Custom emoji"),
                     value=bool_emojify(emoji.is_custom_emoji()))
        # em.add_field(
        #     name=_("Unicode emoji"), value=bool_emojify(emoji.is_unicode_emoji())
        # )
    return em
 async def steamprofile(self, ctx, profile: SteamUser):
     """Get steam user's steamcommunity profile"""
     em = discord.Embed(
         title=profile.personaname,
         description=profile.personastate(),
         url=profile.profileurl,
         timestamp=datetime.utcfromtimestamp(profile.lastlogoff)
         if profile.lastlogoff else discord.Embed.Empty,
         color=profile.personastatecolor,
     )
     if profile.gameid:
         em.description = _(
             "In game: [{}](http://store.steampowered.com/app/{})").format(
                 profile.gameextrainfo or "Unknown", profile.gameid)
         if profile.gameserver:
             em.description += _(" on server {}").format(profile.gameserver)
         if profile.shared_by:
             em.description += _("\nFamily Shared by [{}]({})").format(
                 profile.shared_by.personaname,
                 profile.shared_by.profileurl)
     if profile.realname:
         em.add_field(name=_("Real name"),
                      value=profile.realname,
                      inline=False)
     em.add_field(name=_("Level"), value=profile.level or "0")
     if profile.country:
         em.add_field(name=_("Country"),
                      value=":flag_{}:".format(profile.country.lower()))
     em.add_field(name=_("Visibility"), value=profile.visibility)
     if profile.createdat:
         em.add_field(
             name=_("Created at"),
             value=get_markdown_timestamp(
                 datetime.utcfromtimestamp(profile.createdat)),
         )
     em.add_field(name="SteamID",
                  value="{}\n{}".format(profile.steamid, profile.sid3))
     em.add_field(name="SteamID64", value=profile.steamid64)
     if any([profile.VACbanned, profile.gamebans]):
         bansdescription = _("Days since last ban: {}").format(
             profile.sincelastban)
     elif any([profile.communitybanned, profile.economyban]):
         bansdescription = _("Has one or more bans:")
     else:
         bansdescription = _("No bans on record")
     em.add_field(name=_("🛡 Bans"), value=bansdescription, inline=False)
     em.add_field(name=_("Community ban"),
                  value=bool_emojify(profile.communitybanned))
     em.add_field(
         name=_("Economy ban"),
         value=profile.economyban.capitalize()
         if profile.economyban else "❌",
     )
     em.add_field(
         name=_("VAC bans"),
         value=_("{} VAC bans").format(profile.VACbans)
         if profile.VACbans else "❌",
     )
     em.add_field(
         name=_("Game bans"),
         value=_("{} game bans").format(profile.gamebans)
         if profile.gamebans else "❌",
     )
     em.set_thumbnail(url=profile.avatar184)
     footer = [_("Powered by Steam")]
     if profile.lastlogoff:
         footer.append(_("Last seen on"))
     em.set_footer(
         text=" • ".join(footer),
         icon_url=
         "https://steamstore-a.akamaihd.net/public/shared/images/responsive/share_steam_logo.png",
     )
     await ctx.send(embed=em)
 async def cinfo(
     self,
     ctx,
     *,
     channel: Union[discord.TextChannel, discord.VoiceChannel,
                    discord.StageChannel, discord.CategoryChannel, ] = None,
 ):
     """Get info about channel"""
     if channel is None:
         channel = ctx.channel
     changed_roles = sorted(channel.changed_roles,
                            key=lambda r: r.position,
                            reverse=True)
     em = discord.Embed(
         title=chat.escape(str(channel.name), formatting=True),
         description=topic if
         (topic := getattr(channel, "topic", None)) else
         "\N{SPEECH BALLOON}: {} | \N{SPEAKER}: {} | \N{SATELLITE ANTENNA}: {}"
         .format(
             len(channel.text_channels),
             len(channel.voice_channels),
             len(channel.stage_channels),
         ) if isinstance(channel,
                         discord.CategoryChannel) else discord.Embed.Empty,
         color=await ctx.embed_color(),
     )
     em.add_field(name=_("ID"), value=channel.id)
     em.add_field(
         name=_("Type"),
         value=CHANNEL_TYPE_EMOJIS.get(channel.type, str(channel.type)),
     )
     em.add_field(
         name=_("Exists since"),
         value=get_markdown_timestamp(channel.created_at,
                                      TimestampStyle.datetime_long),
     )
     em.add_field(
         name=_("Category"),
         value=chat.escape(str(channel.category), formatting=True)
         or chat.inline(_("Not in category")),
     )
     em.add_field(name=_("Position"), value=channel.position)
     if isinstance(channel, discord.TextChannel):
         em.add_field(name=_("Users"), value=str(len(channel.members)))
     em.add_field(
         name=_("Changed roles permissions"),
         value=chat.escape(
             "\n".join(str(x) for x in changed_roles) or _("Not set"),
             formatting=True,
         ),
     )
     em.add_field(
         name=_("Mention"),
         value=f"{channel.mention}\n{chat.inline(channel.mention)}",
     )
     if isinstance(channel, discord.TextChannel):
         if channel.slowmode_delay:
             em.add_field(
                 name=_("Slowmode delay"),
                 value=_("{} seconds").format(channel.slowmode_delay),
             )
         em.add_field(name=_("NSFW"), value=bool_emojify(channel.is_nsfw()))
         if (channel.guild.me.permissions_in(channel).manage_webhooks
                 and await channel.webhooks()):
             em.add_field(name=_("Webhooks count"),
                          value=str(len(await channel.webhooks())))
     elif isinstance(channel, (discord.VoiceChannel, discord.StageChannel)):
         em.add_field(name=_("Region"),
                      value=channel.rtc_region or _("Automatic"))
         em.add_field(name=_("Bitrate"),
                      value=_("{}kbps").format(channel.bitrate / 1000))
         em.add_field(
             name=_("Users"),
             value=channel.user_limit
             and f"{len(channel.members)}/{channel.user_limit}"
             or f"{len(channel.members)}",
         )
         if isinstance(channel, discord.StageChannel):
             em.add_field(
                 name=_("Requesting to speak"),
                 value=_("{} users").format(len(
                     channel.requesting_to_speak)),
             )
     elif isinstance(channel, discord.CategoryChannel):
         em.add_field(name=_("NSFW"), value=bool_emojify(channel.is_nsfw()))
     await ctx.send(embed=em)
 async def sinfo(self, ctx, *, server: commands.GuildConverter = None):
     """Shows server information"""
     if server is None or not await self.bot.is_owner(ctx.author):
         server = ctx.guild
     afk = server.afk_timeout / 60
     try:
         widget = await server.widget()
     except (discord.Forbidden, discord.HTTPException):
         widget = SimpleNamespace(invite_url=None)
     em = discord.Embed(
         title=_("Server info"),
         description=server.description and server.description or None,
         color=server.owner.color.value and server.owner.color
         or discord.Embed.Empty,
     )
     em.add_field(name=_("Name"),
                  value=chat.escape(server.name, formatting=True))
     em.add_field(name=_("Server ID"), value=server.id)
     em.add_field(
         name=_("Exists since"),
         value=get_markdown_timestamp(server.created_at,
                                      TimestampStyle.datetime_long),
     )
     em.add_field(name=_("Region"), value=server.region)
     if server.preferred_locale:
         em.add_field(name=_("Discovery language"),
                      value=server.preferred_locale)
     em.add_field(name=_("Owner"),
                  value=chat.escape(str(server.owner), formatting=True))
     em.add_field(
         name=_("AFK timeout and channel"),
         value=_("{} min in {}").format(
             afk, chat.escape(str(server.afk_channel), formatting=True)),
     )
     em.add_field(
         name=_("Verification level"),
         value=_("None")
         if server.verification_level == discord.VerificationLevel.none else
         _("Low") if server.verification_level
         == discord.VerificationLevel.low else _("Medium") if
         server.verification_level == discord.VerificationLevel.medium else
         _("High") if server.verification_level == discord.VerificationLevel
         .high else _("Highest") if server.verification_level ==
         discord.VerificationLevel.extreme else _("Unknown"),
     )
     em.add_field(
         name=_("Explicit content filter"),
         value=_("Don't scan any messages.")
         if server.explicit_content_filter == discord.ContentFilter.disabled
         else _("Scan messages from members without a role.")
         if server.explicit_content_filter == discord.ContentFilter.no_role
         else _("Scan messages sent by all members.")
         if server.explicit_content_filter ==
         discord.ContentFilter.all_members else _("Unknown"),
     )
     em.add_field(
         name=_("Default notifications"),
         value=_("All messages") if server.default_notifications
         == discord.NotificationLevel.all_messages else
         _("Only @mentions") if server.default_notifications
         == discord.NotificationLevel.only_mentions else _("Unknown"),
     )
     em.add_field(name=_("2FA admins"),
                  value=bool_emojify(server.mfa_level))
     if server.rules_channel:
         em.add_field(
             name=_("Rules channel"),
             value=chat.escape(server.rules_channel.name, formatting=True),
         )
     if server.public_updates_channel:
         em.add_field(
             name=_("Public updates channel"),
             value=chat.escape(server.public_updates_channel.name,
                               formatting=True),
         )
     if server.system_channel:
         em.add_field(
             name=_("System messages channel"),
             value=_(
                 "**Channel:** {channel}\n"
                 "**Welcome message:** {welcome}\n"
                 "**Boosts:** {boost}").format(
                     channel=chat.escape(server.system_channel.name,
                                         formatting=True),
                     welcome=bool_emojify(
                         server.system_channel_flags.join_notifications),
                     boost=bool_emojify(
                         server.system_channel_flags.premium_subscriptions),
                 ),
             inline=False,
         )
     em.add_field(
         name=_("Stats"),
         value=_(
             "**Bot's shard:** {shard}\n"
             "**Member count:** {members}/{members_limit}\n"
             "**Role count:** {roles}/250\n"
             "**Channel count:** {channels}/500\n"
             "**Emoji count:** {emojis}/{emoji_limit}\n"
             "**Animated emoji count:** {animated_emojis}/{emoji_limit}\n"
             "**Boosters:** {boosters} ({boosts} **boosts**) (**Tier:** {tier}/3)\n"
             "**Max bitrate:** {bitrate} kbps\n"
             "**Max filesize:** {files} MB\n"
             "**Max users in voice with video:** {max_video}").format(
                 shard=server.shard_id,
                 members=server.member_count,
                 members_limit=server.max_members or "100000",
                 roles=len(server.roles),
                 channels=len(server.channels),
                 emojis=len([e for e in server.emojis if not e.animated]),
                 animated_emojis=len(
                     [e for e in server.emojis if e.animated]),
                 emoji_limit=server.emoji_limit,
                 tier=server.premium_tier,
                 boosters=len(server.premium_subscribers),
                 boosts=server.premium_subscription_count,
                 bitrate=server.bitrate_limit / 1000,
                 files=server.filesize_limit / 1048576,
                 max_video=server.max_video_channel_users,
             ),
         inline=False,
     )
     if server.features:
         em.add_field(
             name=_("Features"),
             value="\n".join(
                 sorted(
                     _(GUILD_FEATURES.get(f, f)) for f in server.features)).
             format(
                 banner=server.banner
                 and f" [🔗]({server.banner_url_as(format='png')})" or "",
                 splash=server.splash
                 and f" [🔗]({server.splash_url_as(format='png')})" or "",
                 discovery=server.discovery_splash and
                 f" [🔗]({server.discovery_splash_url_as(format='png')})"
                 or "",
             ),
             inline=False,
         )
     roles_str = _("**Everyone role:** {}").format(server.default_role)
     if boost_role := server.premium_subscriber_role:
         roles_str += "\n" + _("**Booster role:** {}").format(boost_role)
    async def uinfo(self, ctx, *, member: discord.Member = None):
        """Information on a user"""
        if member is None:
            member = ctx.message.author
        em = discord.Embed(
            title=chat.escape(str(member), formatting=True),
            color=member.color.value and member.color or discord.Embed.Empty,
        )
        if member.nick:
            em.add_field(name=_("Nickname"), value=member.nick)
        else:
            em.add_field(name=_("Name"), value=member.name)
        em.add_field(
            name=_("Client"),
            value=f"📱: {str(member.mobile_status).capitalize()}\n"
            f"🖥: {str(member.desktop_status).capitalize()}\n"
            f"🌎: {str(member.web_status).capitalize()}",
        )

        em.add_field(
            name=_("Joined server"),
            value=get_markdown_timestamp(member.joined_at,
                                         TimestampStyle.datetime_long),
        )
        em.add_field(name="ID", value=member.id)
        em.add_field(
            name=_("Exists since"),
            value=get_markdown_timestamp(member.created_at,
                                         TimestampStyle.datetime_long),
        )
        if member.color.value:
            em.add_field(name=_("Color"), value=member.colour)
        if member.premium_since:
            em.add_field(
                name=_("Boosted server"),
                value=get_markdown_timestamp(member.premium_since,
                                             TimestampStyle.datetime_long),
            )
        em.add_field(name=_("Bot?"), value=bool_emojify(member.bot))
        em.add_field(name=_("System?"), value=bool_emojify(member.system))
        em.add_field(
            name=_("Server permissions"),
            value=
            "[{0}](https://cogs.fixator10.ru/permissions-calculator/?v={0})".
            format(member.guild_permissions.value),
        )
        if member.voice:
            em.add_field(name=_("In voice channel"),
                         value=member.voice.channel.mention)
        em.add_field(
            name=_("Mention"),
            value=f"{member.mention}\n{chat.inline(member.mention)}",
            inline=False,
        )
        if roles := [
                role.name for role in member.roles if not role.is_default()
        ]:
            em.add_field(
                name=_("Roles"),
                value=chat.escape("\n".join(roles), formatting=True),
                inline=False,
            )