mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 02:16:09 -05:00
Move logic for fetching latest Red version info to internal util (#3904)
* Only Send out of date message to Final builds available on PyPi * Only Send out of date message to Final builds available on PyPi * sorted the resulting list so that the newest build is first in the list * forgot about this one * well jack is a bitch but we love him. * simplify logic * Add the new function to `__all__` Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
@@ -19,11 +19,14 @@ from typing import (
|
||||
Optional,
|
||||
Union,
|
||||
TYPE_CHECKING,
|
||||
Tuple,
|
||||
)
|
||||
|
||||
import aiohttp
|
||||
import discord
|
||||
import pkg_resources
|
||||
from fuzzywuzzy import fuzz, process
|
||||
from redbot import VersionInfo
|
||||
|
||||
from redbot.core import data_manager
|
||||
from redbot.core.utils.chat_formatting import box
|
||||
@@ -42,6 +45,7 @@ __all__ = (
|
||||
"send_to_owners_with_preprocessor",
|
||||
"send_to_owners_with_prefix_replaced",
|
||||
"expected_version",
|
||||
"fetch_latest_red_version_info",
|
||||
)
|
||||
|
||||
|
||||
@@ -298,3 +302,17 @@ async def send_to_owners_with_prefix_replaced(bot: Red, content: str, **kwargs):
|
||||
def expected_version(current: str, expected: str) -> bool:
|
||||
# `pkg_resources` needs a regular requirement string, so "x" serves as requirement's name here
|
||||
return current in pkg_resources.Requirement.parse(f"x{expected}")
|
||||
|
||||
|
||||
async def fetch_latest_red_version_info() -> Tuple[Optional[VersionInfo], Optional[str]]:
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user