Skip to content

Commit 49f3e56

Browse files
committed
Plugin registry checks upon boot
Plugins will be checked upon start if they are not in the registry and REGISTRY_PLUGINS_ONLY is set to Yes they will be removed. Also plugins are allowed to be removed regardless of being in the registry or not.
1 parent ad801b1 commit 49f3e56

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

cogs/plugins.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ async def initial_load_plugins(self):
153153
logger.info("Migrated legacy plugin name: %s, now %s.", plugin_name, str(plugin))
154154
self.bot.config["plugins"].append(str(plugin))
155155

156+
if self.bot.config.get("registry_plugins_only") and not plugin_name in self.registry:
157+
self.bot.config["plugins"].remove(plugin_name)
158+
logger.info(
159+
"Loading of plugin %s was skipped and the plugin was removed because it is not present in the registry.",
160+
plugin_name,
161+
)
162+
continue
163+
156164
try:
157165
await self.download_plugin(plugin)
158166
await self.load_plugin(plugin)
@@ -281,7 +289,7 @@ async def unload_plugin(self, plugin: Plugin) -> None:
281289
if module == ext_parent or module.startswith(ext_parent + "."):
282290
del sys.modules[module]
283291

284-
async def parse_user_input(self, ctx, plugin_name, check_version=False):
292+
async def parse_user_input(self, ctx, plugin_name, check_version=False, check_registry=True):
285293
if not self.bot.config["enable_plugins"]:
286294
embed = discord.Embed(
287295
description="Plugins are disabled, enable them by setting `ENABLE_PLUGINS=true`",
@@ -318,14 +326,15 @@ async def parse_user_input(self, ctx, plugin_name, check_version=False):
318326
plugin = Plugin(user, repo, plugin_name, branch)
319327

320328
else:
321-
if self.bot.config.get("registry_plugins_only"):
322-
embed = discord.Embed(
323-
description="This plugin is not in the registry. To install this plugin, "
324-
"you must set `REGISTRY_PLUGINS_ONLY=no` or remove this key in your .env file.",
325-
color=self.bot.error_color,
326-
)
327-
await ctx.send(embed=embed)
328-
return
329+
if check_registry:
330+
if self.bot.config.get("registry_plugins_only"):
331+
embed = discord.Embed(
332+
description="This plugin is not in the registry. To install this plugin, "
333+
"you must set `REGISTRY_PLUGINS_ONLY=no` or remove this key in your .env file.",
334+
color=self.bot.error_color,
335+
)
336+
await ctx.send(embed=embed)
337+
return
329338
try:
330339
plugin = Plugin.from_string(plugin_name)
331340
except InvalidPluginError:
@@ -337,7 +346,7 @@ async def parse_user_input(self, ctx, plugin_name, check_version=False):
337346
)
338347
await ctx.send(embed=embed)
339348
return
340-
return plugin
349+
return plugin
341350

342351
@commands.group(aliases=["plugin"], invoke_without_command=True)
343352
@checks.has_permissions(PermissionLevel.OWNER)
@@ -446,7 +455,7 @@ async def plugins_remove(self, ctx, *, plugin_name: str):
446455
`plugin_name` can be the name of the plugin found in `{prefix}plugin registry`, or a direct reference
447456
to a GitHub hosted plugin (in the format `user/repo/name[@branch]`) or `@local/name` for local plugins.
448457
"""
449-
plugin = await self.parse_user_input(ctx, plugin_name)
458+
plugin = await self.parse_user_input(ctx, plugin_name, check_registry=False)
450459
if plugin is None:
451460
return
452461

0 commit comments

Comments
 (0)