Skip to main content

A discord.py extension including useful tools for bot development and debugging.

Project description

py license status travis circle appveyor issues commit

jishaku is a debugging and experimenting cog for Discord bots using discord.py.

It is locked to Python 3.6+ and requirements will shift as new discord.py and Python versions release. This repo primarily exists for the purpose of example and usage in other bot projects.

Some documentation is available on readthedocs. If in doubt, all commands have docstrings visible from the help command.

Installing

This cog can be installed through the following command:

python3 -m pip install -U jishaku

Or the development version:

From GitHub:

python3 -m pip install -U git+https://github.com/Gorialis/jishaku@master#egg=jishaku

From GitLab:

python3 -m pip install -U git+https://gitlab.com/Gorialis/jishaku@master#egg=jishaku

It can be used in bots directly using

bot.load_extension("jishaku")

Functionality

Extension loading/unloading

Jishaku contains 3 commands for loading and unloading extensions:

  • [jishaku|jsk] load [exts...]

  • [jishaku|jsk] reload [exts...]

  • [jishaku|jsk] unload [exts...]

These commands do as described, with reload unloading and loading cogs again for quick reloads. [exts...] are a set of extension names separated by spaces, such as cogs.one cogs.two cogs.three. reload is actually an alias of load, extensions are automatically reloaded based on their presence.

Reloading jishaku itself can be done conventionally with [jishaku|jsk] reload jishaku.

Task queue

Some actions jishaku can do may take a long time, and could be invoked incorrectly or by accident. As such, jishaku implements a command queue that long-lasting commands are submitted to.

  • [jishaku|jsk] tasks

  • [jishaku|jsk] cancel <id>

tasks shows which tasks are currently running, for what commands. You can use this to figure out which task you need to cancel.

cancel cancels a task by a given ID. It will accept a numeric ID as shown in tasks. Supplying -1 will make it cancel the last task submitted.

Python REPL

Jishaku can evaluate Python code with [jishaku|jsk] [python|py] <codeline|codeblock>.

Evaluation-like REPL is supported, allowing you to type statements like 3+4 or _ctx.author.name to return their result. This supports async syntax, so you can do evaluations like await coro() or [m async for m in _ctx.history()].

In large blocks, the last standalone expression will be returned if not in a control flow block.

Variables available in REPL are:

  • _bot: Represents the current commands.Bot instance.

  • _ctx: Represents the current commands.Context.

  • _message: Shorthand for _ctx.message

  • _msg: Shorthand for _ctx.message

  • _guild: Shorthand for _ctx.guild

  • _channel: Shorthand for _ctx.channel

  • _author: Shorthand for _ctx.message.author

These variables are local and cleared between sessions, so they will not persist into other sessions.

The underscore prefix is to help reduce accidental shadowing. If you don’t want your variables to be prefixed, set JISHAKU_NO_UNDERSCORE=true in your environment variables.

By default, variables are not shared at all between REPL contexts. You can use [jishaku|jsk] retain on to try and preserve locals between sessions.

Yielding inside of a codeblock allows you to return intermediate data as your code runs. Any objects yielded will be treated as if they were returned, without terminating execution.

(Note that as yielding creates an asynchronous generator, you can no longer return and must yield for all results you feed back.)

An alternate command is available, [jishaku|jsk] [python_inspect|pyi] <codeline|codeblock>.

This command performs identically as the standard REPL, but inspects yielded results instead of just formatting them.

Shell Interaction

Jishaku can interact with CLI programs with [jishaku|jsk] sh <codeline|codeblock>.

On Windows, this acts similar to Command Prompt.

On Linux, your shell is automatically determined from $SHELL, or set to bash if no such environment variable exists.

For bots maintained using the git version control system, a shortcut command [jishaku|jsk] git <codeline> is available.

This simply invokes the sh command, but prefixes with git to make running git commands easier, such as jsk git pull.

Command Invocation

Jishaku can invoke other commands on your bot in special modes:

  • [jishaku|jsk] sudo <command string>

  • [jishaku|jsk] debug <command string>

  • [jishaku|jsk] repeat <times> <command string>

  • [jishaku|jsk] su <member> <command string>

  • [jishaku|jsk] in <channel> <command string>

sudo invokes a command bypassing all checks and cooldowns. This may also invoke parent group callbacks, depending on how the command is defined. For example, jsk sudo foo will invoke foo regardless of if checks or cooldowns fail.

debug invokes a command normally, but as if it were in a Jishaku evaluation context with a timer. This means if an exception occurs, it will be direct messaged to you like as in jishaku python.

When execution finishes, the time taken to complete execution will be sent as a message.

repeat invokes a command many times in a row. It acts the same as a direct message invocation, so it will obey cooldowns if commands have them. As this command may take a long time, it is submitted to the task queue so it can be cancelled.

su invokes a command as if it was invoked directly by another member. This allows you to effectively impersonate another account to your own bot, such that you can perform actions on their behalf or test command behavior.

For example, jsk su @Clyde#0001 foo will invoke foo as if it was used directly by @Clyde#0001. This command won’t work on users that the bot cannot see.

Trying to use this command with a user that is not in the current guild (if applicable) will work, but may cause weird side effects, so it is recommended to restrict usage to available members.

in invokes a command as if it was invoked in another channel. In guilds, this only works in channels of the same guild, but can work across guilds if in is used in a DM.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jishaku-1.16.2.157.tar.gz (34.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

jishaku-1.16.2.157-py3.8.egg (78.8 kB view details)

Uploaded Egg

jishaku-1.16.2.157-py3.7.egg (78.6 kB view details)

Uploaded Egg

jishaku-1.16.2.157-py3.6.egg (78.5 kB view details)

Uploaded Egg

jishaku-1.16.2.157-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

File details

Details for the file jishaku-1.16.2.157.tar.gz.

File metadata

  • Download URL: jishaku-1.16.2.157.tar.gz
  • Upload date:
  • Size: 34.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0b4

File hashes

Hashes for jishaku-1.16.2.157.tar.gz
Algorithm Hash digest
SHA256 26f7e8d3048825cc7bc0a00a981076e734e05a37f5d8e3ddcaf1a43d47168d4f
MD5 bfd61c3d1b3ca6ab7eaf4ddfacaaf7e1
BLAKE2b-256 2dc7d1e1684ef22d1ce062017656364c8dd15d3bddfb414797e711b5354fa995

See more details on using hashes here.

File details

Details for the file jishaku-1.16.2.157-py3.8.egg.

File metadata

  • Download URL: jishaku-1.16.2.157-py3.8.egg
  • Upload date:
  • Size: 78.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0b4

File hashes

Hashes for jishaku-1.16.2.157-py3.8.egg
Algorithm Hash digest
SHA256 08e82d25a4717e25b2c35695afa412b584e36c93d416ddad6e1f710e5c7794cd
MD5 9190d3cc9ce224ab6c371a723938f9a2
BLAKE2b-256 99db987cfb52d2ca06b316947503e3b9e9a26563eddb2e0504418c938438dfba

See more details on using hashes here.

File details

Details for the file jishaku-1.16.2.157-py3.7.egg.

File metadata

  • Download URL: jishaku-1.16.2.157-py3.7.egg
  • Upload date:
  • Size: 78.6 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0b4

File hashes

Hashes for jishaku-1.16.2.157-py3.7.egg
Algorithm Hash digest
SHA256 f6c787a8a31938036d117c573abb4e1d238615e0fd4af86cc382eb870d5956f5
MD5 8d9bb10faa9f3cd66eb560125f1771d2
BLAKE2b-256 4f974ddeeaeea15de94375ec09b09b4ab280a0d8d77f007b58e8b6e5032c4198

See more details on using hashes here.

File details

Details for the file jishaku-1.16.2.157-py3.6.egg.

File metadata

  • Download URL: jishaku-1.16.2.157-py3.6.egg
  • Upload date:
  • Size: 78.5 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0b4

File hashes

Hashes for jishaku-1.16.2.157-py3.6.egg
Algorithm Hash digest
SHA256 1c053d2bd9548c542d734c17a74747dafbc6c52579b4febc4caaa43ce8582ece
MD5 70d1ff0b07984bdf85412e9db9364877
BLAKE2b-256 0bd64531be6e4fde3e65406c5d1fa3d9e4414c6dcfadd6ed69d2bb23652f415b

See more details on using hashes here.

File details

Details for the file jishaku-1.16.2.157-py3-none-any.whl.

File metadata

  • Download URL: jishaku-1.16.2.157-py3-none-any.whl
  • Upload date:
  • Size: 36.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0b4

File hashes

Hashes for jishaku-1.16.2.157-py3-none-any.whl
Algorithm Hash digest
SHA256 f448c53f31ff9b0dddab546c62fcf044a7432a6671f93c164f5c29f5b11c292a
MD5 e62fcb4b0a0743e7ff26e75aab5c47e2
BLAKE2b-256 d868274cbce55e16fc8755e4691b770f238f29f76a0c1336672f2da69e005220

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page