Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions cogs/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ async def initial_load_plugins(self):
logger.info("Migrated legacy plugin name: %s, now %s.", plugin_name, str(plugin))
self.bot.config["plugins"].append(str(plugin))

if self.bot.config.get("registry_plugins_only") and not plugin_name in self.registry:
self.bot.config["plugins"].remove(plugin_name)
logger.info(
"Loading of plugin %s was skipped and the plugin was removed because it is not present in the registry.",
plugin_name,
)
continue

try:
await self.download_plugin(plugin)
await self.load_plugin(plugin)
Expand Down Expand Up @@ -281,7 +289,7 @@ async def unload_plugin(self, plugin: Plugin) -> None:
if module == ext_parent or module.startswith(ext_parent + "."):
del sys.modules[module]

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

else:
if self.bot.config.get("registry_plugins_only"):
embed = discord.Embed(
description="This plugin is not in the registry. To install this plugin, "
"you must set `REGISTRY_PLUGINS_ONLY=no` or remove this key in your .env file.",
color=self.bot.error_color,
)
await ctx.send(embed=embed)
return
if check_registry:
if self.bot.config.get("registry_plugins_only"):
embed = discord.Embed(
description="This plugin is not in the registry. To install this plugin, "
"you must set `REGISTRY_PLUGINS_ONLY=no` or remove this key in your .env file.",
color=self.bot.error_color,
)
await ctx.send(embed=embed)
return
try:
plugin = Plugin.from_string(plugin_name)
except InvalidPluginError:
Expand All @@ -337,7 +346,7 @@ async def parse_user_input(self, ctx, plugin_name, check_version=False):
)
await ctx.send(embed=embed)
return
return plugin
return plugin

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

Expand Down
Loading