mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-07 01:42:30 -05:00
Make some dependency changes, support Python 3.10 and 3.11 (#5611)
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
@@ -1098,6 +1098,8 @@ class Red(
|
||||
"""
|
||||
This should only be run once, prior to logging in to Discord REST API.
|
||||
"""
|
||||
await super()._pre_login()
|
||||
|
||||
await self._maybe_update_config()
|
||||
self.description = await self._config.description()
|
||||
self._color = discord.Colour(await self._config.color())
|
||||
|
||||
@@ -8,7 +8,7 @@ from copy import deepcopy
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
|
||||
import appdirs
|
||||
import platformdirs
|
||||
from discord.utils import deprecated
|
||||
|
||||
from . import commands
|
||||
@@ -37,22 +37,30 @@ basic_config_default: Dict[str, Any] = {
|
||||
"CORE_PATH_APPEND": "core",
|
||||
}
|
||||
|
||||
appdir = appdirs.AppDirs("Red-DiscordBot")
|
||||
config_dir = Path(appdir.user_config_dir)
|
||||
appdir = platformdirs.PlatformDirs("Red-DiscordBot")
|
||||
config_dir = appdir.user_config_path
|
||||
_system_user = sys.platform == "linux" and 0 < os.getuid() < 1000
|
||||
if _system_user:
|
||||
if Path.home().exists():
|
||||
# We don't want to break someone just because they created home dir
|
||||
# but were already using the site_data_dir.
|
||||
# but were already using the site_data_path.
|
||||
#
|
||||
# But otherwise, we do want Red to use user_config_dir if home dir exists.
|
||||
_maybe_config_file = Path(appdir.site_data_dir) / "config.json"
|
||||
# But otherwise, we do want Red to use user_config_path if home dir exists.
|
||||
_maybe_config_file = appdir.site_data_path / "config.json"
|
||||
if _maybe_config_file.exists():
|
||||
config_dir = _maybe_config_file.parent
|
||||
else:
|
||||
config_dir = Path(appdir.site_data_dir)
|
||||
config_dir = appdir.site_data_path
|
||||
|
||||
config_file = config_dir / "config.json"
|
||||
if not config_file.exists() and sys.platform == "darwin":
|
||||
# backwards compatibility with the location given by appdirs 1.4.4 (replaced by platformdirs 2)
|
||||
# which was the same as user_data_path
|
||||
# https://platformdirs.readthedocs.io/en/stable/changelog.html#platformdirs-2-0-0
|
||||
_old_config_location = appdir.user_data_path / "config.json"
|
||||
if _old_config_location.exists():
|
||||
config_dir.mkdir(parents=True, exist_ok=True)
|
||||
_old_config_location.rename(config_file)
|
||||
|
||||
|
||||
def load_existing_config():
|
||||
|
||||
@@ -64,14 +64,20 @@ class RPC:
|
||||
RPC server manager.
|
||||
"""
|
||||
|
||||
app: web.Application
|
||||
_rpc: RedRpc
|
||||
_runner: web.AppRunner
|
||||
|
||||
def __init__(self):
|
||||
self._site: Optional[web.TCPSite] = None
|
||||
self._started = False
|
||||
|
||||
async def _pre_login(self) -> None:
|
||||
self.app = web.Application()
|
||||
self._rpc = RedRpc()
|
||||
self.app.router.add_route("*", "/", self._rpc.handle_request)
|
||||
|
||||
self._runner = web.AppRunner(self.app)
|
||||
self._site: Optional[web.TCPSite] = None
|
||||
self._started = False
|
||||
|
||||
async def initialize(self, port: int):
|
||||
"""
|
||||
@@ -134,6 +140,9 @@ class RPCMixin:
|
||||
|
||||
self.rpc_handlers = {} # Uppercase cog name to method
|
||||
|
||||
async def _pre_login(self) -> None:
|
||||
await self.rpc._pre_login()
|
||||
|
||||
def register_rpc_handler(self, method):
|
||||
"""
|
||||
Registers a method to act as an RPC handler if the internal RPC server is active.
|
||||
|
||||
@@ -32,7 +32,7 @@ from typing import (
|
||||
import aiohttp
|
||||
import discord
|
||||
from packaging.requirements import Requirement
|
||||
from fuzzywuzzy import fuzz, process
|
||||
from rapidfuzz import fuzz, process
|
||||
from rich.progress import ProgressColumn
|
||||
from rich.progress_bar import ProgressBar
|
||||
from red_commons.logging import VERBOSE, TRACE
|
||||
@@ -147,20 +147,20 @@ async def fuzzy_command_search(
|
||||
return None
|
||||
|
||||
if commands is None:
|
||||
choices = set(ctx.bot.walk_commands())
|
||||
choices = {c: c.qualified_name for c in ctx.bot.walk_commands()}
|
||||
elif isinstance(commands, collections.abc.AsyncIterator):
|
||||
choices = {c async for c in commands}
|
||||
choices = {c: c.qualified_name async for c in commands}
|
||||
else:
|
||||
choices = set(commands)
|
||||
choices = {c: c.qualified_name for c in commands}
|
||||
|
||||
# Do the scoring. `extracted` is a list of tuples in the form `(command, score)`
|
||||
# Do the scoring. `extracted` is a list of tuples in the form `(cmd_name, score, cmd)`
|
||||
extracted = process.extract(term, choices, limit=5, scorer=fuzz.QRatio)
|
||||
if not extracted:
|
||||
return None
|
||||
|
||||
# Filter through the fuzzy-matched commands.
|
||||
matched_commands = []
|
||||
for command, score in extracted:
|
||||
for __, score, command in extracted:
|
||||
if score < min_score:
|
||||
# Since the list is in decreasing order of score, we can exit early.
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user