From da514416a9324a3a00309545957be2f919077178 Mon Sep 17 00:00:00 2001 From: Sebastian Kuipers Date: Tue, 30 Jan 2024 16:56:06 +0100 Subject: [PATCH 1/4] Fix registry loading errors --- cogs/plugins.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cogs/plugins.py b/cogs/plugins.py index fc6e09f05d..4d698440bb 100644 --- a/cogs/plugins.py +++ b/cogs/plugins.py @@ -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"]): @@ -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: From a7bf9e0eec5014f18c6e37f788233c96179df0e9 Mon Sep 17 00:00:00 2001 From: Sebastian Kuipers Date: Tue, 30 Jan 2024 17:00:01 +0100 Subject: [PATCH 2/4] Fix black formatting --- cogs/plugins.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cogs/plugins.py b/cogs/plugins.py index 4d698440bb..c969da2a5c 100644 --- a/cogs/plugins.py +++ b/cogs/plugins.py @@ -6,8 +6,8 @@ import sys import typing import zipfile -from importlib import invalidate_caches from difflib import get_close_matches +from importlib import invalidate_caches from pathlib import Path, PurePath from re import match from site import USER_SITE @@ -15,13 +15,12 @@ import discord from discord.ext import commands - from packaging.version import Version from core import checks from core.models import PermissionLevel, getLogger from core.paginator import EmbedPaginatorSession -from core.utils import truncate, trigger_typing +from core.utils import trigger_typing, truncate logger = getLogger(__name__) @@ -645,7 +644,7 @@ async def plugins_registry(self, ctx, *, plugin_name: typing.Union[int, str] = N if registry == {}: embed = discord.Embed( color=self.bot.error_color, - description='Registry is empty. This could be because it failed to load.' + description="Registry is empty. This could be because it failed to load.", ) await ctx.send(embed=embed) return From 851f823aba364baaa503c50d6466af45d2e457b3 Mon Sep 17 00:00:00 2001 From: Sebastian Kuipers Date: Tue, 30 Jan 2024 18:41:08 +0100 Subject: [PATCH 3/4] Repo consistency --- cogs/plugins.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/plugins.py b/cogs/plugins.py index c969da2a5c..a46a8a2d69 100644 --- a/cogs/plugins.py +++ b/cogs/plugins.py @@ -135,8 +135,8 @@ async def populate_registry(self): 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 = {} + logger.warning("Failed to fetch registry. Loading with empty registry") + self.registry = {} if not self.registry else self.registry async def initial_load_plugins(self): for plugin_name in list(self.bot.config["plugins"]): From bba6af13b7e92b94672a95c7542208272447b5d6 Mon Sep 17 00:00:00 2001 From: Sebastian Kuipers Date: Mon, 11 Mar 2024 22:53:50 +0100 Subject: [PATCH 4/4] Change code cleanness as requested by taku --- cogs/plugins.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cogs/plugins.py b/cogs/plugins.py index a46a8a2d69..78bc0aa544 100644 --- a/cogs/plugins.py +++ b/cogs/plugins.py @@ -136,7 +136,6 @@ async def populate_registry(self): self.registry = json.loads(await resp.text()) except asyncio.TimeoutError: logger.warning("Failed to fetch registry. Loading with empty registry") - self.registry = {} if not self.registry else self.registry async def initial_load_plugins(self): for plugin_name in list(self.bot.config["plugins"]): @@ -641,7 +640,7 @@ 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 == {}: + if not registry: embed = discord.Embed( color=self.bot.error_color, description="Registry is empty. This could be because it failed to load.",