Skip to content

Commit

Permalink
Use local registry instead of empty registry
Browse files Browse the repository at this point in the history
  • Loading branch information
raidensakura committed Apr 18, 2024
1 parent 0dd9c0b commit 218052a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
11 changes: 11 additions & 0 deletions REGISTRY.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"logviewer": {
"repository": "raidensakura/modmail-plugins",
"branch": "main",
"description": "Run the logviewer application alongside Modmail as a plugin.",
"bot_version": "4.1.0",
"title": "Logviewer",
"icon_url": "https://old.project-mei.xyz/images/logo.png",
"thumbnail_url": "https://modmail.project-mei.xyz/logo-ico.png"
}
}
13 changes: 8 additions & 5 deletions cogs/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,17 @@ async def cog_load(self):
logger.info("Plugins not loaded since ENABLE_PLUGINS=false.")

async def populate_registry(self):
url = "https://raw.githubusercontent.com/modmail-dev/modmail/master/plugins/registry.json"
url = "https://raw.githubusercontent.com/raidensakura/modmail/stable/plugins/registry.json"
try:
async with self.bot.session.get(url) as resp:
self.registry = json.loads(await resp.text())
except asyncio.TimeoutError:
logger.warning("Failed to fetch registry. Loading with empty registry")
except Exception as e:
logger.warning(f"Failed to fetch remote registry, using local registry:\n{e}")
registry_json = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "REGISTRY.json"
)
with open(registry_json, "r", encoding="utf-8") as f:
self.registry = json.load(f)

async def initial_load_plugins(self):
for plugin_name in list(self.bot.config["plugins"]):
Expand Down Expand Up @@ -619,8 +624,6 @@ async def plugins_registry(self, ctx, *, plugin_name: typing.Union[int, str] = N
`{prefix}plugin registry page-number` Jump to a page in the registry.
"""

await self.populate_registry()

embeds = []

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

0 comments on commit 218052a

Please sign in to comment.