Пример #1
0
    async def debug(self, ctx):
        """Shows the recent application-logs of the bot."""

        log_file_name = self.bot.config.token.split(".")[0]

        with open(
            os.path.join(
                os.path.dirname(os.path.abspath(__file__)),
                f"../temp/{log_file_name}.log",
            ),
            "r+",
        ) as f:
            logs = f.read().strip()

        if not logs:
            embed = Embed(
                color=self.bot.main_color,
                title="Debug Logs:",
                description="You don't have any logs at the moment.",
            )
            embed.set_footer(text="Go to Heroku to see your logs.")
            return await ctx.send(embed=embed)

        messages = []

        # Using Scala formatting because it's similar to Python for exceptions
        # and it does a fine job formatting the logs.
        msg = "```Scala\n"

        for line in logs.splitlines(keepends=True):
            if msg != "```Scala\n":
                if len(line) + len(msg) + 3 > 2000:
                    msg += "```"
                    messages.append(msg)
                    msg = "```Scala\n"
            msg += line
            if len(msg) + 3 > 2000:
                msg = msg[:1993] + "[...]```"
                messages.append(msg)
                msg = "```Scala\n"

        if msg != "```Scala\n":
            msg += "```"
            messages.append(msg)

        embed = Embed(color=self.bot.main_color)
        embed.set_footer(text="Debug logs - Navigate using the reactions below.")

        session = MessagePaginatorSession(ctx, *messages, embed=embed)
        session.current = len(messages) - 1
        return await session.run()
Пример #2
0
    async def calcv2(self, ctx, *, exp):
        """
        Basically a simple calculator-v2. This command is safe.
        """
        exp = REMOVE_CODE.sub('', exp).strip().splitlines()
        outputs = []
        for i, line in enumerate(exp, start=1):
            try:
                e = self.calc(line.strip())
                if hasattr(e, 'evalf'):
                    e = e.evalf(n=CalculateTree.precision, chop=True)
                e = REMOVE_ZERO.sub(r'\1\2', str(e))

                outputs += [f"Line {i}: " + e + '\n']
            except Exception as e:
                outputs += [f"Error on line {i}: {e}.\n"]

        messages = ['```\n']
        for output in outputs:
            if len(messages[-1]) + len(output) + len('```') > 2000:
                messages[-1] += '```'
                messages.append('```\n')
            messages[-1] += output
        if not messages[-1].endswith('```'):
            messages[-1] += '```'

        session = MessagePaginatorSession(ctx, *messages)
        return await session.run()
Пример #3
0
    async def debug(self, ctx):
        """Shows the recent logs of the bot."""

        if ctx.invoked_subcommand is not None:
            return

        with open(
                os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             '../temp/logs.log'), 'r+') as f:
            logs = f.read().strip(' \n\r')

        if not logs:
            embed = Embed(
                color=self.bot.main_color,
                title='Debug Logs:',
                description='You don\'t have any logs at the moment.')
            embed.set_footer(text='Go to Heroku to see your logs.')
            return await ctx.send(embed=embed)

        messages = []

        # Using Scala formatting because it's similar to Python for exceptions
        # and it does a fine job formatting the logs.
        msg = '```Scala\n'

        for line in logs.splitlines(keepends=True):
            if msg != '```Scala\n':
                if len(line) + len(msg) + 3 > 2000:
                    msg += '```'
                    messages.append(msg)
                    msg = '```Scala\n'
            msg += line
            if len(msg) + 3 > 2000:
                msg = msg[:1993] + '[...]```'
                messages.append(msg)
                msg = '```Scala\n'

        if msg != '```Scala\n':
            msg += '```'
            messages.append(msg)

        embed = Embed(color=self.bot.main_color,
                      title='Debug Logs:',
                      description='This message contains your '
                      'locally cached Modmail bot logs, '
                      'go to the last page to see the most recent logs.')
        embed.add_field(name='\u200b',
                        value='**Navigate using the reactions below.**')
        embed.set_footer(text='If you\'re hosting Modmail on Heroku, '
                         'logs are cleared at least once every 27 hours.')

        session = MessagePaginatorSession(ctx, *messages, embed=embed)
        return await session.run()
Пример #4
0
    async def send_leaderboard(self, ctx: commands.Context, data: dict,
                               key: str, top: int):
        """
        Send the leaderboard from the given data.

        Parameters
        ----------
        ctx : commands.Context
            The context to send the leaderboard to.
        data : dict
            The data for the leaderboard. This must map `discord.Member` ->
            `dict`.
        key : str
            The field to sort the data by. Can be ``wins``, ``total_score``,
            ``games`` or ``average_score``.
        top : int
            The number of members to display on the leaderboard.

        Returns
        -------
        `list` of `discord.Message`
            The sent leaderboard messages.
        """
        if not data:
            raise commands.BadArgument("There are no scores on record!")

        leaderboard = self._get_leaderboard(data, key, top)
        ret = []
        msg = "```py\n"
        for line in leaderboard.splitlines(keepends=True):
            if len(line) + len(msg) + 3 > 2000:
                msg += "```"
                ret.append(msg)
                msg = "```py\n"
            msg += line
            if len(msg) + 3 > 2000:
                msg = msg[:1993] + "[...]```"
                ret.append(msg)
                msg = "```py\n"

        if msg != "```py\n":
            msg += "```"
            ret.append(msg)

        embed = discord.Embed(color=self.bot.main_color)
        footer_text = "Leaderboard"
        if len(ret) > 1:
            footer_text += " - Navigate using the reactions below."
        embed.set_footer(text=footer_text)

        session = MessagePaginatorSession(ctx, *ret, embed=embed)
        return await session.run()
Пример #5
0
    async def debug(self, ctx):
        """Affiche les logs récents du bot."""

        if ctx.invoked_subcommand is not None:
            return

        with open(
                os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             '../temp/logs.log'), 'r+') as f:
            logs = f.read().strip()

        if not logs:
            embed = Embed(
                color=self.bot.main_color,
                title='Debug Logs:',
                description='Vous n`\'avez pas de logs pour le moment.')
            embed.set_footer(text='Allez sur Heroku pour voir vos logs.')
            return await ctx.send(embed=embed)

        messages = []

        # Using Scala formatting because it's similar to Python for exceptions
        # and it does a fine job formatting the logs.
        msg = '```Scala\n'

        for line in logs.splitlines(keepends=True):
            if msg != '```Scala\n':
                if len(line) + len(msg) + 3 > 2000:
                    msg += '```'
                    messages.append(msg)
                    msg = '```Scala\n'
            msg += line
            if len(msg) + 3 > 2000:
                msg = msg[:1993] + '[...]```'
                messages.append(msg)
                msg = '```Scala\n'

        if msg != '```Scala\n':
            msg += '```'
            messages.append(msg)

        embed = Embed(color=self.bot.main_color)
        embed.set_footer(
            text='Debug logs - Naviguez en utilisant les réactions ci-dessous.'
        )

        session = MessagePaginatorSession(ctx, *messages, embed=embed)
        return await session.run()
Пример #6
0
    async def debug(self, ctx):
        """Shows the recent logs of the bot."""

        if ctx.invoked_subcommand is not None:
            return

        with open(
                os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             '../temp/logs.log'), 'r+') as f:
            logs = f.read().strip()

        if not logs:
            embed = Embed(
                color=self.bot.main_color,
                title='Debug Logs:',
                description='You don\'t have any logs at the moment.')
            embed.set_footer(text='Go to Heroku to see your logs.')
            return await ctx.send(embed=embed)

        messages = []

        # Using Scala formatting because it's similar to Python for exceptions
        # and it does a fine job formatting the logs.
        msg = '```Scala\n'

        for line in logs.splitlines(keepends=True):
            if msg != '```Scala\n':
                if len(line) + len(msg) + 3 > 2000:
                    msg += '```'
                    messages.append(msg)
                    msg = '```Scala\n'
            msg += line
            if len(msg) + 3 > 2000:
                msg = msg[:1993] + '[...]```'
                messages.append(msg)
                msg = '```Scala\n'

        if msg != '```Scala\n':
            msg += '```'
            messages.append(msg)

        embed = Embed(color=self.bot.main_color)
        embed.set_footer(
            text='Debug logs - Navigate using the reactions below.')

        session = MessagePaginatorSession(ctx, *messages, embed=embed)
        return await session.run()
Пример #7
0
    async def send(self, *msgs, **kwargs) -> discord.Message:
        reference = self.message.reference or self.message.to_reference()
        reference = kwargs.pop("reference", reference)
        message = kwargs.pop("content", " ".join(str(msg) for msg in msgs))
        embeds = kwargs.pop("embeds", None)
        messages = kwargs.pop("messages", None)
        if embeds:
            session = EmbedPaginatorSession(self, *embeds)
            return await session.run()
        elif messages:
            embed = kwargs.pop("embed", None)
            session = MessagePaginatorSession(self, *messages, embed=embed)
            return await session.run()
        try:
            ret = await super().send(message, reference=reference, **kwargs)
        except discord.errors.HTTPException:
            ret = await super().send(message, **kwargs)

        return ret