How to use the jishaku.repl.Scope function in jishaku

To help you get started, we’ve selected a few jishaku examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Gorialis / jishaku / tests / test_repl.py View on Github external
async def test_scope_copy(scope):
    scope2 = Scope()
    scope2.update(scope)

    assert scope.globals == scope2.globals, "Checking scope globals copied"
    assert scope.locals == scope2.locals, "Checking scope locals copied"

    insert_dict = {'e': 7}
    scope.update_locals(insert_dict)

    assert 'e' in scope.locals, "Checking scope locals updated"
    assert 'e' not in scope2.locals, "Checking scope clone locals not updated"

    scope.clear_intersection(insert_dict)

    assert 'e' not in scope.locals, "Checking locals intersection cleared"

    scope.update_globals(insert_dict)
github Gorialis / jishaku / tests / test_repl.py View on Github external
def scope():
    return Scope(
        {
            "add_numbers": add_numbers,
            "placement": 81
        },
        {
            "placement_local": 18
        }
github Gorialis / jishaku / jishaku / cog_base.py View on Github external
def __init__(self, bot: commands.Bot):
        self.bot = bot
        self._scope = Scope()
        self.retain = JISHAKU_RETAIN
        self.last_result = None
        self.start_time = datetime.datetime.now()
        self.tasks = collections.deque()
        self.task_count: int = 0
github Gorialis / jishaku / jishaku / cog_base.py View on Github external
def scope(self):
        """
        Gets a scope for use in REPL.

        If retention is on, this is the internal stored scope,
        otherwise it is always a new Scope.
        """

        if self.retain:
            return self._scope
        return Scope()
github Gorialis / jishaku / jishaku / cog_base.py View on Github external
Provide no argument for current status.
        """

        if toggle is None:
            if self.retain:
                return await ctx.send("Variable retention is set to ON.")

            return await ctx.send("Variable retention is set to OFF.")

        if toggle:
            if self.retain:
                return await ctx.send("Variable retention is already set to ON.")

            self.retain = True
            self._scope = Scope()
            return await ctx.send("Variable retention is ON. Future REPL sessions will retain their scope.")

        if not self.retain:
            return await ctx.send("Variable retention is already set to OFF.")

        self.retain = False
        return await ctx.send("Variable retention is OFF. Future REPL sessions will dispose their scope when done.")