Ejemplo n.º 1
0
    async def mute(self, ctx, member: discord.Member, time, *, reason):
        """
        Mutes a member for the given time and reason
        Usage: .mute <member> <time> <reason>

        :param ctx: context object
        :param member: member to mute
        :param time: time to mute for
        :param reason: reason for the mute (dm'ed to the user)
        """
        muted_role = ctx.guild.get_role(615956736616038432)

        # Is user already muted
        if muted_role in member.roles:
            await ctx.send("This member is already muted")
            return

        # Check role hierarchy
        if ctx.author.top_role.position <= member.top_role.position:
            await ctx.send("You're not high enough in the role hierarchy to do that.")
            return

        username = member.name + "#" + str(member.discriminator)

        seconds = pytimeparse.parse(time)
        if seconds is None:
            await ctx.send("Not a valid time, try again")

        delta = timedelta(seconds=seconds)
        if len(reason) < 1:
            await ctx.send("You must include a reason for the mute")
            return

        Config.add_mute(member, datetime.now() + timedelta(seconds=seconds))

        mute_time = time_delta_string(datetime.utcnow(), datetime.utcnow() + delta)

        mute_embed = discord.Embed(
            title="Member muted",
            color=0xbe4041,
            description=(
                    "**Muted:** <@" + str(member.id) + ">\n**Time:** " + mute_time + "\n**__Reason__**\n> " + reason +
                    "\n\n**Muter:** <@" + str(ctx.author.id) + ">"
            )
        )

        mute_embed.set_author(name=member.name + "#" + member.discriminator, icon_url=member.avatar_url)
        mute_embed.set_footer(text="ID: " + str(member.id))
        mute_embed.timestamp = datetime.utcnow()

        await member.add_roles(muted_role)
        await ctx.send("**Muted** user **" + username + "** for **" + mute_time + "** for: **" + reason + "**")
        if Config.guilds[ctx.guild]["logging"]["overwrite_channels"]["mod"] is not None:
            await Config.guilds[ctx.guild]["logging"]["overwrite_channels"]["mod"].send(embed=mute_embed)
        await member.send(
            "**You were muted in the " + ctx.guild.name + " for " + mute_time + ". Reason:**\n> " +
            reason + "\n\nYou can respond here to contact staff."
        )

        await self.mute_helper(member, seconds, muted_role)
Ejemplo n.º 2
0
async def on_ready():
    """
    Load state and update information since last run
    """
    if Config.status is not None:
        await gompei.change_presence(
            activity=discord.Game(name=Config.status, start=datetime.utcnow()))

    await Config.set_client(gompei)
    await Config.load_settings()

    print("Logged on as {0}".format(gompei.user))
    if Config.dm_channel is not None:
        start_embed = discord.Embed(title="Bot started", color=0x43b581)
        start_embed.set_author(name=gompei.user.name + "#" +
                               gompei.user.discriminator,
                               icon_url=gompei.user.avatar_url)
        if Config.close_time is None:
            start_embed.description = "**Downtime:** NaN"
        else:
            start_embed.description = "**Downtime:** " + time_delta_string(
                Config.close_time, datetime.now())

        start_embed.set_footer(text="ID: " + str(gompei.user.id))
        start_embed.timestamp = datetime.utcnow()

        await Config.dm_channel.send(embed=start_embed)

    Config.clear_close_time()
Ejemplo n.º 3
0
    async def emoji_info(self, emoji: typing.Union[discord.Emoji, discord.PartialEmoji]):
        """
        Dumps emoji info into an embed

        :param emoji: Emoji to gather info for
        """
        embed = discord.Embed(
            title="Emoji Info",
            colour=discord.Colour(0x43b581),
            description=(
                    "**[Image](" + str(emoji.url) + ")**" +
                    "\n**Name:** " + emoji.name
            )
        )

        if emoji.animated:
            embed.description += r"\n**Format:** \<a:" + emoji.name + ":" + str(emoji.id) + ">"
        else:
            embed.description += r"\n**Format:** \<:" + emoji.name + ":" + str(emoji.id) + ">"
        embed.description += "\n**Animated:** " + str(emoji.animated)
        if isinstance(emoji, discord.Emoji):
            embed.description += "\n**Available:** " + str(emoji.available)
            embed.description += "\n**Created at:** " + emoji.created_at.strftime("%m-%d-%y %H:%M:%S") + " UTC" + \
                                 "\n(" + time_delta_string(emoji.created_at, datetime.utcnow()) + " ago)"

        embed.set_footer(text=str(emoji.id))
        embed.timestamp = datetime.utcnow()

        return embed
Ejemplo n.º 4
0
    async def role_info(self, role: discord.Role):
        """
        Dumps role info into the embed

        :param role: Role to gather info for
        """
        embed = discord.Embed(
            title="Role Info",
            colour=role.colour,
            description=(
                    "**Name:** " + role.name +
                    "\n**Mention:** " + role.mention +
                    "\n**Members:** " + str(len(role.members)) +
                    "\n**(R,G,B):** " + str(role.color.to_rgb()) +
                    "\n**Hoisted:** " + str(role.hoist) +
                    "\n**Mentionable:** " + str(role.mentionable) +
                    "\n**Position:** " + str(role.position) +
                    "\n**Created:** " + role.created_at.strftime("%m-%d-%y %H:%M:%S") + " UTC" +
                    "\n(" + time_delta_string(role.created_at, datetime.utcnow()) + " ago)"
            )
        )

        permissions = []
        values = []

        for permission in role.permissions:
            if permission[1] is not None:
                if permission[1] is True:
                    permissions.append(permission[0].replace("_", " ").title())
                    values.append("✔")

        if len(permissions) > 0:
            max_length = len(max(permissions, key=len))

            permission_values = "```"
            for i in range(0, len(permissions)):
                permission_values += permissions[i] + (" " * (max_length - len(permissions[i]))) + " " + values[
                    i] + "\n"
            permission_values += "```"

            embed.add_field(name="Permissions", value=permission_values, inline=True)

        if len(embed.description) > 2048:
            embed.description = embed.description[0:2047]

        embed.set_footer(text=str(role.id))
        embed.timestamp = datetime.utcnow()

        return embed
Ejemplo n.º 5
0
    async def set_time_requirement(self, ctx, *, time: str):
        """
        Sets the number of verification messages required to become a member

        :param ctx: Context object
        :param time: Time required to get verified
        """
        seconds = pytimeparse.parse(time)
        if seconds is None:
            await ctx.send("Not a valid time, try again")

        delta = timedelta(seconds=seconds)

        Config.set_member_time_req(ctx.guild, delta)
        await ctx.send("Updated the required time to become verified to " +
                       time_delta_string(datetime.now(),
                                         datetime.now() + delta))
Ejemplo n.º 6
0
    async def jail(self, ctx, member: discord.Member, time: str, *, reason: str):
        """
        Jails a member from the server by removing all of their roles
        Usage: .jail <member> <time> <reason>

        :param ctx: Context object
        :param member: Member to jail
        :param time: Time to jail for
        :param reason: Reason for the jail
        """
        # Is user already jailed
        if member in Config.guilds[ctx.guild]["administration"]["jails"]:
            await ctx.send("This member is already jailed")
            return

        # Check role hierarchy
        if ctx.author.top_role.position <= member.top_role.position:
            await ctx.send("You're not high enough in the role hierarchy to do that.")
            return

        roles = member.roles

        seconds = pytimeparse.parse(time)
        if seconds is None:
            await ctx.send("Not a valid time, try again")

        delta = timedelta(seconds=seconds)
        jail_time = time_delta_string(datetime.utcnow(), datetime.utcnow() + delta)

        if len(reason) < 1:
            await ctx.send("You must include a reason for the jail")
            return

        Config.add_jail(member, datetime.now() + timedelta(seconds=seconds), roles)

        jail_embed = discord.Embed(
            title="Member jailed",
            color=0xbe4041,
            description=(
                    "**Muted:** <@" + str(member.id) + ">\n**Time:** " + jail_time + "\n**__Reason__**\n> " + reason +
                    "\n\n**Muter:** <@" + str(ctx.author.id) + ">"
            )
        )

        jail_embed.set_author(name=member.name + "#" + member.discriminator, icon_url=member.avatar_url)
        jail_embed.set_footer(text="ID: " + str(member.id))
        jail_embed.timestamp = datetime.utcnow()

        if member.premium_since is None:
            await member.edit(roles=[])
        else:
            await member.edit(roles=[Config[ctx.guild]["nitro_role"]])

        await member.send(
            "You have been locked out of the server for " + jail_time + ". Reason:\n> " + reason +
            "\n\nYou can respond here to contact staff."
        )

        if Config.guilds[ctx.guild]["logging"]["overwrite_channels"]["mod"] is not None:
            await Config.guilds[ctx.guild]["logging"]["overwrite_channels"]["mod"].send(embed=jail_embed)
        await ctx.send(
            "**Jailed** user **" + member.display_name + "** for **" + jail_time + "** for: **" + reason + "**"
        )
        await self.jail_helper(member, seconds, roles)
Ejemplo n.º 7
0
    async def channel_info(self, channel: typing.Union[discord.TextChannel, discord.VoiceChannel, discord.CategoryChannel]):
        """
        Dumps channel info into the embed

        :param channel: Channel to gather info for
        """
        f_description = "**Name:** " + channel.name

        # If a text channel
        if isinstance(channel, discord.TextChannel):
            title = "Text Channel Info"
            f_description += "\n**Mention:** " + channel.mention
            if channel.topic is not None:
                f_description += "\n**Description:** " + channel.topic
        # If a voice channel
        elif isinstance(channel, discord.VoiceChannel):
            title = "Voice Channel Info"
            f_description += "\n**Bitrate:** " + str(channel.bitrate) + \
                             "\n**User Limit:** " + str(channel.user_limit)
        else:
            title = "Category Info"
            if len(channel.text_channels) > 0:
                f_description += "\n**__Text Channels__**"
                for text_channel in channel.text_channels:
                    f_description += "\n" + text_channel.mention
            if len(channel.voice_channels) > 0:
                f_description += "\n**__Voice Channels__**"
                for voice_channel in channel.voice_channels:
                    f_description += "\n" + voice_channel.mention

        if channel.category is not None:
            f_description += "\n**Category:** " + str(channel.category.name)

        f_description += "\n**Position:** " + str(channel.position) + \
                         "\n**Created:** " + channel.created_at.strftime("%m-%d-%y %H:%M:%S") + \
                         " UTC\n(" + time_delta_string(channel.created_at, datetime.utcnow()) + " ago)" + \
                         "\n\n**__Overwrites__\n**"

        embed = discord.Embed(
            title=title,
            colour=discord.Colour(0x43b581),
            description=f_description
        )

        roles = []
        members = []
        for target in channel.overwrites:
            if isinstance(target, discord.Role):
                roles.append(target)
            else:
                members.append(target)

        targets = members + sorted(roles, key=lambda a: a.position, reverse=True)

        for target in targets:
            permissions = []
            values = []

            for permission in channel.overwrites[target]:
                if permission[1] is not None:
                    permissions.append(permission[0].replace("_", " ").title())
                    if permission[1] is True:
                        values.append("✔")
                    else:
                        values.append("✘")

            if len(permissions) > 0:
                max_length = len(max(permissions, key=len))

                f_description = "```"
                for i in range(0, len(permissions)):
                    f_description += permissions[i] + (" " * (max_length - len(permissions[i]))) + " " + values[i] + "\n"
                f_description += "```"

                embed.add_field(name=target.name, value=f_description, inline=True)

        if len(embed.description) > 2048:
            embed.description = embed.description[0:2047]

        embed.set_footer(text=str(channel.id))
        embed.timestamp = datetime.utcnow()

        return embed
Ejemplo n.º 8
0
    async def guild_info(self, guild: discord.Guild):
        """
        Dumps guild info into an embed

        :param guild: Guild to gather info for
        """
        if guild.mfa_level == 1:
            description = "**2FA:** Required"
        else:
            description = "**2FA:** Not Required"

        embed = discord.Embed(
            title=guild.name,
            colour=discord.Colour(0x43b581),
            description=(
                    description +
                    "\n**Default Notifications: ** " + str(guild.default_notifications)[18:].replace("_", " ").title() +
                    "\n**Description: ** " + str(guild.description) +
                    "\n**Explicit Content Filter:** " + str(guild.explicit_content_filter).replace("_", " ").title() +
                    "\n**Owner:** " + "<@" + str(guild.owner_id) + ">" +
                    "\n**Region:** " + str(guild.region).replace("-", " ").title() +
                    "\n**Verification Level:** " + str(guild.verification_level).title()
            )
        )

        resource_values = "[Icon](" + str(guild.icon_url) + ")"
        if guild.banner is not None:
            resource_values += "\n[Banner](" + str(guild.banner_url) + ")"
        if guild.splash is not None:
            resource_values += "\n[Splash](" + str(guild.splash_url) + ")"
        if guild.discovery_splash is not None:
            resource_values += "\n[Discovery Splash](" + str(guild.discovery_splash_url) + ")"

        feature_values = ""
        for feature in guild.features:
            feature_values += feature.replace("_", " ").title() + "\n"
        if feature_values == "":
            feature_values = "None"

        if guild.premium_subscription_count >= 30:
            boosts = "Level 3\n" + str(guild.premium_subscription_count) + "/30 boosts"
        elif guild.premium_subscription_count >= 15:
            boosts = "Level 2\n" + str(guild.premium_subscription_count) + "/30 boosts"
        elif guild.premium_subscription_count >= 2:
            boosts = "Level 1\n" + str(guild.premium_subscription_count) + "/15 boosts"
        else:
            boosts = "Level 0\n" + str(guild.premium_subscription_count) + "/2 boosts"

        humans = bots = 0
        online = idle = dnd = offline = 0
        animated = static = 0
        playing = streaming = listening = watching = competing = 0

        for member in guild.members:
            # Counting humans vs. bots
            if member.bot:
                bots += 1
            else:
                humans += 1

            # Counting statuses
            if member.status is discord.Status.online:
                online += 1
            elif member.status is discord.Status.idle:
                idle += 1
            elif member.status is discord.Status.dnd:
                dnd += 1
            elif member.status is discord.Status.offline:
                offline += 1

            play = stream = listen = watch = compete = False

            # Counting activities
            for activity in member.activities:
                if isinstance(activity, discord.activity.Spotify):
                    if not listen:
                        listen = True
                        listening += 1
                elif isinstance(activity, discord.activity.Game):
                    if not play:
                        play = True
                        playing += 1
                elif isinstance(activity, discord.activity.Streaming):
                    if not stream:
                        stream = True
                        streaming += 1
                elif isinstance(activity, discord.activity.Activity):
                    if activity.type is discord.ActivityType.playing:
                        if not play:
                            play = True
                            playing += 1
                    elif activity.type is discord.ActivityType.streaming:
                        if not stream:
                            stream = True
                            streaming += 1
                    elif activity.type is discord.ActivityType.listening:
                        if not listen:
                            listen = True
                            listening += 1
                    elif activity.type is discord.ActivityType.watching:
                        if not watch:
                            watch = True
                            watching += 1
                    elif activity.type is discord.ActivityType.competing:
                        if not compete:
                            compete = True
                            competing += 1

        # Counting emojis
        for emoji in guild.emojis:
            if emoji.animated:
                animated += 1
            else:
                static += 1

        embed.add_field(name="Resources", value=resource_values, inline=True)
        embed.add_field(name="Features", value=feature_values, inline=True)
        embed.add_field(name="Boosts", value=boosts, inline=True)
        embed.add_field(
            name="Members",
            value=(
                    "Total: " + str(guild.member_count) +
                    "\nHumans: " + str(humans) +
                    "\nBots: " + str(bots)
            ),
            inline=True
        )
        embed.add_field(
            name="Statuses",
            value=(
                    ":green_circle: " + str(online) +
                    "\n:yellow_circle: " + str(idle) +
                    "\n:red_circle: " + str(dnd) +
                    "\n:white_circle: " + str(offline)
            ),
            inline=True
        )
        embed.add_field(
            name="Activities",
            value=(
                    "\nCompeting: " + str(competing) +
                    "\nListening: " + str(listening) +
                    "\nPlaying: " + str(playing) +
                    "\nStreaming: " + str(streaming) +
                    "\nWatching: " + str(watching)
            ),
            inline=True
        )
        embed.add_field(
            name="Channels",
            value=(
                    "Text Channels: " + str(len(guild.text_channels)) +
                    "\nVoice Channels: " + str(len(guild.voice_channels)) +
                    "\nCategories: " + str(len(guild.categories))
            ),
            inline=True
        )
        embed.add_field(
            name="Emojis",
            value=(
                    "Total: " + str(len(guild.emojis)) +
                    "\nAnimated: " + str(animated) + " / " + str(guild.emoji_limit) +
                    "\nStatic: " + str(static) + " / " + str(guild.emoji_limit)
            ),
            inline=True
        )
        embed.add_field(name="Roles", value=str(len(guild.roles)) + " roles", inline=True)
        embed.add_field(
            name="Created",
            value=(
                    guild.created_at.strftime("%m-%d-%y %H:%M:%S") + " UTC" +
                    "\n(" + time_delta_string(guild.created_at, datetime.utcnow()) + " ago)"
            ),
            inline=True
        )
        # Playing, Listening, Watching, Streaming ACTIVITIES

        embed.set_thumbnail(url=guild.icon_url)
        embed.set_footer(text=str(guild.id))
        embed.timestamp = datetime.utcnow()

        return embed
Ejemplo n.º 9
0
    async def user_info(self, user: [discord.Member, discord.User]):
        """
        Dumps user info into the embed

        :param user: User to gather info for
        """
        embed = discord.Embed(
            description=(
                    "[Avatar](" + str(user.avatar_url) + ")" +
                    "\n**Mention:** <@" + str(user.id) + ">"
            )
        )

        if isinstance(user, discord.Member):
            embed.title = "Member info"
            embed.description += "\n**Display Name:** " + user.display_name

            role_value = ""
            for role in user.roles[1:]:
                role_value = "<@&" + str(role.id) + "> " + role_value

            if role_value == "":
                role_value = "None"

            embed.colour = user.colour
            embed.add_field(name="Roles", value=role_value, inline=True)
            embed.add_field(
                name="Created at",
                value=(
                        user.created_at.strftime("%m-%d-%y %H:%M:%S") + " UTC" +
                        "\n(" + time_delta_string(user.created_at, datetime.utcnow()) + " ago)"
                ),
                inline=True
            )
            embed.add_field(
                name="Joined at",
                value=(
                        user.joined_at.strftime("%m-%d-%y %H:%M:%S") + " UTC" +
                        "\n(" + time_delta_string(user.joined_at, datetime.utcnow()) + " ago)"
                ),
                inline=True
            )
        else:
            embed.title = "User info"
            embed.colour = discord.Colour(0x43b581)
            embed.add_field(
                name="Created at",
                value=(
                        user.created_at.strftime("%m-%d-%y %H:%M:%S") + " UTC" +
                        "\n(" + time_delta_string(user.created_at, datetime.utcnow()) + " ago)"
                ),
                inline=True
            )

        if len(embed.description) > 2048:
            embed.description = embed.description[0:2047]

        embed.set_author(name=user.name + "#" + user.discriminator, icon_url=user.avatar_url)
        embed.set_footer(text=str(user.id))
        embed.timestamp = datetime.utcnow()

        return embed