mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2026-03-07 04:38:35 -05:00
Stop waiting for update check on bot startup (#6687)
This commit is contained in:
@@ -176,14 +176,15 @@ def init_events(bot, cli_flags):
|
|||||||
if bot.intents.members: # Lets avoid 0 Unique Users
|
if bot.intents.members: # Lets avoid 0 Unique Users
|
||||||
table_counts.add_row("Unique Users", str(users))
|
table_counts.add_row("Unique Users", str(users))
|
||||||
|
|
||||||
outdated_red_message = ""
|
fetch_version_task = asyncio.create_task(fetch_latest_red_version_info())
|
||||||
rich_outdated_message = ""
|
log.info("Fetching information about latest Red version...")
|
||||||
pypi_version, py_version_req = await fetch_latest_red_version_info()
|
try:
|
||||||
outdated = pypi_version and pypi_version > red_version_info
|
await asyncio.wait_for(asyncio.shield(fetch_version_task), timeout=5)
|
||||||
if outdated:
|
except asyncio.TimeoutError:
|
||||||
outdated_red_message, rich_outdated_message = get_outdated_red_messages(
|
log.info("Version information will continue to be fetched in the background...")
|
||||||
pypi_version, py_version_req
|
except Exception:
|
||||||
)
|
# these will be logged later
|
||||||
|
pass
|
||||||
|
|
||||||
rich_console = rich.get_console()
|
rich_console = rich.get_console()
|
||||||
rich_console.print(INTRO, style="red", markup=False, highlight=False)
|
rich_console.print(INTRO, style="red", markup=False, highlight=False)
|
||||||
@@ -209,12 +210,23 @@ def init_events(bot, cli_flags):
|
|||||||
rich_console.print(
|
rich_console.print(
|
||||||
f"Looking for a quick guide on setting up Red? Checkout {Text('https://start.discord.red', style='link https://start.discord.red}')}"
|
f"Looking for a quick guide on setting up Red? Checkout {Text('https://start.discord.red', style='link https://start.discord.red}')}"
|
||||||
)
|
)
|
||||||
if rich_outdated_message:
|
|
||||||
rich_console.print(rich_outdated_message)
|
|
||||||
|
|
||||||
bot._red_ready.set()
|
bot._red_ready.set()
|
||||||
if outdated_red_message:
|
|
||||||
await send_to_owners_with_prefix_replaced(bot, outdated_red_message)
|
try:
|
||||||
|
pypi_version, py_version_req = await fetch_version_task
|
||||||
|
except (aiohttp.ClientError, asyncio.TimeoutError) as exc:
|
||||||
|
log.error("Failed to fetch latest version information from PyPI.", exc_info=exc)
|
||||||
|
except (KeyError, ValueError) as exc:
|
||||||
|
log.error("Failed to parse version metadata received from PyPI.", exc_info=exc)
|
||||||
|
else:
|
||||||
|
outdated = pypi_version and pypi_version > red_version_info
|
||||||
|
if outdated:
|
||||||
|
outdated_red_message, rich_outdated_message = get_outdated_red_messages(
|
||||||
|
pypi_version, py_version_req
|
||||||
|
)
|
||||||
|
rich_console.print(rich_outdated_message)
|
||||||
|
await send_to_owners_with_prefix_replaced(bot, outdated_red_message)
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_command_completion(ctx: commands.Context):
|
async def on_command_completion(ctx: commands.Context):
|
||||||
|
|||||||
@@ -424,7 +424,11 @@ class Core(commands.commands._RuleDropper, 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()
|
||||||
|
|
||||||
pypi_version, py_version_req = await fetch_latest_red_version_info()
|
try:
|
||||||
|
pypi_version, __ = await fetch_latest_red_version_info()
|
||||||
|
except (aiohttp.ClientError, TimeoutError) as exc:
|
||||||
|
log.error("Failed to fetch latest version information from PyPI.", exc_info=exc)
|
||||||
|
pypi_version = None
|
||||||
outdated = pypi_version and pypi_version > red_version_info
|
outdated = pypi_version and pypi_version > red_version_info
|
||||||
|
|
||||||
if embed_links:
|
if embed_links:
|
||||||
|
|||||||
@@ -326,18 +326,29 @@ def expected_version(current: str, expected: str) -> bool:
|
|||||||
return Requirement(f"x{expected}").specifier.contains(current, prereleases=True)
|
return Requirement(f"x{expected}").specifier.contains(current, prereleases=True)
|
||||||
|
|
||||||
|
|
||||||
async def fetch_latest_red_version_info() -> Tuple[Optional[VersionInfo], Optional[str]]:
|
async def fetch_latest_red_version_info() -> Tuple[VersionInfo, Optional[str]]:
|
||||||
try:
|
"""
|
||||||
async with aiohttp.ClientSession() as session:
|
Fetch information about latest Red release on PyPI.
|
||||||
async with session.get("https://pypi.org/pypi/Red-DiscordBot/json") as r:
|
|
||||||
data = await r.json()
|
|
||||||
except (aiohttp.ClientError, asyncio.TimeoutError):
|
|
||||||
return None, None
|
|
||||||
else:
|
|
||||||
release = VersionInfo.from_str(data["info"]["version"])
|
|
||||||
required_python = data["info"]["requires_python"]
|
|
||||||
|
|
||||||
return release, required_python
|
Raises
|
||||||
|
------
|
||||||
|
aiohttp.ClientError
|
||||||
|
An error occurred during request to PyPI.
|
||||||
|
TimeoutError
|
||||||
|
The request to PyPI timed out.
|
||||||
|
ValueError
|
||||||
|
An invalid version string was returned in PyPI metadata.
|
||||||
|
KeyError
|
||||||
|
The PyPI metadata is missing some of the required information.
|
||||||
|
"""
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
async with session.get("https://pypi.org/pypi/Red-DiscordBot/json") as r:
|
||||||
|
data = await r.json()
|
||||||
|
|
||||||
|
release = VersionInfo.from_str(data["info"]["version"])
|
||||||
|
required_python = data["info"]["requires_python"]
|
||||||
|
|
||||||
|
return release, required_python
|
||||||
|
|
||||||
|
|
||||||
def deprecated_removed(
|
def deprecated_removed(
|
||||||
|
|||||||
Reference in New Issue
Block a user