Skip to content

Commit

Permalink
Fix registry loading errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sebkuip committed Jan 30, 2024
1 parent 61336bc commit da51441
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cogs/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,12 @@ async def cog_load(self):

async def populate_registry(self):
url = "https://raw.githubusercontent.com/modmail-dev/modmail/master/plugins/registry.json"
async with self.bot.session.get(url) as resp:
self.registry = json.loads(await resp.text())
try:
async with self.bot.session.get(url) as resp:
self.registry = json.loads(await resp.text())
except asyncio.TimeoutError:
logger.warn("Failed to fetch registry. Loading with empty registry")
self.registry = {}

async def initial_load_plugins(self):
for plugin_name in list(self.bot.config["plugins"]):
Expand Down Expand Up @@ -638,6 +642,14 @@ async def plugins_registry(self, ctx, *, plugin_name: typing.Union[int, str] = N

registry = sorted(self.registry.items(), key=lambda elem: elem[0])

if registry == {}:
embed = discord.Embed(
color=self.bot.error_color,
description='Registry is empty. This could be because it failed to load.'
)
await ctx.send(embed=embed)
return

if isinstance(plugin_name, int):
index = plugin_name - 1
if index < 0:
Expand Down

0 comments on commit da51441

Please sign in to comment.