Giter VIP home page Giter VIP logo

jishaku's Introduction

Python versions License Status Issues Commit activity


  jishaku

a debugging and utility extension for discord.py bots
Read the documentation online.


jishaku is an extension for bot developers that enables rapid prototyping, experimentation, and debugging of features for bots.

One of jishaku's core philosophies is to be dynamic and easy-to-use. Here's the two step install:

  1. Download jishaku on the command line using pip:
pip install -U jishaku
  1. Load the extension in your bot code before it runs:
bot.load_extension('jishaku')
# or
await bot.load_extension('jishaku')

That's it!

You can also import the module to use the command development utilities.

Index

Command reference

> jishaku [py|python] <argument>

> jishaku [pyi|python_inspect] <argument>

The Python commands execute or evaluate Python code passed into them. It supports simple expressions:

> jsk py 3+4

Beep Bot

7

It also supports async expressions:

> jsk py await _ctx.pins()

Beep Bot

[<Message id=123456789012345678 ...>, ...]

You can pass in codeblocks for longer blocks of code to execute, and you can use yield to return intermediate results within your processing.

The inspect variant of the command will return a codeblock with detailed inspection information on all objects returned.

The variables available by default in all execution contexts are:

_ctx The Context that invoked the command.
_bot The running Bot instance.
_author
_channel
_guild
_me
_message
_msg
Shortcuts for attributes on _ctx.
_find
_get
Shortcuts for discord.utils functions.

The underscore prefix on the provided variables is intended to help prevent shadowing when writing large blocks of code within the command.
If you decide that you don't want the prefix, you can disable it by setting the JISHAKU_NO_UNDERSCORE environment variable to true.

Each Python command is individually scoped. That means variables you create won't be retained in later invocations.
You can use jishaku retain on to change this behavior and retain variables, and jishaku retain off if you change your mind later.

> jishaku [dis|disassemble] <argument>

This command compiles Python code in an asynchronous context, and then disassembles the resulting function into Python bytecode in the style of dis.dis.

This allows you to quickly and easily determine the bytecode that results from a given expression or piece of code. The code itself is not actually executed.

> jishaku ast <argument>

This command compiles Python code into its Abstract Syntax Tree, and then displays it as a formatted tree of AST blocks.

> jishaku [sh|shell] <argument>

The shell command executes commands within your system shell.

If you're on Linux and are using a custom shell, jishaku will obey the SHELL environment variable, otherwise, it will use /bin/bash.
On Windows, jishaku will use PowerShell if it's detected, otherwise, it will use Command Prompt.

The results from the commands you pass in are returned through a paginator interface live as the command runs. If you need to stop a command, you can press the stop button reaction, or use jsk cancel.

The execution will terminate automatically if no output is produced for 120 seconds.

> jishaku git <argument>

> jishaku pip <argument>

These commands act as shortcuts to the shell command, so you can save typing a word if you use these frequently.

> jishaku [load|reload] [extensions...]

> jishaku unload [extensions...]

These commands load, reload, or unload extensions on your bot.

You can reload jishaku itself with jsk reload jishaku.
jsk reload ~ will reload all extensions on your bot.

You can load, reload, or unload multiple extensions at once: jsk reload cogs.one cogs.two

> jishaku shutdown

This command gracefully shuts down your bot.

> jishaku rtt

This command calculates Round-Trip Time for your bot to the API. It does this by calculating response time samples, so you can tell if your bot is being slow or not.

> jishaku sync [guild_ids...]

This command syncs the app_command tree for a list of guilds, or globally if none are given, and then reports the results.

> jishaku cat <file>

This command reads a file from your file system, automatically detecting encoding and (if applicable) highlighting.

You can use this to read things like bot logs or source files in your project.

> jishaku curl <url>

This command reads text from a URL and attempts to detect encoding and language, similar to jsk cat.

You can use this to display contents of files online, for instance, the message.txt files created when a message is too long, or raw files from paste sites.

> jishaku exec [member and/or channel...] <command string>

> jishaku debug <command string>

> jishaku repeat <times> <command string>

These commands serve as command control for other commands.

jishaku exec allows you to execute a command as another user, in another channel, or both. Using aliases with a postfix exclamation mark (such as jsk exec! ...) executes the command bypassing checks and cooldowns.

jishaku debug executes a command with an exception wrapper and a timer. This allows you to quickly get feedback on reproducable command errors and slowdowns.

jishaku repeat repeats a command a number of times.

> jishaku permtrace <channel> [targets...]

This command allows you to investigate the source of expressed permissions in a given channel. Targets can be either a member, or a list of roles (to simulate a member with those roles).

It will read all of the guild permissions and channel overwrites for the given member or roles in the channel, and provide a breakdown containing whether the permission is granted, and the most fundamental reason why.

Installing development versions

If you'd like to test the latest versions of jishaku, you can do so by downloading from the git hosts instead of from PyPI.

From GitHub:

pip install -U "jishaku @ git+https://github.com/Gorialis/jishaku@master"

From GitLab:

pip install -U "jishaku @ git+https://gitlab.com/Gorialis/jishaku@master"

Please note that the new 2020 dependency resolver now no longer discounts git package sources from reinstall prevention, which means that if you are installing the jishaku development version multiple times within the same version target you may run into pip just discarding the update.

If you run into such a problem, you can force jishaku to be reinstalled like this:

From GitHub:

pip install -U --force-reinstall "jishaku @ git+https://github.com/Gorialis/jishaku@master"

From GitLab:

pip install -U --force-reinstall "jishaku @ git+https://gitlab.com/Gorialis/jishaku@master"

You must have installed jishaku with one of the commands above before doing this else you will probably end up with a broken installation.

Acknowledgements

The documentation and this README uses icons from the Material Design Icon library, which is licensed under the Apache License Version 2.0.

jishaku's People

Contributors

abstractumbra avatar bhagyajbijukumar avatar bmintz avatar bobdotcom avatar clari7744 avatar codewithswastik avatar daggy1234 avatar deadsafari avatar fretgfr avatar gorialis avatar imnimboss avatar interstella0 avatar ioistired avatar itslychee avatar lee-matod avatar leocx1000 avatar lostluma avatar makonede avatar ncplayz avatar owocado avatar starrfox avatar tuna2134 avatar z03h avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

jishaku's Issues

not omitting bot token

Summary

invoking jsk py _bot.http.token covers the token, but invoking it as jsk py await _ctx.send(_bot.http.token) does not

Reproduction steps

doing jsk py await _ctx.send(_bot.http.token)

Expected results

Covering the token in both ways

Actual results

It didnt the cover in jsk py await _ctx.send(_bot.http.token)

Checklist

  • I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • I have searched the open issues for duplicates
  • I have shown the entire traceback, if possible
  • I have removed my token from display, if visible

System information

Jishaku v1.18.2, discord.py 1.3.2, Python 3.8.2 (default, Mar 10 2020, 03:00:36) [GCC 7.4.0] on linux

A suggestion

Hello, I've a suggestion I wanted to add it to jsk source code but I didn't understand the source code, but anyway the suggestion is:
Having something like a flag --catch-buffer that's a boolean value, that catches the buffer printed to the terminal for jsk py subcommand or any commmand that runs code I found sometimes useful so I won't reconnect to the host again to get the printed results

About the error when restarting the bot

I'm using a shell script to allow the bot to restart, but when I use jishaku to log out (jsk logout) and restart, I get the following error message:

Unhandled exception during Client.run shutdown.
task: <Task finished name='Task-118' coro=<PaginatorInterface.wait_loop() done, defined at /home/takkun/.local/lib/python3.8/site-packages/jishaku/paginators.py:206> exception=RuntimeError('Session is closed')>
Traceback (most recent call last):
  File "/home/takkun/.local/lib/python3.8/site-packages/jishaku/paginators.py", line 236, in wait_loop
    payload = await self.bot.wait_for('raw_reaction_add', check=check, timeout=self.timeout)
  File "/usr/local/lib/python3.8/asyncio/tasks.py", line 476, in wait_for
    await waiter
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/takkun/.local/lib/python3.8/site-packages/jishaku/paginators.py", line 268, in wait_loop
    await self.message.remove_reaction(emoji, self.bot.user)
  File "/home/takkun/.local/lib/python3.8/site-packages/discord/message.py", line 1186, in remove_reaction
    await self._state.http.remove_own_reaction(self.channel.id, self.id, emoji)
  File "/home/takkun/.local/lib/python3.8/site-packages/discord/http.py", line 185, in request
    async with self.__session.request(method, url, **kwargs) as r:
  File "/home/takkun/.local/lib/python3.8/site-packages/aiohttp/client.py", line 1117, in __aenter__
    self._resp = await self._coro
  File "/home/takkun/.local/lib/python3.8/site-packages/aiohttp/client.py", line 381, in _request
    raise RuntimeError("Session is closed")
RuntimeError: Session is closed

What does this mean?
And how can I fix it?

[Shell script source]

#!/bin/bash
while :
do
    python3.8 main.py
    if [ "false" = `cat reboot.txt` ]; then
        break
    fi
done

[Source of main.py]
https://gist.github.com/dpy-manager-bot/b74e2ccb741260698c6d073ba1ecf2ae#file-main-py

Team administrator does not count as owner.

You cannot use jishaku modules if a bot application is part of a team, part of the new 'Discord Developer License', as it believes that a team administrator does not count as the owner of a bot.

Paginator can block on large results

Summary

When the pagination result from jishaku python is extremely long (hundreds of thousands of lines), preparing the paginator can block the bot off Discord

Reproduction steps

jishaku python '\n'.join(['This is a long string of text that will be reproduced 1,000,000 times.'] * 1_000_000)

Expected results

The bot returns a paginator with hundreds of thousands of pages

Actual results

The bot drops offline.

2020-12-07 09:04:00,246 (PID:3244) - WARNING - Shard ID None heartbeat blocked for more than 170 seconds.
Loop thread traceback (most recent call last):
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/pi/pikalaxbot/pikalaxbot/__main__.py", line 124, in <module>
    sys.exit(main())
  File "/home/pi/pikalaxbot/pikalaxbot/__main__.py", line 119, in main
    bot.run()
  File "/home/pi/pikalaxbot/pikalaxbot/__init__.py", line 127, in run
    super().run(token)
  File "/usr/local/lib/python3.9/site-packages/discord/client.py", line 708, in run
    loop.run_forever()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 596, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1890, in _run_once
    handle._run()
  File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.9/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 942, in on_message
    await self.process_commands(message)
  File "/usr/local/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 939, in process_commands
    await self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 902, in invoke
    await ctx.command.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 1329, in invoke
    await ctx.invoked_subcommand.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 859, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/usr/local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/jishaku/cog_base.py", line 535, in jsk_python
    paginator.add_line(result)
  File "/usr/local/lib/python3.9/site-packages/jishaku/paginators.py", line 369, in add_line
    line = line[position:]

Checklist

  • I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • I have searched the open issues for duplicates
  • I have shown the entire traceback, if possible
  • I have removed my token from display, if visible

System information

Jishaku v1.20.0, discord.py 1.6.0a2599+g6e6a3be, Python 3.9.0 (default, Oct 11 2020, 13:08:01) [GCC 8.3.0] on linux

imports not working

Summary

I was working on subclassing the jishaku command to make it work with my command system, but for some reason I am missing things in my jishaku but jishaku does still seem to work. I have tried this on both 1.20.0 and 2.0.0 and with both I have the same issue...

Reproduction steps

I'm not sure. I completely reinstalled jishaku, and I even tried loading just by bot.load_extension("jishaku") in stead of the file with my subclass.

Expected results

Having access to anything in jishaku

Actual results

Dont have access to basically everything. ( https://media.discordapp.net/attachments/381963689470984203/787497858994798602/unknown.png )

Checklist

  • I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • I have searched the open issues for duplicates
  • I have shown the entire traceback, if possible
  • I have removed my token from display, if visible

System information

Jishaku 1.20.0 (and tried 2.0.0 as well),
discord.py 1.5.1

PaginatorInterface stops being interactive when message leaves the cache

Using jishaku on a bot which has a smaller than default message cache or receives a lot of messages currently causes paginators to stop being interactive before the one hour timeout.

It would be useful if instead of relying on messages being in the cache raw events were used, as this behavior is pretty irritating when trying to debug.

Jishaku error

I have Error.
discord.ext.commands.errors.ExtensionNotFound: Extension 'jishaku' could not be loaded

bot.load_extension('jishaku')
Supplied by jishaku. Pip install jishaku.

Add _get and _find helpers

This isn't a pull request because the implementation is quite trivial, but I propose that _get and _find should be added to the injected locals of jishaku's repl. These will obviously correlate to discord.utils.get and discord.utils.find.

I propose this change because these two functions are quite commonly used throughout code that uses Discord.py, both in cog code and in repl code.

Statistics

Searching for "jsk py discord.utils.get" in the Discord.py server returns 98 results, so we know that this function is used commonly in the jishaku repl. "jsk py discord.utils.find" returns 14 results.

While the latter result is not as common, I believe that it should be included alongside get as they seem to work in conjunction in performing a similar task (fetching something from an iterable due to arbitrary criteria).

Length-wise, these aliases would also save on typing. For example, _author is aliased to _ctx.author. That saves about 4 characters of typing. However, the _get alias would save 13 characters of typing total, which is a larger benefit. Alongside being a larger benefit, this function is used all over the place (see aforementioned points), so I believe that it would be worth it to include.

Naming

I don't think that the _get and _find names can be easily mistaken for something else, or that conflicts will be introduced. There is already the _ prefix, and even moderately experienced Discord.py developers are able to infer what the function aliases to due to their ubiquitous usage in various codebases.

add an environment variable that sends tracebacks to the channel

something like JISHAKU_TRACEBACK_NO_DM would prevent DMing tracebacks. The reason to hide them is normally cause sometimes the traceback can supposedly go back to bot.run('token'), but for many that's not an issue, and the convenience of seeing tracebacks in the same place as the repl commands would be preferred.

Request: Redirect STDERR/STDOUT to DMs

Not everything I have to test is ran on commands, some of it runs on events instead.

It would be useful for jishaku to have a command to temporarily enable sending the contents of anything send to stderr and stdout to the owners DMs.

A similar feature already exists in Discord-Selfbot which could be used as a base for this.

jsk as selftest causes incorrect commands to run a selftest instead of not saying anything

This is an enhancement request, not a bug report.

Please bring back jsk selftest

problem step

jsk await _ctx.send('foo')

expected output

Nothing

actual output

Jishaku v1.2.1 is active. (3908 guild(s), 270666 user(s))
Module load time: 5 days ago
Using automatic sharding.
Average websocket latency: 52.14ms

why that differs from my expectations

If i say jsk Foo+3 that's a mistake, not an intentional invocation of the selftest command. Having jsk as the selftest effectively adds a "command not found" message. Since Foo+3 is an invalid Jishaku command, I'd expect there to be no output.

I also believe that a selftest is not something that needs to be run often enough to warrant saving characters on the command invocation.

imports not working

Summary

I was working on subclassing the jishaku command to make it work with my command system, but for some reason I am missing things in my jishaku but jishaku does still seem to work. I have tried this on both 1.20.0 and 2.0.0 and with both I have the same issue...

Reproduction steps

I'm not sure. I completely reinstalled jishaku, and I even tried loading just by bot.load_extension("jishaku") in stead of the file with my subclass.

Expected results

Having access to anything in jishaku

Actual results

Dont have access to basically everything. ( https://media.discordapp.net/attachments/381963689470984203/787497858994798602/unknown.png )

Checklist

  • I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • I have searched the open issues for duplicates
  • I have shown the entire traceback, if possible
  • I have removed my token from display, if visible

System information

Jishaku 1.20.0 (and tried 2.0.0 as well),
discord.py 1.5.1

Close reason for PaginatorInterface

The Problem

I'd like to delete the invoking command when a user uses the close button on a PaginatorInterface.
As I do not use the delete_message option I don't want to unconditionally do this when the interface is done.

The Ideal Solution

Have some way of knowing whether the interface was closed by the user, or was closed via the timeout.

interface = PaginatorInterface(...)
await interface.send_to(channel)

await interface.task

if interface.closed_by_user:  # How exactly this looks doesn't really matter to me
    await ctx.message.delete()

The Current Solution

One could wait for the message to be deleted, however this seems rather impractical if used in more than one location:

interface = PaginatorInterface(...)
await interface.send_to(channel)

try:
    # This has the issue of not even working properly as the timeout counts from last button use
    await bot.wait_for('raw_message_delete', check=lambda x: x.message_id = interface.message.id, timeout=interface.timeout)
except asyncio.TimeoutError:
    return

await ctx.message.delete()

Summary

Knowing whether a PaginatorInterface was closed manually or via the timeout.

Windows Server 2019 shell pm2 error

Summary

Reproduction steps

Expected results

jishaku shell -> pm2 list

Actual results

cmd > pm2

[stderr] child_process.js:127
[stderr] p.open(fd);
[stderr] ^
[stderr]
[stderr] Error: EBADF: bad file descriptor, uv_pipe_open
[stderr] at Object._forkChild (child_process.js:127:5)
[stderr] at setupChildProcessIpcChannel (internal/bootstrap/pre_execution.js:337:30)
[stderr] at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:59:3)
[stderr] at internal/main/run_main_module.js:7:1 {
[stderr] errno: -4083,
[stderr] code: 'EBADF',
[stderr] syscall: 'uv_pipe_open'
[stderr] }

[status] Return code 1

Checklist

  • I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • I have searched the open issues for duplicates
  • I have shown the entire traceback, if possible
  • I have removed my token from display, if visible

System information

Jishaku v1.20.0, discord.py 1.6.0, Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32

Unable to receive messages

Summary

Jishaku seems to throw an error when attempting to send a msg via multiple commaands:

  • jsk help
  • jsk cog

Reproduction steps

Running jsk help

Expected results

a proper execution of the command

Actual results

Ignoring exception in on_command_error
Traceback (most recent call last):
File "/home/botuser/.local/lib/python3.7/site-packages/discord/client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "main.py", line 104, in on_command_error
await channel.send(embed=embed)
AttributeError: 'NoneType' object has no attribute 'send'

Checklist

  • I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • I have searched the open issues for duplicates
  • I have shown the entire traceback, if possible
  • I have removed my token from display, if visible

System information

Python v3.7.3-final discord.py v1.3.3-final aiohttp v3.6.2 websockets v8.1 system info: Linux 4.19.0-8-cloud-amd64 #1 SMP Debian 4.19.98-1 (2020-01-26)

Name: jishaku Version: 1.18.2.190 Summary: A discord.py extension including useful tools for bot development and debugging. Home-page: https://github.com/Gorialis/jishaku Author: Devon (Gorialis) R Author-email: None License: MIT Location: /home/botuser/.local/lib/python3.7/site-packages Requires: import-expression, discord.py, braceexpand, humanize Required-by:

PaginatorInterface timeout no longer works

Summary

PaginatorInterfaces created in v2 after 3389383 seem to never close,
as asyncio.wait does not raise asyncio.TimeoutError on timeout, but simply returns with no tasks being done:

https://docs.python.org/3/library/asyncio-task.html#asyncio.wait

Note that this function does not raise asyncio.TimeoutError. Futures or Tasks that aren’t done when the timeout occurs are simply returned in the second set.

Reproduction steps

Create an instance of PaginatorInterface with a small timeout and use the send_to method.

Expected results

All reactions by the bot are removed after the timeout is over, and the buttons are thus no longer usable.

Actual results

Reactions stay on the interface's message and the buttons are usable regardless of the timeout being over.

Checklist

  • I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • I have searched the open issues for duplicates
  • I have shown the entire traceback, if possible
  • I have removed my token from display, if visible

System information

Jishaku v2.0.0 @ 69a58f2
discord.py 1.7.0a2789+g1db3560 (running a forked branch, up to date with official master though)

Reassignment of retained vars within one repl invocation causes UnboundLocalError

Summary

Reassignment of retained variables causes UnboundLocalError

Reproduction steps

  1. jsk retain 1
  2. jsk py x = 1
  3. jsk py x = x + 1

Expected results

x is reassigned to 2.

Actual results

Traceback (most recent call last):
  File ".venv/lib/python3.8/site-packages/jishaku/cog_base.py", line 494, in jsk_python
    async for send, result in AsyncSender(executor):
  File ".venv/lib/python3.8/site-packages/jishaku/functools.py", line 109, in _internal
    value = await base.asend(self.send_value)
  File ".venv/lib/python3.8/site-packages/jishaku/repl/compilation.py", line 151, in traverse
    yield await func(*self.args)
  File "<repl>", line 1, in _repl_coroutine
UnboundLocalError: local variable 'x' referenced before assignment

Checklist

  • I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • I have searched the open issues for duplicates
  • I have shown the entire traceback, if possible (other than abbreviating path names)
  • I have removed my token from display, if visible

System information

  • Python v3.8.0-final
  • discord.py v1.3.0-alpha
    • discord.py pkg_resources: v1.3.0a2146+g4ef0fb0
  • aiohttp v3.6.2
  • websockets v6.0
  • system info: Linux 4.19.0-6-amd64 #​1 SMP Debian 4.19.67-2+deb10u1 (2019-09-20)
  • jishaku v1.17.0.172

Remarks

This is apparently due to x being a global name. Ideally we could pass in locals to the user-defined code, but this is not possible, even with PyCF_ALLOW_TOP_LEVEL_AWAIT. Fixing this might require transforming all name lookups to globals()['x'] if x in globals() else x.

[feature] say something as another user

The Problem

Lots of times when testing things I use jsk su to run a command as another user.

However, it's difficult to do so when there are confirmation prompts involved that require the user to send a message. I could login on different browser profiles, but it's difficult to manage when lots of accounts are involved as Discord tends to phone lock these accounts.

The Ideal Solution

Something like jsk susay @user message that dispatches a message event with the author and content. (not sure what to call it.)

The Current Solution

Use jsk py to run some dispatch code

Summary

It'd be nice to have this feature. Though, I don't know whether this falls within the scope of the module. I guess it might be too specific of a feature, and it might be weird to add this without adding similar things for other events. Maybe a generic dispatch command, then. Though, that's really close to just writing code at that point.

Please let me know your thoughts. I'd be willing to submit a PR if you'd be willing to have this feature. Also, suggestions for a name

Make it easier to create aliases for commands

The Problem

I would love it if you could make it easier to add aliases without overriding commands. I think it would make life easier for quite a few people.

The Ideal Solution

Add a command for it (!jsk alias [command] [allias])

The Current Solution

Currently you need to make your own cog or edit the source code (which is tedious since you'll have to redo it every time there is an update)

Summary

Make it easier to add aliases without overriding commands.

jsk py: docstrings get indented

Problem steps

ec/jsk py
exec("""
from __future__ import braces
""")

Expected result

Traceback (most recent call last):
  File "<string>", line None
SyntaxError: not a chance

Actual result

Traceback (most recent call last):
  File "<string>", line 2
    from __future__ import braces
    ^
IndentationError: unexpected indent

Suspected cause

def get_wrapped_code(code: str, args: str = ''):
"""
Wraps code into an async function body for REPL.
"""
return CORO_CODE.format(args, textwrap.indent(code, ' ' * 8))

String formatting causes the entire function to be indented, creating this:

async def _repl_coroutine():
    prologue()

    try:

        exec('''
        from __future__ import braces
        ''')

    finally:
        epilogue()

Where ideally it would look like this:

async def _repl_coroutine():
    prologue()

    try:

        exec('''
from __future__ import braces
''')

    finally:
        epilogue()

Suggested fix

  1. Pre-parse the CORO_CODE into an AST, using pass as the body of the try block.
  2. In get_wrapped_code: Parse the user code into another AST.
  3. Replace the pass body of CORO_CODE with the parsed user code.

Afterwards, maybe_add_return would use import_expression.parse_ast instead of import_expression.parse, then do its post-processing of yield and return statements.

Automatically expose cogs as globals in python eval

The Problem

Almost every time I invoke jsk py, it starts with _bot.get_cog('MyCog'). It would be nice if this was exposed as _MyCog.

The Ideal Solution

Iterate over Bot.__cogs and expose them while generating the scope

The Current Solution

Turn on Retain Variables, and manually store cogs in the global context, or manually execute the search every time you eval something.

Token Leak via jishaku py

Summary

You are able to get the bot's token by using jishaku py

Reproduction steps

jsk py list(bot.http.token)

Expected results

The token is [token omitted].

Actual results

You get enough information to put together the bot's token.

Checklist

  • I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • I have searched the open issues for duplicates
  • I have shown the entire traceback, if possible
  • I have removed my token from display, if visible

System information

jiskaku version: 1.20.0.220
discord.py version: 1.6.0

jsk su as the bot doesn't work

jsk su <@my_bots_id> some command here

Expected output

The output of some with arguments command and here

Actual output

Command "None" is not found

Task exception was never retrieved

Summary

SO I use sentry.io for error logging and discovered this error happening quite frequently.

Task exception was never retrieved
future: <Task finished name='Task-14762120' coro=<PaginatorInterface.update() done, defined at /usr/local/lib/python3.8/dist-packages/jishaku/paginators.py:272> exception=NotFound('404 Not Found (error code: 10008): Unknown Message')>

https://sentry.io/share/issue/48cb426e53e649058eda70f39719eee3/

All the data is at the link above!

pip install jishaku requires a non existing version of discord

Summary

When running pip install jishaku i get following error:
Collecting discord.py>=1.3.0a2084 (from jishaku) Could not find a version that satisfies the requirement discord.py>=1.3.0a2084 (from jishaku) (from versions: 0.1.0, 0.2.0, 0.2.1, 0.3.0, 0.3.1, 0.4.0, 0.4.1, 0.5.0, 0.5.1, 0.6.0, 0.6.1, 0.6.2, 0.6.3, 0.7.0, 0.8.0, 0.9.0, 0.9.1, 0.9.2, 0.10.0, 0.11.0, 0.12.0, 0.13.0, 0.14.0, 0.14.1, 0.14.2, 0.14.3, 0.15.0, 0.15.1, 0.16.0, 0.16.1, 0.16.2, 0.16.3, 0.16.4, 0.16.5, 0.16.6, 0.16.7, 0.16.8, 0.16.9, 0.16.10, 0.16.11, 0.16.12, 1.0.0, 1.0.1, 1.1.0, 1.1.1, 1.2.0, 1.2.1, 1.2.2, 1.2.3) No matching distribution found for discord.py>=1.3.0a2084 (from jishaku)

Reproduction steps

run pip install jishaku in command prompt

Expected results

Jishaku installs

Actual results

Error saying that discord version was not found

Checklist

  • [x ] I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • [x ] I have searched the open issues for duplicates
  • [ x] I have shown the entire traceback, if possible
  • [ x] I have removed my token from display, if visible

System information

No jishaku and discord.py 1.3.0a

Local Host .env variable JISHAKU_NO_UNDERSCORE = true doesn't work

Summary

I am trying to remove the _ before ctx, author... and if I do it with a host it works, but if I do it in local host it doesn't work.

Reproduction steps

Create a .env file, add JISHAKU_NO_UNDERSCORE = true to it, run a thing like jsk py author.name

Expected results

It should work without the underscore

Actual results

It works only with the underscore

Checklist

  • [ x] I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • [x ] I have searched the open issues for duplicates
  • I have shown the entire traceback, if possible
  • [ x] I have removed my token from display, if visible

System information

Jishaku: Version: 1.18.1.187
discord.py: Version: 1.3.2
Ruuning on Windows-10-10.0.18362-SP0

GroupCogMeta overwrites the superclass's command parents

Summary

JishakuBase's commands are altered by GroupCogMeta when they should not

Reproduction steps


from jishaku import JishakuBase
from jishaku.metacog import GroupCogMeta
from discord.ext import commands

bot = commands.Bot('!')

@commands.group()
async def not_jsk(self, ctx):
    pass

class MyJsk(JishakuBase, metaclass=GroupCogMeta, command_parent=not_jsk):
    pass

MyJsk(bot)

Expected results

Should make a new cog with not_jsk as the parent of all commands

Actual results

Traceback (most recent call last):
  File "/home/starrfox/bots/Discord-chan/venv/lib/python3.7/site-packages/jishaku/cog_base.py", line 494, in jsk_python
    async for send, result in AsyncSender(executor):
  File "/home/starrfox/bots/Discord-chan/venv/lib/python3.7/site-packages/jishaku/functools.py", line 109, in _internal
    value = await base.asend(self.send_value)
  File "/home/starrfox/bots/Discord-chan/venv/lib/python3.7/site-packages/jishaku/repl/compilation.py", line 154, in traverse
    async for send, result in AsyncSender(func(*async_executor.args)):
  File "/home/starrfox/bots/Discord-chan/venv/lib/python3.7/site-packages/jishaku/functools.py", line 109, in _internal
    value = await base.asend(self.send_value)
  File "<repl>", line 13, in _repl_coroutine
  File "/home/starrfox/bots/Discord-chan/venv/lib/python3.7/site-packages/discord/ext/commands/cog.py", line 182, in __new__
    parent = lookup[parent.qualified_name]
KeyError: 'jishaku'

Checklist

  • I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • I have searched the open issues for duplicates
  • I have shown the entire traceback, if possible
  • I have removed my token from display, if visible

System information

Discord.py:

  • Python v3.7.3-final
  • discord.py v1.3.0-alpha
    • discord.py pkg_resources: v1.3.0a2157+g1b9108f
  • aiohttp v3.6.2
  • websockets v8.1
  • system info: Linux 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11)

jishaku:
Name: jishaku
Version: 1.17.0.169
Summary: A discord.py extension including useful tools for bot development and debugging.
Home-page: https://github.com/Gorialis/jishaku
Author: Devon (Gorialis) R
Author-email: None
License: MIT
Location: /home/starrfox/bots/Discord-chan/venv/lib/python3.7/site-packages
Requires: discord.py, braceexpand, import-expression, humanize

what's in a name?

Apparently jishaku means "magnet" in Japanese. Why'd you choose that name? Just curious.

triple backticks are not escaped in error messages

message: ec/jsk py '```foo```

Expected response

``​`py
Traceback (most recent call last):
  File "<repl-x session>", line 9
    '```foo
          ^
SyntaxError: EOL while scanning string literal
``​`​

Image: soon™

Actual response:

I can only provide a screenshot since the difference is invisible from looking at the source of the message
screenshot of the buggy behavior

This can be fixed by escaping the ```. A routine that escapes these is provided as part of spoo.py.

codeblocks which end on the same line as the code are not stripped

problem step

jsk py
`​`​`py
1+1`​`​`

or

jsk py `​`​`py
1+1`​`​`

expected result

2

actual result

Traceback (most recent call last):
  File "<string>", line 1
    1+1`​``
       ^
SyntaxError: invalid syntax

remarks

i'd fix this myself but i don't understand your regex lol

paginator: support the TextIO interface

Would allow doing like

out = jishaku.IOPaginator()
yield jishaku.PaginatorInterface(out)
dis.dis(some_code, file=out)

And the message would get updated as out is written to. It's up to you whether to support .seek

cannot delete retained vars

problem steps

jsk retain ON
jsk py x = 1
jsk py del x

expected result

no output

actual result

UnboundLocalError: local variable 'x' referenced before assignment

Jishaku env variables not working

Summary

I was making a new test bot on my mac, using this code:

bot = commands.Bot(command_prefix=';',intents=discord.Intents.all(),case_insensitive=True)
os.environ['JISHAKU_NO_UNDERSCORE'] = 'True'
os.environ['JISHAKU_RETAIN'] = 'True'
bot.load_extension('jishaku')

However, jishaku is running without either of these options enabled. It worked on my other bot (jsk 1.20, python 3.8.5 on Linux Ubuntu) but it doesnt work on my test bot (jsk 1.20, python 3.8.2 on macOS Catalina). I've tried making them capital and lowercase, but it doesn't do anything. Also, I did reinstall jsk on both devices today.

Image

Reproduction steps

I haven't been able to run the code without this bug with this setup.

Expected results

Jishaku no underscore and jishaku retain to work.

Actual results

They didnt, although the env variables are working.

Checklist

  • I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • I have searched the open issues for duplicates
  • I have shown the entire traceback, if possible (not needed, the traceback is as expected with this bug)
  • I have removed my token from display, if visible

System information

  • Jishaku Version: 1.20.0.220
  • Python v3.8.2-final
  • discord.py v1.6.0-alpha
    • discord.py pkg_resources: v1.5.1
  • aiohttp v3.7.3
  • system info: Darwin 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020

Jishaku isn't working at all on any of my bots anymore

Summary

Actual results

Checklist

  • I have updated discord.py and jishaku to the latest available versions and have confirmed that this issue is still present
  • I have searched the open issues for duplicates
  • I have shown the entire traceback, if possible
  • I have removed my token from display, if visible

System information

Paginator does not support long lines

problematic command

jsk py ``​`
('e'*1976+'\n')*3
`​``​

expected output

a lot of e

actual output

DMed traceback:

Traceback (most recent call last):
  File "/home/bots/.local/lib/python3.7/site-packages/jishaku/cog.py", line 291, in jsk_python
    paginator.add_line(result)
  File "/home/bots/.local/lib/python3.7/site-packages/jishaku/paginators.py", line 332, in add_line
    super().add_line(line, empty=empty)
  File "/home/bots/.local/lib/python3.7/site-packages/discord/ext/commands/formatter.py", line 94, in add_line
    raise RuntimeError('Line exceeds maximum page size %s' % (self.max_size - len(self.prefix) - 2))
RuntimeError: Line exceeds maximum page size 1975

Cannot install

On a fresh python3.6 venv I get:

└> command pip3 install jishaku
Collecting jishaku
Collecting discord.py>=1.0.0a1430 (from jishaku)
  Could not find a version that satisfies the requirement discord.py>=1.0.0a1430 (from jishaku) (from versions: 0.1.0, 0.2.0, 0.2.1, 0.3.0, 0.3.1, 0.4.0, 0.4.1, 0.5.0, 0.5.1, 0.6.0, 0.6.1, 0.6.2, 0.6.3, 0.7.0, 0.8.0, 0.9.0, 0.9.1, 0.9.2, 0.10.0, 0.11.0, 0.12.0, 0.13.0, 0.14.0, 0.14.1, 0.14.2, 0.14.3, 0.15.0, 0.15.1, 0.16.0, 0.16.1, 0.16.2, 0.16.3, 0.16.4, 0.16.5, 0.16.6, 0.16.7, 0.16.8, 0.16.9, 0.16.10, 0.16.11, 0.16.12)
No matching distribution found for discord.py>=1.0.0a1430 (from jishaku)

To fix it you have to remove the line from requirements.txt manually and install discord.py before installing jishaku.

`jsk py False` sends nothing back

Steps to reproduce

  1. Send <prefix>jsk py False or <prefix>jsk py _msg.author.bot

Expected behavior

False is sent back

Actual behavior

Nothing is sent back

Workaround

Use pywhat or wrap expressions that evaluate to booleans in a call to str().

Add `update` command to Jishaku

Currently, you can run a few commands to update Jishaku on the bot remotely through Discord, and this would be a cool thing to be able to do with one simple update command.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.