Ejemplo n.º 1
0
    async def platforms_send(self, ctx):
        """Send the initial reaction embed for platform roles."""
        prompt = 'Are you sure you would like to send the platforms reaction message?'
        if not await ctx.prompt(prompt):
            return

        await ctx.message.delete()

        description = '\n'.join((
            "To help us provide accurate help we've created platform-specific"
            + 'help channels and roles.\n',
            'React to this message to assign the appropriate role.',
            'If you have any questions contact a Community Manager.',
        ))
        embed = discord.Embed(title='Platform Roles',
                              description=description,
                              colour=Colour.light_blue())

        records = await ctx.db.fetch('SELECT * FROM roles WHERE type=$1;',
                                     RoleType.platform.value)

        if not records:
            return

        for record in records:
            embed.add_field(name=record['reaction'] + ' ' + record['name'],
                            value=record['description'],
                            inline=False)

        message = await ctx.send(embed=embed)
        self.bot.settings.platform_message = message.id

        for record in records:
            await message.add_reaction(record['reaction'].strip('<>'))
Ejemplo n.º 2
0
    async def pings_send(self, ctx):
        """Send the initial reaction embed for ping roles."""
        prompt = 'Are you sure you would like to send the pings reaction message?'
        if not await ctx.prompt(prompt):
            return

        await ctx.message.delete()

        description = '\n'.join((
            "To avoid pinging everyone we've created a few roles to ping instead.\n",
            'React to this message to assign the appropriate role.',
            'If you have any questions feel free to ping a Community Manager.',
        ))
        embed = discord.Embed(title='Role Management',
                              description=description,
                              colour=Colour.light_blue())

        records = await ctx.db.fetch('SELECT * FROM roles WHERE type=$1;',
                                     RoleType.ping.value)

        if not records:
            return

        for record in records:
            embed.add_field(name=record['reaction'] + ' ' + record['name'],
                            value=record['description'],
                            inline=False)

        message = await ctx.send(embed=embed)
        self.bot.settings.pings_message = message.id

        for record in records:
            await message.add_reaction(record['reaction'].strip('<>'))
Ejemplo n.º 3
0
    async def language_send(self, ctx):
        """Send the initial reaction embed for language roles."""
        prompt = 'Are you sure you would like to send the language reaction message?'
        if not await ctx.prompt(prompt):
            return

        await ctx.message.delete()

        description = '\n'.join((
            'To help find games in your langauges we have created ' +
            'some roles for *you* to ping instead.',
            'This does mean that these roles will be pinged a lot, so only assign '
            + 'them to yourself if you are fine with '
            'getting pinged a lot by members in <#540999156660174878>.\n',
            'React to this message to assign yourself the appropriate role.',
            'If you have any questions please ping a Community Manager',
        ))

        embed = discord.Embed(title='Language Roles',
                              description=description,
                              colour=Colour.light_blue())

        records = await ctx.db.fetch('SELECT * FROM roles WHERE type=$1;',
                                     RoleType.language.value)

        for record in records:
            embed.add_field(name=record['reaction'] + ' ' + record['name'],
                            value=record['description'],
                            inline=True)

        message = await ctx.send(embed=embed)
        self.bot.settings.language_message = message.id

        for record in records:
            await message.add_reaction(record['reaction'].strip('<>'))
Ejemplo n.º 4
0
    async def send_command_help(self, command):
        if command.hidden:
            return

        await self.get_destination().send(embed=discord.Embed(
            title=command.name[0].upper() + command.name[1:],
            description='`{0}` {1}'.format(
                self.get_command_signature(command),
                command.help or command.brief,
            ),
            colour=Colour.light_blue(),
        ))
Ejemplo n.º 5
0
    async def create_report(self, author: discord.Member, *, conn=None):
        conn = conn or self.bot.pool

        report_id: int = await conn.fetchval("SELECT nextval('report_id');")

        overwrites = {author: discord.PermissionOverwrite(read_messages=True)}
        overwrites.update(self.category.overwrites)

        channel = await self.category.create_text_channel(
            name='{0}-{1}'.format(report_id, author.display_name),
            sync_permissions=True,
            overwrites=overwrites,
            reason='Creating report #{0} ({1}) for {2}'.format(
                report_id, report_id, author.display_name))

        query = """INSERT INTO reports (
                    id, channel_id, author_id
                ) VALUES ($1, $2, $3) RETURNING *;
        """
        record = await conn.fetchrow(query, report_id, channel.id, author.id)

        await channel.send('Welcome {0}'.format(author.mention),
                           embed=discord.Embed(
                               description=self.open_message,
                               colour=Colour.light_blue(),
                           ))

        embed = discord.Embed(title=f"Report #{record['id']}",
                              colour=Colour.cyan())

        embed.set_author(name=author, icon_url=author.avatar_url)

        message = await self.status_channel.send(embed=embed)

        await conn.execute(
            'UPDATE reports SET status_message_id=$1 WHERE id=$2', message.id,
            record['id'])

        return channel, record
Ejemplo n.º 6
0
    async def start(self):
        self.manager.lobbies.remove(self)
        await self.message.clear_reactions()
        await self.message.channel.send(
            'You have enough players to start a game! ' + ', '.join(
                '<@{0}>'.format(player) for player in self.players
            ),
        )

        description = 'This lobby reached the desired amount of players.'
        await self.message.edit(embed=discord.Embed(
            title='Lobby Full!',
            description=description,
            colour=Colour.apricot(),
        ))
Ejemplo n.º 7
0
    async def send_bot_help(self, mapping):
        bot = self.context.bot
        all_commands = await self.filter_commands(bot.commands, sort=True)

        embed = discord.Embed(
            title='All commands',
            colour=Colour.light_blue(),
        )

        for command in all_commands:
            embed.add_field(name=self.get_command_signature(command),
                            value=command.brief
                            or self.generate_brief(command.help)
                            or '*missing*',
                            inline=False)

        await self.get_destination().send(embed=embed)
Ejemplo n.º 8
0
    async def disband(self, *, timeout=False):
        if not timeout:
            self.timeout.cancel()  # Cancel the timeout task

        self.manager.lobbies.remove(self)
        await self.message.clear_reactions()
        await self.message.channel.send(
            '<@{0}> your lobby was disbanded.'.format(
                self.owner_id
            )
        )

        description = 'This lobby was disbanded.'
        await self.message.edit(embed=discord.Embed(
            title='Lobby Disbanded!',
            description=description,
            colour=Colour.unvaulted_red(),
        ))
Ejemplo n.º 9
0
    async def send_group_help(self, group):
        if group.hidden:
            return

        all_commands = await self.filter_commands(group.commands, sort=True)

        embed = discord.Embed(
            title=group.name[0].upper() + group.name[1:],
            description='`{0}` {1}'.format(
                self.get_command_signature(group),
                group.help or group.brief,
            ),
            colour=Colour.light_blue(),
        )

        for command in all_commands:
            embed.add_field(name=self.get_command_signature(command),
                            value=command.brief
                            or self.generate_brief(command.help),
                            inline=False)

        await self.get_destination().send(embed=embed)
Ejemplo n.º 10
0
    async def lobby(self, ctx, players: int = 5):
        """
        Open a managed waiting lobby to gather players. This then pings all players when full.
        """
        lobby = self.get_lobby_by_owner(ctx.author.id)

        if lobby:
            return await ctx.send('Please disband your old lobby before opening a new one.')

        if players < 2 or players > 8:
            return

        beta_mention = f'<@&{self.bot.settings.beta_role}>'
        message = await ctx.send(beta_mention, embed=discord.Embed(
            title='Looking for players!',
            description='If you are available for a game, react below.',
            colour=Colour.cyan(),
        ), allowed_mentions=discord.AllowedMentions(everyone=True, roles=True))

        self.lobbies.add(Lobby(self, ctx.author.id, message, players))

        await message.add_reaction(':high5:{}'.format(self.bot.settings.high5_emoji))
Ejemplo n.º 11
0
    async def tickets(self, ctx, user: discord.Member):
        """Get all tickets opened by a specific user."""

        embed = discord.Embed(title=f"Tickets opened by {user}", colour=Colour.light_blue())

        tickets = await self.bot.pool.fetch(
            'SELECT * FROM tickets WHERE author_id=$1;',
            user.id
        )

        to_display = tickets
        if len(tickets) > 25:
            to_display = tickets[:25]

        for ticket in to_display:
            # Craft the message link
            link = 'https://discord.com/channels/431073730828173312/'
            link += f'{self.status_channel.id}/'
            link += str(ticket['status_message_id'])

            # Craft the field name
            name = f"Ticket #{ticket['id']}"
            if ticket['issue']:
                name += f" - {ticket['issue'][:235]}"

            embed.add_field(
                name=name,
                value=f"[Message link!]({link})",
                inline=False
            )

        footer = f'{user} has opened {len(tickets)} tickets.'
        if to_display is not tickets:
            footer += 'Displaying only 25 in no particular order.'

        embed.set_footer(text=footer)

        await ctx.send(embed=embed)
Ejemplo n.º 12
0
    async def send_report(self, ctx):
        """Send the report message to be reacted to."""
        if not await ctx.prompt(
                'Are you sure you want to send the report message here?'):
            return

        await ctx.message.delete()

        description = '\n'.join((
            '*Please make sure you have proof for your report.*\n',
            'Due to the nature of the game, so called "RDM" and "teaming" can be subjective'
            +
            ' due to a lack of information, paranoia or simply being new players. But if '
            +
            'someone is blatantly doing this to ruin games please report that.\n',
            '**Before opening a report ticket please do the following:**',
            '1. Report in-game when you can (hit ESC, click Players, select Report)',
            '2. Record a video or take screenshots',
            '3. Get a steam link to their account\n',
            '**To report a player simply react below with <:high5:{}>!**'.
            format(self.bot.settings.high5_emoji)))

        embed = discord.Embed(title='Report Player',
                              description=description,
                              colour=Colour.light_blue())

        embed.set_footer(
            text=
            'We are dedicated to ensure a safe and respective community and ' +
            'all reports will be looked into.')

        message = await ctx.send(embed=embed)
        self.bot.settings.report_message = message.id

        await message.add_reaction(':high5:{}'.format(
            self.bot.settings.high5_emoji))
Ejemplo n.º 13
0
    async def _create_ticket(self, author, issue, *, prefix=None, conn=None):
        conn = conn or self.bot.pool

        # If issue is None
        issue = issue.strip('<>') if isinstance(issue, str) else issue
        ticket_id = await conn.fetchval("SELECT nextval('ticket_id');")

        overwrites = {
            author: discord.PermissionOverwrite(
                read_messages=True
            )
        }
        overwrites.update(self.category.overwrites)

        channel = await self.category.create_text_channel(
            name='{0}-{1}-{2}'.format(
                prefix or '', ticket_id, issue[:90] if issue else author.display_name
            ),
            sync_permissions=True, overwrites=overwrites,
            reason='Creating ticket #{0}: {1}'.format(ticket_id, issue)
        )

        query = """INSERT INTO tickets (
                    id, channel_id, author_id, issue
                ) VALUES ($1, $2, $3, $4) RETURNING *;
        """
        record = await conn.fetchrow(
            query, ticket_id, channel.id, author.id,
            issue[:90] if issue else None
        )

        await channel.send(
            'Welcome {0}'.format(author.mention),
            embed=discord.Embed(
                description=await self.bot.fetch_tag(
                    prefix + '-ticket'
                ) if prefix else self.open_message,
                colour=Colour.light_blue(),
            )
        )

        title = '{} #{}{}'.format(
            (prefix[0].upper() + prefix[1:]) if prefix else 'Ticket',
            record['id'], ' - {}'.format(issue[:235]) if issue else ''
        )

        embed = discord.Embed(
            title=title,
            colour=Colour.cyan()
        )

        embed.set_author(name=author, icon_url=author.avatar_url)

        message = await self.status_channel.send(embed=embed)

        await conn.execute(
            'UPDATE tickets SET status_message_id=$1 WHERE id=$2',
            message.id, record['id']
        )

        return channel, record
Ejemplo n.º 14
0
    async def ticket_close(self, ctx, *, reason=None):
        """Close the ticket and create an archive. The reason should be a summary."""

        query = 'SELECT * from tickets WHERE channel_id=$1;'
        record = await ctx.db.fetchrow(query, ctx.channel.id)

        if not record:
            return

        query = 'UPDATE tickets SET state=$1 WHERE channel_id=$2'
        await ctx.db.execute(query, TicketState.closed.value, record['channel_id'])

        await ctx.send('Creating logs please do not send any messages, this may take a while.')

        message = await self.status_channel.fetch_message(record['status_message_id'])
        embed = message.embeds[0]

        embed.description = reason
        embed.colour = Colour.apricot()

        ticket = 'Ticket #{}{}'.format(
            record['id'], ' - {}'.format(record['issue']) if record['issue'] else ''
        )
        files = await self._generate_log(ctx.channel, record)
        jumps = ''
        for attachment in files[1:]:  # The log comes afterwards
            # Embed fields cannot exceed 1024 characters, so we need to split
            # the jump URLs before this happens.
            if len(jumps) > 800:
                embed.add_field(
                    name='Attachments',
                    value=jumps,
                    inline=False
                )
                jumps = ''

            msg = await self.log_channel.send(
                f'Attachment from **{ticket}**',
                file=discord.File(attachment, filename=attachment)
            )
            jumps += f'[Jump: {attachment}]({msg.jump_url})\n'

            os.remove(attachment)

        if jumps:  # There's some jump URLs to send
            embed.add_field(
                name='Attachments',
                value=jumps,
                inline=False
            )

        transcript = await self.log_channel.send(
            f"Transcription from **{ticket}**",
            file=discord.File(files[0], filename=files[0])
        )
        embed.add_field(name='Log', value=f'[Jump!]({transcript.jump_url})')
        os.remove(files[0])

        embed.set_footer(
            text=f'{ctx.author} ({ctx.author.id})',
            icon_url=ctx.author.avatar_url
        )

        await message.edit(embed=embed)

        await ctx.channel.delete(
            reason='Closing ticket #{0} because: {1}'.format(record['id'], reason)
        )
Ejemplo n.º 15
0
    async def report_close(self, ctx, *, reason=''):
        """Close the report. The reason should be a summary."""

        query = 'SELECT * from reports WHERE channel_id=$1;'
        record = await ctx.db.fetchrow(query, ctx.channel.id)

        if not record:
            return

        query = 'UPDATE reports SET state=$1 WHERE channel_id=$2;'
        await ctx.db.execute(query, ReportState.closed.value,
                             record['channel_id'])

        # For older reports before this change that don't have a status message
        if record['status_message_id'] is None:
            return await ctx.channel.delete(
                reason='Closing report #{0}'.format(record['id']))

        await self._lock_channel(ctx.channel)

        message = await self.status_channel.fetch_message(
            record['status_message_id'])
        embed = message.embeds[0]

        embed.description = reason
        embed.colour = Colour.apricot()

        transcript, evidence, links = await self._gather_evidence(
            ctx.channel, record)

        transcript_link = await self.evidence_channel.send(
            f"Transcription for **Report #{record['id']}**",
            file=discord.File(transcript))

        os.remove(transcript)

        embed.add_field(name='Transcription',
                        value=f'[Jump to message]({transcript_link.jump_url})',
                        inline=False)

        if links:
            embed.add_field(name='Links', value='\n'.join(links), inline=False)

        if evidence:
            jumps = ''
            for attachment in evidence:
                # Embed fields cannot exceed 1024 characters, so we need to split
                # the jump URLs before this happens.
                if len(jumps) > 800:
                    embed.add_field(name='Attachments',
                                    value=jumps,
                                    inline=False)
                    jumps = ''

                name = (f"report-evidence-{record['id']}" +
                        os.path.splitext(attachment.filename)[1])
                await attachment.save(name)

                msg = await self.evidence_channel.send(
                    f"Evidence for **Report #{record['id']}**",
                    file=discord.File(name, filename=attachment.filename))
                jumps += f'[Jump: {attachment.filename}]({msg.jump_url})\n'

                os.remove(name)

            embed.add_field(name='Attachments', value=jumps, inline=False)

        embed.set_footer(text=f'{ctx.author} ({ctx.author.id})',
                         icon_url=ctx.author.avatar_url)

        await message.edit(embed=embed)

        await ctx.channel.delete(
            reason='Closing report #{0}'.format(record['id']))