mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
Prevent PyPI's unavailability from causing command failure (#3663)
This commit is contained in:
parent
23eae27a8f
commit
a126da5f23
@ -327,9 +327,13 @@ class Core(commands.Cog, CoreLogic):
|
|||||||
owner = app_info.owner
|
owner = app_info.owner
|
||||||
custom_info = await self.bot._config.custom_info()
|
custom_info = await self.bot._config.custom_info()
|
||||||
|
|
||||||
|
try:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get(red_pypi_json) as r:
|
async with session.get(red_pypi_json) as r:
|
||||||
data = await r.json()
|
data = await r.json()
|
||||||
|
except (aiohttp.ClientError, asyncio.TimeoutError):
|
||||||
|
outdated = None
|
||||||
|
else:
|
||||||
outdated = VersionInfo.from_str(data["info"]["version"]) > red_version_info
|
outdated = VersionInfo.from_str(data["info"]["version"]) > red_version_info
|
||||||
about = _(
|
about = _(
|
||||||
"This bot is an instance of [Red, an open source Discord bot]({}) "
|
"This bot is an instance of [Red, an open source Discord bot]({}) "
|
||||||
@ -345,10 +349,15 @@ class Core(commands.Cog, CoreLogic):
|
|||||||
embed.add_field(name="Python", value=python_version)
|
embed.add_field(name="Python", value=python_version)
|
||||||
embed.add_field(name="discord.py", value=dpy_version)
|
embed.add_field(name="discord.py", value=dpy_version)
|
||||||
embed.add_field(name=_("Red version"), value=red_version)
|
embed.add_field(name=_("Red version"), value=red_version)
|
||||||
if outdated:
|
if outdated is True:
|
||||||
embed.add_field(
|
outdated_value = _("Yes, {version} is available").format(
|
||||||
name=_("Outdated"), value=_("Yes, {} is available").format(data["info"]["version"])
|
version=data["info"]["version"]
|
||||||
)
|
)
|
||||||
|
elif outdated is None:
|
||||||
|
outdated_value = _("Checking for updates failed.")
|
||||||
|
else:
|
||||||
|
outdated_value = _("No")
|
||||||
|
embed.add_field(name=_("Outdated"), value=outdated_value)
|
||||||
if custom_info:
|
if custom_info:
|
||||||
embed.add_field(name=_("About this instance"), value=custom_info, inline=False)
|
embed.add_field(name=_("About this instance"), value=custom_info, inline=False)
|
||||||
embed.add_field(name=_("About Red"), value=about, inline=False)
|
embed.add_field(name=_("About Red"), value=about, inline=False)
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import contextlib
|
import contextlib
|
||||||
import sys
|
import sys
|
||||||
import codecs
|
import codecs
|
||||||
@ -84,7 +85,7 @@ def init_events(bot, cli_flags):
|
|||||||
INFO.append("{} cogs with {} commands".format(len(bot.cogs), len(bot.commands)))
|
INFO.append("{} cogs with {} commands".format(len(bot.cogs), len(bot.commands)))
|
||||||
|
|
||||||
outdated_red_message = ""
|
outdated_red_message = ""
|
||||||
with contextlib.suppress(aiohttp.ClientError, discord.HTTPException):
|
with contextlib.suppress(aiohttp.ClientError, asyncio.TimeoutError):
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get("https://pypi.org/pypi/red-discordbot/json") as r:
|
async with session.get("https://pypi.org/pypi/red-discordbot/json") as r:
|
||||||
data = await r.json()
|
data = await r.json()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user