Exemplo n.º 1
0
 async def report(self, ctx, member: discord.Member, *, report: str = None):
     if len(ctx.message.attachments) < 1:
         msg = f'Your negative review is incomplete. Please attach a screenshot or picture verifying your claim.'
         try:
             await ctx.author.send(embed=tools.single_embed(msg))
         except discord.Forbidden:
             await ctx.send(embed=tools.single_embed(msg), delete_after=5)
         await ctx.message.delete()
         return
     channel = db.get_administrative(ctx.guild)
     embed = discord.Embed(title='Report', description=report, color=discord.Color.red())
     reporter = f'Name: {ctx.author.mention} ({ctx.author})\n' \
                f'Joined: {tools.format_date(ctx.author.joined_at)}\n' \
                f'Created: {tools.format_date(ctx.author.joined_at)}\n' \
                f'Context: {ctx.channel.mention}\n' \
                f'[Jump to Message]({ctx.message.jump_url})'
     embed.add_field(name='Reporter', value=reporter)
     reported = f'Name: {member.mention} ({member})\n' \
                f'Joined: {tools.format_date(member.joined_at)}\n' \
                f'Created: {tools.format_date(member.joined_at)}\n' \
                f'ID: {member.id}'
     embed.add_field(name='Reported', value=reported)
     try:
         url = ctx.message.attachments[0].url
         embed.set_image(url=url)
     except IndexError:
         print('index error')
     embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
     await channel.send(embed=embed)
     await ctx.message.delete()
     await ctx.send(embed=tools.single_embed(f'Your report has been delivered. Thank you.'), delete_after=5)
Exemplo n.º 2
0
    async def settings(self, ctx):
        if ctx.invoked_subcommand is None:
            prefix = database.get_prefix(ctx.guild)[0]
            spam = database.get_spam(ctx.guild)
            autorole = database.get_autorole(ctx.guild)
            administrative = database.get_administrative(ctx.guild)
            review_channel = database.get_review_channel(ctx.guild)
            # get cog status
            admin = database.admin_cog(ctx.guild)
            rep = database.rep_cog(ctx.guild)
            karma = database.karma_cog(ctx.guild)
            mw = database.mw_cog(ctx.guild)
            # assign on/off values
            cogs = [admin, rep, karma, mw]
            for c in range(len(cogs)):
                if cogs[c] is True:
                    cogs[c] = 'On'
                else:
                    cogs[c] = 'Off'

            embed = discord.Embed(title='Settings', color=discord.Color.blue())
            embed.add_field(name='Prefix', value=f'`{prefix}`')
            embed.add_field(name='Autorole', value=autorole)
            msg = f'Spam: {spam.mention}\n'\
                  f'Admin: {administrative.mention}\n'\
                  f'Review (rep): {review_channel.mention}'
            embed.add_field(name='Channel Redirects', value=msg, inline=False)
            msg = f'Admin: `{cogs[0]}`\nRep: `{cogs[1]}`\nKarma: `{cogs[2]}`\n~~MW~~: `{cogs[3]}`'
            embed.add_field(name='Cogs', value=msg, inline=False)
            embed.set_thumbnail(url=ctx.guild.icon_url)
            await ctx.send(embed=embed)
Exemplo n.º 3
0
    async def check_warnings(self, message):
        def check(react, user):
            return react.message.id == cache_msg.id and user.permissions_in(
                admin_channel).kick_members

        # if member's warnings are 2 or greater, commence a vote to kick
        warnings, messages = database.get_warnings(message.author)
        fmt = [
            f'{m[4]} - {m[3]} *Issuer: {discord.utils.get(message.author.guild.members, id=m[5]).display_name}'
            for m in messages
        ]
        if warnings >= 2:
            admin_channel = database.get_administrative(message.guild)
            msg = f'**{message.author.display_name}** has reached `{warnings}` warnings. Should they be kicked?\n' \
                  f'__Past Warnings__\n' + '\n'.join(fmt)
            embed = discord.Embed(color=discord.Color.red(), description=msg)
            embed.set_thumbnail(url=message.author.avatar_url)
            msg = await admin_channel.send(embed=embed)
            await msg.add_reaction('✔')
            await msg.add_reaction('❌')
            await asyncio.sleep(1)

            cache_msg = await admin_channel.fetch_message(msg.id)
            yes = 0
            while yes < 4:
                reaction, member = await self.client.wait_for('reaction_add',
                                                              check=check)
                if reaction.emoji == '✔':
                    yes = reaction.count
            msg = f'You have been kicked from {message.guild.name}. The last warning was: "{message}"'
            await message.author.kick(reason=msg)
            await admin_channel.send(embed=tools.single_embed_neg(
                f'{message.author.display_name} has been kicked.'))
Exemplo n.º 4
0
    async def warn(self, ctx, member: discord.Member, *, message: str = None):
        if not await self.admin_cog_on(ctx):
            return

        def check(react, user):
            return admin_channel == react.message.channel and not user.bot

        database.add_warning(member, message, ctx.author)
        warnings, messages = database.get_warnings(member)
        fmt = [f'{m[4]} - {m[3]} *Issuer: {discord.utils.get(ctx.guild.members, id=m[5]).display_name}' for m in messages]

        msg = f'You have received a warning from an administrator or mod in {ctx.guild.name}.\n> "{message}"'
        try:
            await member.send(embed=tools.single_embed_neg(msg))
        except discord.Forbidden:
            spam = database.get_spam(ctx.guild)
            await spam.send(embed=f'{member.mention}: {msg}')

        embed = discord.Embed(color=discord.Color.red(), description=f'{member.mention} has been warned:\n"{message}"')
        embed.set_thumbnail(url=member.avatar_url)
        await ctx.send(embed=embed)

        if warnings >= 2:
            admin_channel = database.get_administrative(ctx.guild)
            msg = f'**{member.display_name}** has reached `{warnings}` warnings. Should they be kicked?\n' \
                  f'__Past Warnings__\n' + '\n'.join(fmt)
            embed = discord.Embed(color=discord.Color.red(), description=msg)
            embed.set_thumbnail(url=member.avatar_url)
            msg = await admin_channel.send(embed=embed)
            await msg.add_reaction('✔')
            await msg.add_reaction('❌')
            yes = 0
            no = 0
            limit = 4
            while True:
                try:
                    reaction, reactor = await self.client.wait_for('reaction_add', check=check, timeout=28800)
                    if reaction.emoji == '✔':
                        yes = reaction.count
                        if yes >= limit:
                            break
                    if reaction.emoji == '❌':
                        no = reaction.count
                        if no >= limit:
                            break
                except asyncio.TimeoutError:
                    embed.add_field(name='Timeout', value='The vote has timed out.')
                    await msg.edit(embed=embed)
                    await msg.clear_reactions()
                    return
            if yes > no:
                await member.kick(reason=f'You have been kicked from {ctx.guild.name}. The last warning was: "{message}"')
                embed.add_field(name='Vote completed', value=f'{member.display_name} has been kicked.')
                await msg.edit(embed=embed)
                await msg.clear_reactions()
            if no > yes:
                embed.add_field(name='Vote completed', value=f'{member.display_name} has been voted to stay.')
                await msg.edit(embed=embed)
                await msg.clear_reactions()
Exemplo n.º 5
0
 async def autorole(self, ctx, role: discord.Role = None):
     if not await self.admin_cog_on(ctx):
         return
     admin_channel = database.get_administrative(ctx.guild)
     if role is None:
         database.update_autorole(ctx.guild, role)
         await admin_channel.send(embed=tools.single_embed(f'Autorole set to `none`'))
     else:
         database.update_autorole(ctx.guild, role)
         await admin_channel.send(embed=tools.single_embed(f'Autorole set to `{role}`'))
Exemplo n.º 6
0
    async def reset(self, ctx, member: discord.Member, *, message: str = None):
        if not await self.rep_cog_on(ctx):
            return
        if message is None:
            message = 'No additional information given.'

        if not database.in_members_table(ctx.author):
            database.add_member(ctx.author)

        pos, neg = database.get_rep(member)
        database.reset(member)

        # staff_support_channel = self.client.get_channel(694036188813721610)
        staff_support_channel = database.get_administrative(ctx.guild)
        await staff_support_channel.send(embed=tools.single_embed(
            f'**{ctx.author.display_name}** reset '
            f'**{member.display_name}\'s** reviews to 0.\n'
            f'{member.display_name}\'s original score was {pos} pos and {neg} neg.\n'
            f'Log: {message}'))
Exemplo n.º 7
0
    async def neg(self, ctx, member: discord.Member, *, message: str):
        # take message from user and send to staff support
        if await self.can_bypass_cooldown(ctx):
            self.neg.reset_cooldown(ctx)
        if not await self.rep_cog_on(ctx):
            return
        if ctx.author == member:
            msg = f'You cannot give yourself a review, {ctx.author.display_name}. :pig: *squee!*'
            await ctx.send(embed=tools.single_embed(msg))
            await ctx.message.delete()
            return
        # if len(ctx.message.attachments) < 1:
        #     msg = f'Your negative review is incomplete. Please attach a screenshot or picture verifying your claim.'
        #     await ctx.author.send(embed=tools.single_embed(msg))
        #     await ctx.message.delete()
        #     return

        if not database.in_members_table(ctx.author):
            database.add_member(ctx.author)

        database.add_neg(member)
        database.add_reviews_given(ctx.author)

        staff_support_channel = database.get_administrative(ctx.guild)
        msg = f'**{member.display_name}** gained 1 negative review from '\
              f'**{ctx.author.display_name}**.\n\n'\
              f'**{ctx.author.display_name}** said:\n "{message}"'

        embed = discord.Embed(color=discord.Color.red(), description=msg)
        try:
            img = ctx.message.attachments[0].url
            embed.set_image(url=img)
        except IndexError:
            pass
        embed.set_thumbnail(url=member.avatar_url)
        await staff_support_channel.send(embed=embed)

        msg = f'Your review has been submitted and forwarded to staff. Thank you.'
        await ctx.send(embed=tools.single_embed_neg(msg), delete_after=30)
        await ctx.message.delete()
Exemplo n.º 8
0
    async def on_message(self, message):
        # search messages for discord links
        if message is None or message.author.bot:
            return

        # verify admin cog is on
        if not database.admin_cog(message.guild):
            return

        # check for mention spamming
        spam_kick = 5
        spam_notify = 3
        if len(message.mentions) > 0:
            global mention_counter
            if message.author.bot or message.author.permissions_in(
                    message.channel).manage_messages:
                pass
            elif message.author.id not in mention_counter:
                mention_counter[message.author.id] = 1
            else:
                admin_channel = database.get_administrative(message.guild)
                mention_counter[message.author.id] += 1

                if mention_counter[message.author.id] >= spam_kick:
                    msg = f'{message.author.mention} has been kicked for spamming mentions.'
                    embed = discord.Embed(description=msg,
                                          color=discord.Color.red())
                    embed.set_author(name=message.author.display_name,
                                     icon_url=message.author.avatar_url)
                    await admin_channel.send(embed=embed)
                    await message.author.kick(reason='Spamming mentions')

                elif mention_counter[message.author.id] == spam_notify:
                    msg = f'Please stop spamming mentions! If you keep doing this you may be auto-kicked.'
                    try:
                        await message.author.send(
                            embed=tools.single_embed_neg(msg))
                    except discord.Forbidden:
                        await message.channel.send(
                            embed=tools.single_embed_neg(
                                message.author.mention + ' ' + msg))
                    msg = f'{message.author.mention} has been notified that they are spamming mentions.\n' \
                          f'[Jump to Message]({message.jump_url})'
                    embed = discord.Embed(description=msg,
                                          color=discord.Color.red())
                    embed.set_author(
                        name=
                        f'{message.author} | {message.author.display_name}',
                        icon_url=message.author.avatar_url)
                    await admin_channel.send(embed=embed)

        if len(message.attachments) > 0:
            global attachment_counter
            if message.author.bot or message.author.permissions_in(
                    message.channel).administrator:
                pass
            elif message.author.id not in attachment_counter:
                attachment_counter[message.author.id] = 1
            else:
                admin_channel = database.get_administrative(message.guild)
                attachment_counter[message.author.id] += 1

                if attachment_counter[message.author.id] >= spam_kick:
                    msg = f'{message.author.mention} has been kicked for spamming attachments.'
                    embed = discord.Embed(description=msg,
                                          color=discord.Color.red())
                    embed.set_author(name=message.author.display_name,
                                     icon_url=message.author.avatar_url)
                    await admin_channel.send(embed=embed)
                    await message.author.kick(reason='Spamming attachments')

                elif attachment_counter[message.author.id] == spam_notify:
                    msg = f'Please stop spamming attachments! If you keep doing this you may be auto-kicked.'
                    try:
                        await message.author.send(
                            embed=tools.single_embed_neg(msg))
                    except discord.Forbidden:
                        await message.channel.send(
                            embed=tools.single_embed_neg(
                                message.author.mention + ' ' + msg))
                    msg = f'{message.author.mention} has been notified that they are spamming attachments.\n' \
                          f'[Jump to Message]({message.jump_url})'
                    embed = discord.Embed(description=msg,
                                          color=discord.Color.red())
                    embed.set_author(
                        name=
                        f'{message.author} | {message.author.display_name}',
                        icon_url=message.author.avatar_url)
                    await admin_channel.send(embed=embed)

        if await self.profanity_filter(message
                                       ) and not message.author.permissions_in(
                                           message.channel).manage_messages:
            staff_support = database.get_administrative(message.guild)
            description = f'Author: {message.author.mention} \n' \
                          f'Message: "{message.content}" \n' \
                          f'[Jump to Message]({message.jump_url})'
            embed = discord.Embed(title='Slur/Profanity Detected',
                                  description=description,
                                  color=discord.Color.red())
            embed.set_author(
                name=f'{message.author} | {message.author.display_name}',
                icon_url=message.author.avatar_url)
            try:
                url = message.attachments[0].url
                embed.set_image(url=url)
            except IndexError:
                pass
            options = ['🚫', '⚠️', '⭕', '❌']
            value = '🚫: Kick\n' \
                    '⚠️: Warn\n' \
                    '⭕: Ignore\n' \
                    '❌: Delete'
            embed.add_field(name='Staff Options', value=value)
            prompt = await staff_support.send(embed=embed)

            def check_react(react, actor):
                return react.message.id == prompt.id and not actor.bot and actor.permissions_in(
                    staff_support).kick_members

            while True:
                embed.remove_field(1)

                for r in options:
                    await prompt.add_reaction(r)
                reaction, reactor = await self.client.wait_for(
                    'reaction_add', check=check_react)

                # kick
                if reaction.emoji == options[0]:
                    await prompt.clear_reactions()
                    embed.add_field(
                        name='Confirm',
                        value=
                        f'Are you sure you want to **kick** {message.author.display_name}?',
                        inline=False)
                    await prompt.edit(embed=embed)
                    await prompt.add_reaction('✅')
                    await prompt.add_reaction('❌')
                    reaction, reactor = await self.client.wait_for(
                        'reaction_add', check=check_react)

                    if reaction.emoji == '✅':
                        try:
                            msg = f'You have been kicked by an administrator or mod in {message.guild.name} for the ' \
                                  f'following content\n' \
                                  f'> "{message.content}"'
                            await message.author.send(
                                embed=tools.single_embed_neg(msg))
                        except discord.Forbidden:
                            pass

                        # remove confirmation dialogue
                        embed.remove_field(1)
                        embed.remove_field(0)
                        msg = f'{message.author.mention} has been kicked by **{reactor.display_name}**'
                        embed.add_field(name='Action', value=msg, inline=False)
                        await prompt.edit(embed=embed)
                        await prompt.clear_reactions()
                        await message.delete()
                        await message.author.kick(
                            reason='inappropriate or obscene language')
                        break
                    elif reaction.emoji == '❌':
                        await prompt.clear_reactions()

                # warn
                elif reaction.emoji == options[1]:
                    embed.remove_field(1)
                    await prompt.clear_reactions()
                    embed.add_field(
                        name='Confirm',
                        value=
                        f'Are you sure you want to **warn** {message.author.mention}?',
                        inline=False)
                    await prompt.edit(embed=embed)
                    await prompt.add_reaction('✅')
                    await prompt.add_reaction('❌')
                    reaction, reactor = await self.client.wait_for(
                        'reaction_add', check=check_react)
                    if reaction.emoji == '✅':
                        warning = 'inappropriate or obscene language'
                        database.add_warning(message.author, warning,
                                             self.client.user)

                        try:
                            msg = f'You have received a warning from an administrator or mod in {message.guild.name} for the ' \
                                  f'following content\n' \
                                  f'> "{message.content}"'
                            await message.author.send(
                                embed=tools.single_embed_neg(msg))
                        except discord.Forbidden:
                            msg = f'{message.author.mention} has been given a warning for inappropriate language.'
                            await message.channel.send(
                                embed=tools.single_embed_neg(msg))

                        # remove confirmation dialogue
                        embed.remove_field(1)
                        embed.remove_field(0)
                        warn = f'{message.author.display_name} was issued a warning by {reactor.display_name}'
                        embed.add_field(name='Action',
                                        value=warn,
                                        inline=False)
                        await prompt.edit(embed=embed)
                        await prompt.clear_reactions()
                        try:
                            await message.delete()
                        except discord.NotFound:
                            pass
                        break
                    elif reaction.emoji == '❌':
                        embed.remove_field(1)
                        embed.remove_field(0)
                        await prompt.clear_reactions()

                # ignore
                elif reaction.emoji == options[2]:
                    embed.remove_field(1)
                    embed.remove_field(0)
                    embed.add_field(
                        name='Action',
                        value=
                        f'{message.author.display_name}\'s message was ignored by {reactor.display_name}',
                        inline=False)
                    await prompt.edit(embed=embed)
                    await prompt.clear_reactions()
                    break

                elif reaction.emoji == options[3]:
                    try:
                        msg = f'Your message was deleted by a mod or admin for inappropriate content.\n' \
                              f'Your original message: "{message.content}"'
                        await message.author.send(
                            embed=tools.single_embed_neg(msg))
                    except discord.Forbidden:
                        msg = f'{message.author.mention} one of your messages was deleted by a mod or admin for ' \
                              f'inappropriate content."'
                        await message.channel.send(
                            embed=tools.single_embed_neg(msg))
                    embed.remove_field(1)
                    embed.remove_field(0)
                    deleted = f'{message.author.display_name}\'s message was deleted by {reactor.display_name}'
                    embed.add_field(name='Action', value=deleted, inline=False)
                    await prompt.edit(embed=embed)
                    await prompt.clear_reactions()
                    try:
                        await message.delete()
                    except discord.NotFound:
                        pass
                    break

        # ignore links created by moderators
        if message.author.guild_permissions.create_instant_invite:
            return

        # ignore this guild's invites
        for w in message.content.split(' '):
            try:
                if w in [
                        f'discord.gg/{invite.code}'
                        for invite in await message.guild.invites()
                ]:
                    pass
            except discord.HTTPException as e:
                print(e)

        # if link found, delete and warn
        if 'discord.gg/' in message.content and 'discord.gg/stalkmarket' not in message.content:
            try:
                await message.delete()
            except discord.NotFound:
                pass
            except Exception as e:
                print(f'Could not delete discord.gg message {message}: {e}')
            msg = f'Advertising other Discord servers is not allowed.'
            database.add_warning(message.author, msg, self.client.user)
            fmt = f'You have received an automatic warning for posting a Discord link in ' \
                  f'**{message.guild.name}**.\n> "{msg}"'
            try:
                # try to DM the warning to the user
                await message.author.send(embed=tools.single_embed_neg(fmt))
            except discord.Forbidden:
                # warn publicly if DMs are closed
                await message.channel.send(embed=tools.single_embed_neg(fmt))

            await self.check_warnings(message)

        te_links = [
            'https://turnip.exchange', 'http://turnip.exchange',
            'turnip.exchange/island'
        ]
        content = [w for w in message.content.split(' ')]
        if any(x in te_links for x in content):
            try:
                await message.delete()
            except discord.NotFound:
                pass
            except Exception as e:
                print(
                    f'Could not delete turnip.exchange message {message}: {e}')
            msg = f'Advertising Turnip Exchange links is not allowed.'
            database.add_warning(message.author, msg, self.client.user)
            fmt = f'You have received an automatic warning for posting a Turnip Exchange link in ' \
                  f'**{message.guild.name}**.\n> "{msg}"'

            try:
                # try to DM the warning to the user
                await message.author.send(embed=tools.single_embed_neg(fmt))
            except discord.Forbidden:
                # warn publicly if DMs are closed
                await message.channel.send(embed=tools.single_embed_neg(fmt))

            await self.check_warnings(message)

        blacklist = database.get_blacklist(message.guild)
        for b in blacklist:
            if b in message.content.lower():
                try:
                    await message.delete()
                    msg = f'You have entered a blacklisted link in **{message.guild.name}** ' \
                          f'Your message has been deleted.'
                    try:
                        await message.author.send(
                            embed=tools.single_embed_neg(msg))
                    except discord.Forbidden:
                        await message.channel.send(
                            embed=tools.single_embed_neg(msg))
                except discord.NotFound as e:
                    print(e)