Exemple #1
0
    async def predicate(ctx):
        if not tools.is_modmail_channel(ctx.channel):
            await ctx.send(ErrorEmbed("This channel is not a ModMail channel.")
                           )
            return False

        return True
Exemple #2
0
    async def closeall(self, ctx, *, reason: str = None):
        for channel in await ctx.guild.text_channels():
            if tools.is_modmail_channel(channel):
                msg = copy.copy(ctx.message)
                msg.channel = channel
                new_ctx = await self.bot.get_context(msg, cls=type(ctx))
                await self.close_channel(new_ctx, reason)

        try:
            await ctx.send(Embed("All channels are successfully closed."))
        except discord.HTTPException:
            pass
    async def on_message(self, message):
        if message.author.bot or not message.guild or not tools.is_modmail_channel(
                message.channel):
            return

        permissions = await message.channel.permissions_for(await
                                                            message.guild.me())
        if permissions.send_messages is False or permissions.embed_links is False:
            return

        prefix = await tools.get_guild_prefix(self.bot, message.guild)
        if message.content.startswith(prefix):
            return

        if await tools.is_user_banned(self.bot, message.author):
            await message.channel.send(
                ErrorEmbed("You are banned from this bot."))
            return

        if (await tools.get_data(self.bot, message.guild.id))[10] is True:
            await self.send_mail_mod(message, prefix, anon=True)
            return

        await self.send_mail_mod(message, prefix)
    async def send_mail(self, message, guild):
        self.bot.prom.tickets_message.inc({})

        if not guild:
            await message.channel.send(ErrorEmbed("The server was not found."))
            return

        try:
            member = await guild.fetch_member(message.author.id)
        except discord.NotFound:
            await message.channel.send(
                ErrorEmbed(
                    "You are not in that server, and the message is not sent.")
            )
            return

        data = await tools.get_data(self.bot, guild.id)

        category = await guild.get_channel(data[2])
        if not category:
            await message.channel.send(
                ErrorEmbed(
                    "A ModMail category is not found. The bot is not set up properly in the server."
                ))
            return

        if message.author.id in data[9]:
            await message.channel.send(
                ErrorEmbed(
                    "That server has blacklisted you from sending a message there."
                ))
            return

        channel = None
        for text_channel in await guild.text_channels():
            if tools.is_modmail_channel(text_channel, message.author.id):
                channel = text_channel
                break

        if channel is None:
            self.bot.prom.tickets.inc({})

            name = "".join([
                x for x in message.author.name.lower()
                if x not in string.punctuation and x.isprintable()
            ])

            if name:
                name = name + f"-{message.author.discriminator}"
            else:
                name = message.author.id

            try:
                channel = await guild.create_text_channel(
                    name=name,
                    category=category,
                    topic=
                    f"ModMail Channel {message.author.id} {message.channel.id} (Please do "
                    "not change this)",
                )
            except discord.HTTPException as e:
                await message.channel.send(
                    ErrorEmbed(
                        "An HTTPException error occurred. Please contact an admin on the server "
                        f"with the following information: {e.text} ({e.code})."
                    ))
                return

            log_channel = await guild.get_channel(data[4])
            if log_channel:
                embed = Embed(
                    title="New Ticket",
                    colour=0x00FF00,
                    timestamp=True,
                )
                embed.set_footer(
                    f"{message.author.name}#{message.author.discriminator} | "
                    f"{message.author.id}",
                    message.author.avatar_url,
                )

                try:
                    await log_channel.send(embed)
                except discord.Forbidden:
                    pass

            prefix = await tools.get_guild_prefix(self.bot, guild)

            embed = Embed(
                "New Ticket",
                "Type a message in this channel to reply. Messages starting with the server prefix "
                f"`{prefix}` are ignored, and can be used for staff discussion. Use the command "
                f"`{prefix}close [reason]` to close this ticket.",
                timestamp=True,
            )
            embed.add_field("User",
                            f"<@{message.author.id}> ({message.author.id})")
            embed.add_field(
                "Roles",
                "*None*" if len(member._roles) == 0 else
                " ".join([f"<@&{x}>" for x in member._roles])
                if len(" ".join([f"<@&{x}>" for x in member._roles])) <= 1024
                else f"*{len(member._roles)} roles*",
            )
            embed.set_footer(f"{message.author} | {message.author.id}",
                             message.author.avatar_url)

            roles = []
            for role in data[8]:
                if role == guild.id:
                    roles.append("@everyone")
                elif role == -1:
                    roles.append("@here")
                else:
                    roles.append(f"<@&{role}>")

            try:
                await channel.send(" ".join(roles), embed=embed)
            except discord.HTTPException:
                await message.channel.send(
                    ErrorEmbed(
                        "The bot is missing permissions. Please contact an admin on the server."
                    ))
                return

            if data[5]:
                embed = Embed(
                    "Greeting Message",
                    tools.tag_format(data[5], message.author),
                    colour=0xFF4500,
                    timestamp=True,
                )
                embed.set_footer(f"{guild.name} | {guild.id}", guild.icon_url)

                await message.channel.send(embed)

        embed = Embed("Message Sent",
                      message.content,
                      colour=0x00FF00,
                      timestamp=True)
        embed.set_footer(f"{guild.name} | {guild.id}", guild.icon_url)

        files = []
        for file in message.attachments:
            saved_file = io.BytesIO()
            await file.save(saved_file)
            files.append(discord.File(saved_file, file.filename))

        dm_message = await message.channel.send(embed, files=files)

        embed.title = "Message Received"
        embed.set_footer(
            f"{message.author.name}#{message.author.discriminator} | {message.author.id}",
            message.author.avatar_url,
        )

        for count, attachment in enumerate(
            [attachment.url for attachment in dm_message.attachments],
                start=1):
            embed.add_field(f"Attachment {count}", attachment, False)

        for file in files:
            file.reset()

        try:
            await channel.send(embed, files=files)
        except discord.Forbidden:
            await dm_message.delete()
            await message.channel.send(
                ErrorEmbed(
                    "The bot is missing permissions. Please contact an admin on the server."
                ))
Exemple #5
0
    async def select_guild(self, message, msg=None):
        guilds = {}

        for guild in await self.bot.state.smembers(f"user:{message.author.id}"
                                                   ):
            guild = await self.bot.get_guild(int(guild))

            channel = None
            for text_channel in await guild.text_channels():
                if tools.is_modmail_channel(text_channel, message.author.id):
                    channel = text_channel

            if not channel:
                guilds[str(guild.id)] = (guild.name, False)
            else:
                guilds[str(guild.id)] = (guild.name, True)

        if len(guilds) == 0:
            await message.channel.send(embed=ErrorEmbed(
                description=
                "Oops, no server found. Please change your Discord status to online and try again."
            ))
            return

        embeds = []

        for chunk in [
                list(guilds.items())[i:i + 10]
                for i in range(0, len(guilds), 10)
        ]:
            embed = Embed(
                title="Select Server",
                description=
                "Please select the server you want to send this message to. You can do so by reacting "
                "with the corresponding emote.",
            )
            embed.set_footer(text="Use the reactions to flip pages.")

            for guild, value in chunk:
                embed.add_field(
                    name=f"{len(embed.fields) + 1}: {value[0]}",
                    value=
                    f"{'Create a new ticket.' if value[1] is False else 'Existing ticket.'}\nServer ID: {guild}",
                )

            embeds.append(embed)

        if msg:
            msg = await msg.edit(embed=embeds[0])
        else:
            msg = await message.channel.send(embed=embeds[0])

        await msg.add_reaction("◀")
        await msg.add_reaction("▶")
        for reaction in [
                "1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣", "🔟"
        ][:len(embeds[0].fields)]:
            await msg.add_reaction(reaction)

        await self.bot.state.sadd(
            "reaction_menus",
            {
                "kind": "selection",
                "channel": msg.channel.id,
                "message": msg.id,
                "end": int(time.time()) + 180,
                "data": {
                    "msg": message._data,
                    "page": 0,
                    "all_pages": [embed.to_dict() for embed in embeds],
                },
            },
        )