Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for the mobile/force paginator flag #111

Merged
merged 1 commit into from Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions jishaku/features/filesystem.py
Expand Up @@ -24,6 +24,7 @@
from jishaku.features.baseclass import Feature
from jishaku.hljs import get_language, guess_file_traits
from jishaku.paginators import PaginatorInterface, WrappedFilePaginator
from jishaku.flags import JISHAKU_FORCE_PAGINATOR


class FilesystemFeature(Feature):
Expand Down Expand Up @@ -68,7 +69,7 @@ async def jsk_cat(self, ctx: commands.Context, argument: str): # pylint: disabl

try:
with open(path, "rb") as file:
if size < 50_000: # File "full content" preview limit
if size < 50_000 and not ctx.author.is_on_mobile() and not JISHAKU_FORCE_PAGINATOR: # File "full content" preview limit
if line_span:
content, *_ = guess_file_traits(file.read())

Expand Down Expand Up @@ -116,7 +117,7 @@ async def jsk_curl(self, ctx: commands.Context, url: str):
if not data:
return await ctx.send(f"HTTP response was empty (status code {code}).")

if len(data) < 50_000: # File "full content" preview limit
if len(data) < 50_000 and not ctx.author.is_on_mobile() and not JISHAKU_FORCE_PAGINATOR: # File "full content" preview limit
# Shallow language detection
language = None

Expand Down
3 changes: 2 additions & 1 deletion jishaku/features/invocation.py
Expand Up @@ -24,6 +24,7 @@
from jishaku.features.baseclass import Feature
from jishaku.models import copy_context_with
from jishaku.paginators import PaginatorInterface, WrappedPaginator
from jishaku.flags import JISHAKU_FORCE_PAGINATOR


class InvocationFeature(Feature):
Expand Down Expand Up @@ -150,7 +151,7 @@ async def jsk_source(self, ctx: commands.Context, *, command_name: str):
# getsourcelines for some reason returns WITH line endings
source_text = ''.join(source_lines)

if len(source_text) < 50_000: # File "full content" preview limit
if len(source_text) < 50_000 and not ctx.author.is_on_mobile() and not JISHAKU_FORCE_PAGINATOR: # File "full content" preview limit
await ctx.send(file=discord.File(
filename=filename,
fp=io.BytesIO(source_text.encode('utf-8'))
Expand Down
8 changes: 4 additions & 4 deletions jishaku/features/python.py
Expand Up @@ -19,7 +19,7 @@
from jishaku.codeblocks import codeblock_converter
from jishaku.exception_handling import ReplResponseReactor
from jishaku.features.baseclass import Feature
from jishaku.flags import JISHAKU_RETAIN, SCOPE_PREFIX
from jishaku.flags import JISHAKU_RETAIN, SCOPE_PREFIX, JISHAKU_FORCE_PAGINATOR
from jishaku.functools import AsyncSender
from jishaku.paginators import PaginatorInterface, WrappedPaginator
from jishaku.repl import AsyncCodeExecutor, Scope, all_inspections, disassemble, get_var_dict_from_ctx
Expand Down Expand Up @@ -115,7 +115,7 @@ async def jsk_python(self, ctx: commands.Context, *, argument: codeblock_convert

send(await ctx.send(result.replace(self.bot.http.token, "[token omitted]")))

elif len(result) < 50_000: # File "full content" preview limit
elif len(result) < 50_000 and not ctx.author.is_on_mobile() and not JISHAKU_FORCE_PAGINATOR: # File "full content" preview limit
# Discord's desktop and web client now supports an interactive file content
# display for files encoded in UTF-8.
# Since this avoids escape issues and is more intuitive than pagination for
Expand Down Expand Up @@ -169,7 +169,7 @@ async def jsk_python_inspect(self, ctx: commands.Context, *, argument: codeblock

text = "\n".join(lines)

if len(text) < 50_000: # File "full content" preview limit
if len(text) < 50_000 and not ctx.author.is_on_mobile() and not JISHAKU_FORCE_PAGINATOR: # File "full content" preview limit
send(await ctx.send(file=discord.File(
filename="inspection.prolog",
fp=io.BytesIO(text.encode('utf-8'))
Expand All @@ -195,7 +195,7 @@ async def jsk_disassemble(self, ctx: commands.Context, *, argument: codeblock_co
async with ReplResponseReactor(ctx.message):
text = "\n".join(disassemble(argument.content, arg_dict=arg_dict))

if len(text) < 50_000: # File "full content" preview limit
if len(text) < 50_000 and not ctx.author.is_on_mobile() and not JISHAKU_FORCE_PAGINATOR: # File "full content" preview limit
await ctx.send(file=discord.File(
filename="dis.py",
fp=io.BytesIO(text.encode('utf-8'))
Expand Down
4 changes: 4 additions & 0 deletions jishaku/flags.py
Expand Up @@ -34,6 +34,10 @@ def enabled(flag: str) -> bool:
JISHAKU_NO_UNDERSCORE = enabled("JISHAKU_NO_UNDERSCORE")
SCOPE_PREFIX = '' if JISHAKU_NO_UNDERSCORE else '_'

# Flag to indicate whether or not to always use paginators in commands that now use files
# as there is no file preview on mobile and some people just like the paginators better.
JISHAKU_FORCE_PAGINATOR = enabled("JISHAKU_FORCE_PAGINATOR")

# Flag to indicate verbose error tracebacks should be sent to the invoking channel as opposed to via direct message.
JISHAKU_NO_DM_TRACEBACK = enabled("JISHAKU_NO_DM_TRACEBACK")

Expand Down