Exemplo n.º 1
0
 async def unload(self, ctx, extension):
     try:
         self.bot.unload_extension(f"main.cogs.{extension}")
         print(f"{extension} unloaded")
         response = emb.gen_embed_orange("System Alert", f"{extension} unloaded")
         await ctx.send(embed=response)
     except Exception as e:
         log.warning(e)
         log.error(traceback.format_exc())
         response = emb.gen_embed_orange("System Alert", f"{extension} failed to load")
         await ctx.send(embed=response)
Exemplo n.º 2
0
    async def on_message_delete(self, message):
        # Validation
        regex = "^[^\"\'\.\w]"  # noqa
        if re.search(regex, message.content):
            return
        if message.author.bot:
            return
        if len(message.content) < 2:
            return

        # Getting Variables
        author = message.author
        oc = message.channel
        content = message.content
        guild = message.guild
        attachment = message.attachments
        if attachment != []:
            attachment = message.attachments[0].proxy_url
        else:
            attachment = None

        # Sending to log channel
        try:
            cat = utils.get(guild.categories, name='Moderation')
            if cat is None:
                cat = await guild.create_category('Moderation')

            send_channel = utils.get(guild.text_channels, name='modlog')
            if send_channel is None:
                send_channel = await guild.create_text_channel('modlog',
                                                               category=cat)
            limit = 1024
            content = [
                content[i:i + limit] for i in range(0, len(content), limit)
            ]

            # Creating Embed
            e = emb.gen_embed_orange("Deleted Message Log", "")
            if attachment:
                e.add_field(name='Attachments', value=attachment, inline=False)

            for chunk in content:
                e.add_field(name='Channel', value=oc, inline=True)
                e.add_field(name='Author', value=author, inline=True)
                e.add_field(name='Content', value=chunk, inline=False)

                await send_channel.send(embed=e)
                e.clear_fields()

        except Exception as e:
            log.warning(e)
            log.error(traceback.format_exc())
Exemplo n.º 3
0
    async def unban(self, ctx, member: discord.Member, *, reason=None):
        """Unbans a member from the server

        `unban 'username'/@mention/id reason`"""

        if reason is None:
            reason = f"Unbanned by {ctx.author}.\nID: {ctx.author.id}"

        e = emb.gen_embed_white(f'Unbanned {member}', reason)

        try:
            await ctx.guild.unban(member, reason=reason)
            await ctx.message.delete()
            await ctx.send(embed=e)
        except Exception as e:
            log.warning(e)
            log.error(traceback.format_exc())
            embed = emb.gen_embed_orange('Error', e)
            await ctx.send(embed=embed)
Exemplo n.º 4
0
    async def on_member_update(self, before, after):
        # Validation
        if before.bot:
            return

        # Get variables
        member = before.name
        id = before.id
        oldNick = before.nick
        newNick = after.nick
        guild = before.guild

        if oldNick is None:
            oldNick = before.name
        if newNick is None:
            newNick = before.name

        if oldNick == newNick:
            return

        #  Logging to channel
        try:
            cat = utils.get(guild.categories, name='Moderation')
            if cat is None:
                cat = await guild.create_category('Moderation')

            send_channel = utils.get(guild.text_channels, name='modlog')
            if send_channel is None:
                send_channel = await guild.create_text_channel('modlog',
                                                               category=cat)

            # Creating Embed
            e = emb.gen_embed_orange(member, "")
            e.add_field(name='User ID', value=id, inline=True)
            e.add_field(name='Old Nickname', value=oldNick, inline=False)
            e.add_field(name='New Nickname', value=newNick, inline=False)
            e.set_thumbnail(url=before.avatar_url)

            await send_channel.send(embed=e)
        except Exception as e:
            log.warning(e)
            log.error(traceback.format_exc())
Exemplo n.º 5
0
    async def kick(self, ctx, member: discord.Member, *, reason=None):
        """Kicks a member from the server.

        `kick 'username'/@mention/id reason`"""

        if reason is None:
            reason = f"Kicked by {ctx.author}\nID: {ctx.author.id}"

        e = emb.gen_embed_white(f'Kicked {member}', reason)
        e.set_thumbnail(url=member.avatar_url)

        try:
            await ctx.guild.kick(member, reason=reason)
            await ctx.message.delete()
            await ctx.send(embed=e)
        except Exception as e:
            log.warning(e)
            log.error(traceback.format_exc())
            embed = emb.gen_embed_orange('Error', e)
            await ctx.send(embed=embed)
Exemplo n.º 6
0
    async def userinfo(self, ctx, *, member: discord.Member):
        """Displays information about a user

        `userinfo 'username'/@mention/id`"""

        try:
            # Variables
            conn = self.bot.pool
            roles = [
                role.name.replace('@', '@\u200b')
                for role in getattr(member, 'roles', [])
            ]
            shared = sum(
                g.get_member(member.id) is not None for g in self.bot.guilds)

            embed = discord.Embed()
            embed.set_author(name=member)
            embed.add_field(name='ID', value=member.id, inline=True)
            embed.add_field(name='Servers', value=shared, inline=True)
            embed.add_field(name='Joined',
                            value=getattr(member, 'joined_at', None),
                            inline=False)
            embed.add_field(name='Created',
                            value=member.created_at,
                            inline=False)

            voice = getattr(member, 'voice', None)
            if voice is not None:
                vc = voice.channel
                other_people = len(vc.members) - 1
                voice = f'{vc.name} with {other_people} others' if other_people else f'{vc.name} by themselves'
                embed.add_field(name='Voice', value=voice, inline=False)

            if roles:
                embed.add_field(name='Roles',
                                value=', '.join(roles)
                                if len(roles) < 10 else f'{len(roles)} roles',
                                inline=False)

            # Get last message
            sql = """SELECT * FROM lb WHERE server_id= $1 AND user_id = $2; """
            data = await conn.fetchrow(sql, member.guild.id, member.id)
            if data is not None:
                last_msg = data[2]
                last_msg = last_msg.strftime("%c")
                embed.add_field(name="Last Message at",
                                value=last_msg,
                                inline=False)

            color = member.colour
            if color.value:
                embed.color = color
            else:
                embed.color = 0xf2f6f7

            if member.avatar:
                embed.set_thumbnail(url=member.avatar_url)

            if isinstance(member, discord.User):
                embed.set_footer(text='This member is not in this server.')

            await ctx.send(embed=embed)

        except Exception as e:
            log.warning(e)
            log.error(traceback.format_exc())
            await ctx.send(embed=emb.gen_embed_orange('Error', e))
Exemplo n.º 7
0
    async def on_message_edit(self, before, after):

        # Validation
        if before.author.bot:
            return
        elif after.edited_at is not None:
            if (after.edited_at - before.created_at).total_seconds() < 20:
                return
        elif before.content == after.content:
            return

        # Getting Variables
        author = before.author
        oc = before.channel
        oldContent = before.content
        newContent = after.content
        guild = after.guild
        attachment = after.attachments
        if attachment != []:
            attachment = after.attachments[0].proxy_url
        else:
            attachment = None

        # Logging to channel
        try:
            cat = utils.get(guild.categories, name='Moderation')
            if cat is None:
                cat = await guild.create_category('Moderation')

            send_channel = utils.get(guild.text_channels, name='modlog')
            if send_channel is None:
                send_channel = await guild.create_text_channel('modlog',
                                                               category=cat)

            limit = 1024
            oldContent = [
                oldContent[i:i + limit]
                for i in range(0, len(oldContent), limit)
            ]
            newContent = [
                newContent[i:i + limit]
                for i in range(0, len(newContent), limit)
            ]

            # Creating Embed
            e = emb.gen_embed_orange("Edited Message Log", "")
            if attachment:
                e.add_field(name='Attachments', value=attachment, inline=False)

            for elem, chunk in enumerate(oldContent):
                e.add_field(name='Channel', value=oc, inline=True)
                e.add_field(name='Author', value=author, inline=True)
                e.add_field(name='Before', value=chunk, inline=False)
                e.add_field(name='After', value=newContent[elem], inline=False)

                await send_channel.send(embed=e)
                e.clear_fields()

        except Exception as e:
            log.warning(e)
            log.error(traceback.format_exc())