Skip to content

Commit f2e8766

Browse files
committed
black formatting, smoothen menu closure
1 parent 8c341fb commit f2e8766

File tree

14 files changed

+522
-1460
lines changed

14 files changed

+522
-1460
lines changed

bot.py

Lines changed: 71 additions & 227 deletions
Large diffs are not rendered by default.

cogs/modmail.py

Lines changed: 82 additions & 237 deletions
Large diffs are not rendered by default.

cogs/plugins.py

Lines changed: 18 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ def __init__(self, user, repo=None, name=None, branch=None):
5252
def path(self):
5353
if self.local:
5454
return PurePath("plugins") / "@local" / self.name
55-
return (
56-
PurePath("plugins") / self.user / self.repo / f"{self.name}-{self.branch}"
57-
)
55+
return PurePath("plugins") / self.user / self.repo / f"{self.name}-{self.branch}"
5856

5957
@property
6058
def abs_path(self):
@@ -149,14 +147,10 @@ async def initial_load_plugins(self):
149147
# For backwards compat
150148
plugin = Plugin.from_string(plugin_name)
151149
except InvalidPluginError:
152-
logger.error(
153-
"Failed to parse plugin name: %s.", plugin_name, exc_info=True
154-
)
150+
logger.error("Failed to parse plugin name: %s.", plugin_name, exc_info=True)
155151
continue
156152

157-
logger.info(
158-
"Migrated legacy plugin name: %s, now %s.", plugin_name, str(plugin)
159-
)
153+
logger.info("Migrated legacy plugin name: %s, now %s.", plugin_name, str(plugin))
160154
self.bot.config["plugins"].append(str(plugin))
161155

162156
try:
@@ -208,9 +202,7 @@ async def download_plugin(self, plugin, force=False):
208202
if raw == "Not Found":
209203
raise InvalidPluginError("Plugin not found")
210204
else:
211-
raise InvalidPluginError(
212-
"Invalid download received, non-bytes object"
213-
)
205+
raise InvalidPluginError("Invalid download received, non-bytes object")
214206

215207
plugin_io = io.BytesIO(raw)
216208
if not plugin.cache_path.parent.exists():
@@ -242,9 +234,7 @@ async def load_plugin(self, plugin):
242234
if req_txt.exists():
243235
# Install PIP requirements
244236

245-
venv = hasattr(sys, "real_prefix") or hasattr(
246-
sys, "base_prefix"
247-
) # in a virtual env
237+
venv = hasattr(sys, "real_prefix") or hasattr(sys, "base_prefix") # in a virtual env
248238
user_install = " --user" if not venv else ""
249239
proc = await asyncio.create_subprocess_shell(
250240
f'"{sys.executable}" -m pip install --upgrade{user_install} -r {req_txt} -q -q',
@@ -266,9 +256,7 @@ async def load_plugin(self, plugin):
266256
plugin.ext_string,
267257
exc_info=True,
268258
)
269-
raise InvalidPluginError(
270-
f"Unable to download requirements: ```\n{stderr.decode()}\n```"
271-
)
259+
raise InvalidPluginError(f"Unable to download requirements: ```\n{stderr.decode()}\n```")
272260

273261
if os.path.exists(USER_SITE):
274262
sys.path.insert(0, USER_SITE)
@@ -463,9 +451,7 @@ async def plugins_remove(self, ctx, *, plugin_name: str):
463451
return
464452

465453
if str(plugin) not in self.bot.config["plugins"]:
466-
embed = discord.Embed(
467-
description="Plugin is not installed.", color=self.bot.error_color
468-
)
454+
embed = discord.Embed(description="Plugin is not installed.", color=self.bot.error_color)
469455
return await ctx.send(embed=embed)
470456

471457
if self.bot.config.get("enable_plugins"):
@@ -503,9 +489,7 @@ async def update_plugin(self, ctx, plugin_name):
503489
return
504490

505491
if str(plugin) not in self.bot.config["plugins"]:
506-
embed = discord.Embed(
507-
description="Plugin is not installed.", color=self.bot.error_color
508-
)
492+
embed = discord.Embed(description="Plugin is not installed.", color=self.bot.error_color)
509493
return await ctx.send(embed=embed)
510494

511495
async with safe_typing(ctx):
@@ -528,9 +512,7 @@ async def update_plugin(self, ctx, plugin_name):
528512
color=self.bot.error_color,
529513
)
530514
self.bot.config["plugins"].remove(str(plugin))
531-
logger.debug(
532-
"Failed to update %s. Removed plugin from config.", plugin
533-
)
515+
logger.debug("Failed to update %s. Removed plugin from config.", plugin)
534516
else:
535517
logger.debug("Updated %s.", plugin)
536518
else:
@@ -570,9 +552,7 @@ async def plugins_reset(self, ctx):
570552
continue
571553
logger.error("Unloading plugin: %s.", ext)
572554
try:
573-
plugin = next(
574-
(p for p in self.loaded_plugins if p.ext_string == ext), None
575-
)
555+
plugin = next((p for p in self.loaded_plugins if p.ext_string == ext), None)
576556
if plugin:
577557
await self.unload_plugin(plugin)
578558
self.loaded_plugins.remove(plugin)
@@ -648,20 +628,14 @@ async def plugins_loaded(self, ctx):
648628

649629
embeds = []
650630
for page in pages:
651-
embed = discord.Embed(
652-
title="Loaded plugins:", description=page, color=self.bot.main_color
653-
)
631+
embed = discord.Embed(title="Loaded plugins:", description=page, color=self.bot.main_color)
654632
embeds.append(embed)
655633
paginator = EmbedPaginatorSession(ctx, *embeds)
656634
await paginator.run()
657635

658-
@plugins.group(
659-
invoke_without_command=True, name="registry", aliases=["list", "info"]
660-
)
636+
@plugins.group(invoke_without_command=True, name="registry", aliases=["list", "info"])
661637
@checks.has_permissions(PermissionLevel.OWNER)
662-
async def plugins_registry(
663-
self, ctx, *, plugin_name: typing.Union[int, str] = None
664-
):
638+
async def plugins_registry(self, ctx, *, plugin_name: typing.Union[int, str] = None):
665639
"""
666640
Shows a list of all approved plugins.
667641
@@ -692,9 +666,7 @@ async def plugins_registry(
692666
if index >= len(registry):
693667
index = len(registry) - 1
694668
else:
695-
index = next(
696-
(i for i, (n, _) in enumerate(registry) if plugin_name == n), 0
697-
)
669+
index = next((i for i, (n, _) in enumerate(registry) if plugin_name == n), 0)
698670

699671
if not index and plugin_name is not None:
700672
embed = discord.Embed(
@@ -726,13 +698,9 @@ async def plugins_registry(
726698
title=details["repository"],
727699
)
728700

729-
embed.add_field(
730-
name="Installation", value=f"```{self.bot.prefix}plugins add {name}```"
731-
)
701+
embed.add_field(name="Installation", value=f"```{self.bot.prefix}plugins add {name}```")
732702

733-
embed.set_author(
734-
name=details["title"], icon_url=details.get("icon_url"), url=plugin.link
735-
)
703+
embed.set_author(name=details["title"], icon_url=details.get("icon_url"), url=plugin.link)
736704

737705
if details.get("thumbnail_url"):
738706
embed.set_thumbnail(url=details.get("thumbnail_url"))
@@ -778,9 +746,7 @@ async def plugins_registry_compact(self, ctx):
778746

779747
plugin = Plugin(user, repo, plugin_name, branch)
780748

781-
desc = discord.utils.escape_markdown(
782-
details["description"].replace("\n", "")
783-
)
749+
desc = discord.utils.escape_markdown(details["description"].replace("\n", ""))
784750

785751
name = f"[`{plugin.name}`]({plugin.link})"
786752
fmt = f"{name} - {desc}"
@@ -809,9 +775,7 @@ async def plugins_registry_compact(self, ctx):
809775
embed = discord.Embed(color=self.bot.main_color, description=page)
810776
embed.set_author(
811777
name="Plugin Registry",
812-
icon_url=self.bot.user.display_avatar.url
813-
if self.bot.user.display_avatar
814-
else None,
778+
icon_url=self.bot.user.display_avatar.url if self.bot.user.display_avatar else None,
815779
)
816780
embeds.append(embed)
817781

0 commit comments

Comments
 (0)