Ejemplo n.º 1
0
    async def submit(self, ctx):
        """Initializes process of submitting code for event."""
        dm_msg = (
            "Submitting process has begun.\n\n"
            "Please reply with 1 message below that either contains your full code or, "
            "if it's too long, contains a link to code (pastebin/hastebin..)\n"
            "If using those services make sure to set code to private and "
            "expiration date to at least 30 days."
        )
        await ctx.author.send(embed=authored(dm_msg, author=ctx.guild.me))

        def check(msg):
            return msg.author == ctx.author and msg.guild is None

        try:
            code_msg = await self.bot.wait_for("message", check=check, timeout=300)
        except TimeoutError:
            await ctx.send(embed=failure("You took too long to reply."))
            return

        title = f"Submission from {ctx.author}"
        embed = discord.Embed(title=title, description=code_msg.content, color=ctx.me.top_role.color)
        embed.set_thumbnail(url=ctx.author.avatar_url)

        await self.code_submissions_channel.send(embed=embed)
Ejemplo n.º 2
0
    async def create_mod_mail(self, user: discord.User):
        if user.id in self.pending_mod_mails:
            await user.send(embed=failure("You already have a pending mod mail, please be patient."))
            return

        submission_embed = authored(f"`{user.id}` submitted for mod mail.", author=user)
        # Ping roles so they get notified sooner
        await self.mod_mail_report_channel.send("@here", delete_after=30)
        await self.mod_mail_report_channel.send(embed=submission_embed)

        self.pending_mod_mails.add(user.id)
        await user.send(embed=success("Mod mail was sent to admins, please wait for one of the admins to accept."))
Ejemplo n.º 3
0
    async def create_mod_mail(self, user: discord.User):
        if user.id in self.pending_mod_mails:
            await user.send(embed=failure(
                "You already have a pending mod mail, please be patient."))
            return

        mod_mail_report_channel = self.bot.get_channel(
            constants.mod_mail_report_channel_id)
        submission_embed = authored(f"`{user.id}` submitted for mod mail.",
                                    author=user)
        await mod_mail_report_channel.send(embed=submission_embed)
        self.pending_mod_mails.add(user.id)
        await user.send(embed=success(
            "Mod mail was sent to admins, please wait for one of the admins to accept."
        ))
Ejemplo n.º 4
0
    async def attend(self, ctx, user_id: int):
        # Time to wait for FIRST USER reply. Useful if mod attends but user is away.
        first_timeout = 10_800
        # Flag for above variable. False means there has been no messages from the user.
        first_timeout_flag = False
        # After the user sends first reply this is the timeout we use.
        regular_timeout = 600

        user = self.bot.get_user(user_id)
        mod = ctx.author
        # Keep a log of all messages in mod-mail
        log = MessageLogger(mod.id, user.id)
        mod_mail_report_channel = self.bot.get_channel(
            constants.mod_mail_report_channel_id)

        if user is None:
            await ctx.send(embed=failure(
                "That user cannot be found or you entered incorrect ID."))
            return
        elif user_id not in self.pending_mod_mails:
            await ctx.send(
                embed=failure("That user is not registered for mod mail."))
            return
        elif self.is_any_session_active(mod.id):
            await ctx.send(embed=failure(
                "You already have one of active sessions (reports/mod mail etc)."
            ))
            return

        self.pending_mod_mails.remove(user_id)
        self.active_mod_mails[user_id] = mod.id

        await user.send(embed=authored((
            "has accepted your mod mail request.\n"
            "Reply here in DMs to chat with them.\n"
            "This mod mail will be logged, by continuing you agree to that.\n"
            "Type `close` to close this mod mail."),
                                       author=mod))

        await mod.send(
            embed=success(f"You have accepted `{user}` mod mail request.\n"
                          "Reply here in DMs to chat with them.\n"
                          "This mod mail will be logged.\n"
                          "Type `close` to close this mod mail."))
        await ctx.send(embed=success("Mod mail initialized, check your DMs."),
                       delete_after=10)

        def mod_mail_check(msg):
            return msg.guild is None and msg.author.id in (user_id, mod.id)

        _timeout = first_timeout

        while True:
            try:
                mail_msg = await self.bot.wait_for("message",
                                                   check=mod_mail_check,
                                                   timeout=_timeout)
                log.add_message(mail_msg)
            except TimeoutError:
                timeout_embed = failure("Mod mail closed due to inactivity.")
                log.add_embed(timeout_embed)
                await mod.send(embed=timeout_embed)
                await user.send(embed=timeout_embed)
                del self.active_mod_mails[user_id]
                await mod_mail_report_channel.send(file=discord.File(
                    StringIO(str(log)), filename=log.filename))
                break

            # Deal with dynamic timeout.
            if mail_msg.author == user and not first_timeout_flag:
                first_timeout_flag = True
                _timeout = regular_timeout

            # Deal with canceling mod mail
            if mail_msg.content.lower() == "close":
                close_embed = success(
                    f"Mod mail successfully closed by {mail_msg.author}.")
                log.add_embed(close_embed)
                await mod.send(embed=close_embed)
                await user.send(embed=close_embed)
                del self.active_mod_mails[user_id]
                await mod_mail_report_channel.send(file=discord.File(
                    StringIO(str(log)), filename=log.filename))
                break

            # Deal with user-mod communication
            if mail_msg.author == user:
                await mod.send(mail_msg.content)
            elif mail_msg.author == mod:
                await user.send(mail_msg.content)
Ejemplo n.º 5
0
    async def attend(self, ctx, user_id: int):
        if not any(role in ctx.author.roles for role in (self.admin_role, self.moderator_role)):
            await ctx.send(embed=failure("You do not have permission to use this command."))
            return

        # Time to wait for FIRST USER reply. Useful if mod attends but user is away.
        first_timeout = 21_600  # 6 hours
        # Flag for above variable. False means there has been no messages from the user.
        first_timeout_flag = False
        # After the user sends first reply this is the timeout we use.
        regular_timeout = 1800  # 30 min

        user = self.bot.get_user(user_id)
        mod = ctx.author

        if user is None:
            await ctx.send(embed=failure("That user cannot be found or you entered incorrect ID."))
            return
        elif user_id not in self.pending_mod_mails:
            await ctx.send(embed=failure("That user is not registered for mod mail."))
            return
        elif self.is_any_session_active(mod.id):
            await ctx.send(embed=failure("You already have one of active sessions (reports/mod mail etc)."))
            return

        try:
            await mod.send(
                embed=success(
                    f"You have accepted `{user}` mod mail request.\n"
                    "Reply here in DMs to chat with them.\n"
                    "This mod mail will be logged.\n"
                    "Type `close` to close this mod mail."
                )
            )
        except discord.HTTPException:
            await ctx.send(embed=failure("Mod mail failed to initialize due to mod having closed DMs."))
            return

        # Unlike failing for mods due to closed DMs this cannot fail for user since user already did interact
        # with bot in DMs as he needs to in order to even open mod-mail.
        await user.send(
            embed=authored(
                (
                    "has accepted your mod mail request.\n"
                    "Reply here in DMs to chat with them.\n"
                    "This mod mail will be logged, by continuing you agree to that."
                ),
                author=mod
            )
        )

        await ctx.send(embed=success("Mod mail initialized, check your DMs."))
        self.pending_mod_mails.remove(user_id)
        self.active_mod_mails[user_id] = mod.id
        _timeout = first_timeout
        # Keep a log of all messages in mod-mail
        log = MessageLogger(mod.id, user.id)

        def mod_mail_check(msg):
            return msg.guild is None and msg.author.id in (user_id, mod.id)

        while True:
            try:
                mail_msg = await self.bot.wait_for("message", check=mod_mail_check, timeout=_timeout)
                log.add_message(mail_msg)
            except TimeoutError:
                timeout_embed = failure("Mod mail closed due to inactivity.")
                log.add_embed(timeout_embed)
                await mod.send(embed=timeout_embed)
                await user.send(embed=timeout_embed)
                del self.active_mod_mails[user_id]
                await self.mod_mail_report_channel.send(file=discord.File(StringIO(str(log)), filename=log.filename))
                break

            # Deal with attachments. We don't re-upload we just copy paste attachment url.
            attachments = self._get_attachments_as_urls(mail_msg)
            mail_msg.content += attachments

            if len(mail_msg.content) > 1900:
                mail_msg.content = f"{mail_msg.content[:1900]} ...truncated because it was too long."

            # Deal with dynamic timeout.
            if mail_msg.author == user and not first_timeout_flag:
                first_timeout_flag = True
                _timeout = regular_timeout

            # Deal with canceling mod mail
            if mail_msg.content.lower() == "close" and mail_msg.author.id == mod.id:
                close_embed = success(f"Mod mail successfully closed by {mail_msg.author}.")
                log.add_embed(close_embed)
                await mod.send(embed=close_embed)
                await user.send(embed=close_embed)
                del self.active_mod_mails[user_id]
                await self.mod_mail_report_channel.send(file=discord.File(StringIO(str(log)), filename=log.filename))
                break

            # Deal with user-mod communication
            if mail_msg.author == user:
                await mod.send(mail_msg.content)
            elif mail_msg.author == mod:
                await user.send(mail_msg.content)