Skip to content

Commit

Permalink
[Menus] Replace box_language_py kwarg by lang kwarg.
Browse files Browse the repository at this point in the history
  • Loading branch information
AAA3A-AAA3A committed Apr 15, 2023
1 parent bf48d68 commit ddefa0b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion AAA3A_utils/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async def cog_after_invoke(self, ctx: commands.Context) -> None:
else:
await context.tick(reaction="❌")
# from .menus import Menu
# await Menu(pages=str("\n".join([str((x.function, x.frame)) for x in __import__("inspect").stack(30)])), box_language_py=True).start(context)
# await Menu(pages=str("\n".join([str((x.function, x.frame)) for x in __import__("inspect").stack(30)])), lang="py").start(context)
return context

async def cog_command_error(self, ctx: commands.Context, error: Exception) -> None:
Expand Down
4 changes: 1 addition & 3 deletions AAA3A_utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ async def send_interactive(
return await self.original_context.send_interactive(
messages=messages, box_lang=box_lang, timeout=timeout
)
if box_lang is not None:
messages = [box(message, lang=box_lang) for message in messages]
menu = Menu(pages=messages)
menu = Menu(pages=list(messages), lang=box_lang)
if discord.version_info.major >= 2 and len(messages) <= 1:
menu.disabled_controls.extend(["send_as_file", "choose_page"])
await menu.start(self)
Expand Down
2 changes: 1 addition & 1 deletion AAA3A_utils/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def get_env(

async def _rtfs(ctx: commands.Context, object):
code = inspect.getsource(object)
await Menu(pages=code, box_language_py=True).start(ctx)
await Menu(pages=code, lang="py").start(ctx)

async def get_url(url: str, **kwargs):
async with aiohttp.ClientSession() as session:
Expand Down
16 changes: 8 additions & 8 deletions AAA3A_utils/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
page_start: typing.Optional[int] = 0,
members: typing.Optional[typing.Iterable[typing.Union[discord.Member, int]]] = None,
ephemeral: typing.Optional[bool] = False,
box_language_py: typing.Optional[bool] = False,
lang: typing.Optional[str] = None,
) -> None:
if members is None:
members = []
Expand Down Expand Up @@ -67,9 +67,9 @@ def __init__(
if not self.pages:
self.pages: typing.List[str] = ["Nothing to show."]
if isinstance(self.pages, str):
self.pages: typing.List[str] = list(pagify(self.pages, page_length=2000 - 10))
if box_language_py and all(isinstance(page, str) for page in self.pages):
self.pages: typing.List[str] = [box(page, "py") for page in self.pages]
self.pages: typing.List[str] = list(pagify(self.pages, page_length=2000 - len(f"```{lang}\n\n```" if lang is not None else "")))
if lang is not None and all(isinstance(page, str) for page in self.pages):
self.pages: typing.List[str] = [box(page, lang) for page in self.pages]
if not isinstance(self.pages[0], (typing.Dict, discord.Embed, str)):
raise RuntimeError("Pages must be of type typing.Dict, discord.Embed or str.")

Expand Down Expand Up @@ -371,7 +371,7 @@ def __init__(
check_owner: typing.Optional[bool] = True,
members: typing.Optional[typing.Iterable[discord.Member]] = None,
ephemeral: typing.Optional[bool] = False,
box_language_py: typing.Optional[bool] = False,
lang: typing.Optional[str] = False,
) -> None:
if members is None:
members = []
Expand Down Expand Up @@ -399,9 +399,9 @@ def __init__(
if not self.pages:
self.pages: typing.List[str] = ["Nothing to show."]
if isinstance(self.pages, str):
self.pages: typing.List[str] = list(pagify(self.pages, page_length=2000 - 10))
if box_language_py and all(isinstance(page, str) for page in self.pages):
self.pages: typing.List[str] = [box(page, "py") for page in self.pages]
self.pages: typing.List[str] = list(pagify(self.pages, page_length=2000 - len(f"```{lang}\n\n```" if lang is not None else "")))
if lang is not None and all(isinstance(page, str) for page in self.pages):
self.pages: typing.List[str] = [box(page, lang) for page in self.pages]
if not isinstance(self.pages[0], (typing.Dict, discord.Embed, str)):
raise RuntimeError("Pages must be of type typing.Dict, discord.Embed or str.")

Expand Down

0 comments on commit ddefa0b

Please sign in to comment.