Skip to content

Commit 268fc71

Browse files
committed
Fix code errors, improve logging, and disable strict plugin parsing
1 parent 0c174e5 commit 268fc71

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

cogs/plugins.py

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class Plugins(commands.Cog):
117117
"""
118118

119119
def __init__(self, bot):
120+
self.forced_plugins: list[str] = []
120121
self.bot = bot
121122
self.registry = {}
122123
self.loaded_plugins = set()
@@ -139,47 +140,47 @@ def _get_forced_plugins(self) -> list[str]:
139140
if env_list is None:
140141
return []
141142
plugins = env_list.split(",")
142-
143+
return plugins
143144

144-
async def _init_load_plugin(plugin_name: str):
145+
async def _init_load_plugin(self, plugin_name: str):
146+
try:
147+
# Strict seems to only affect whether specifying the branch is required
148+
plugin = Plugin.from_string(plugin_name, strict=False)
149+
except InvalidPluginError:
150+
self.bot.config["plugins"].remove(plugin_name)
145151
try:
146-
plugin = Plugin.from_string(plugin_name, strict=True)
152+
# For backwards compat
153+
plugin = Plugin.from_string(plugin_name)
147154
except InvalidPluginError:
148-
self.bot.config["plugins"].remove(plugin_name)
149-
try:
150-
# For backwards compat
151-
plugin = Plugin.from_string(plugin_name)
152-
except InvalidPluginError:
153-
logger.error("Failed to parse plugin name: %s.", plugin_name, exc_info=True)
154-
continue
155+
logger.error("Failed to parse plugin name: %s.", plugin_name, exc_info=True)
156+
return
155157

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

159-
try:
160-
await self.download_plugin(plugin)
161-
await self.load_plugin(plugin)
162-
except Exception:
163-
self.bot.config["plugins"].remove(plugin_name)
164-
logger.error(
165-
"Error when loading plugin %s. Plugin removed from config.",
166-
plugin,
167-
exc_info=True,
168-
)
169-
continue
161+
try:
162+
await self.download_plugin(plugin)
163+
await self.load_plugin(plugin)
164+
except Exception:
165+
self.bot.config["plugins"].remove(plugin_name)
166+
logger.error(
167+
"Error when loading plugin %s. Plugin removed from config.",
168+
plugin,
169+
exc_info=True,
170+
)
170171

171-
172172
async def initial_load_plugins(self):
173-
self.forced_plugins = _get_forced_plugins()
174-
logger.debug("loading forced plugins")
175-
for plugin_name in self.forced_plugins
176-
_init_plugin_load(plugin_name)
177-
173+
self.forced_plugins = self._get_forced_plugins()
174+
logger.debug(f"loading {len(self.forced_plugins)} forced plugins")
175+
for plugin_name in self.forced_plugins:
176+
logger.debug(f"loading forced plugin {plugin_name}")
177+
await self._init_load_plugin(plugin_name)
178+
178179
logger.debug("loading config plugins")
179-
180+
180181
for plugin_name in list(self.bot.config["plugins"]):
181-
_init_plugin_load(plugin_name)
182-
182+
await self._init_load_plugin(plugin_name)
183+
183184
logger.debug("Finished loading all plugins.")
184185

185186
self.bot.dispatch("plugins_ready")
@@ -448,7 +449,12 @@ async def plugins_remove(self, ctx, *, plugin_name: str):
448449
return
449450

450451
if str(plugin) in self.forced_plugins:
451-
await ctx.send(embed=discord.Embed(description="This plugin cannot be removed. Contact your admin for more information.", color=self.bot.error_color))
452+
await ctx.send(
453+
embed=discord.Embed(
454+
description="This plugin cannot be removed. Contact your admin for more information.",
455+
color=self.bot.error_color,
456+
)
457+
)
452458
return
453459

454460
if str(plugin) not in self.bot.config["plugins"]:

0 commit comments

Comments
 (0)