From 18bf9a3fb3b046663da75bd479fc1cdd2e291485 Mon Sep 17 00:00:00 2001 From: DA-344 <108473820+DA-344@users.noreply.github.com> Date: Sat, 14 Dec 2024 13:27:39 +0100 Subject: [PATCH] chore: Added changelog and missing versionadded's and versionchanged's --- discord_tools/app_commands/context_menu.py | 2 + discord_tools/app_commands/i18n/translator.py | 48 ++++++++++++++++++- discord_tools/converters.py | 2 + discord_tools/errors.py | 2 + discord_tools/flags.py | 6 +++ discord_tools/ipc/response.py | 2 + discord_tools/ipc/route.py | 2 + discord_tools/ipc/server.py | 4 ++ discord_tools/ipc/session.py | 2 + discord_tools/voice/__init__.py | 0 discord_tools/voice/client.py | 0 discord_tools/voice/encryption/__init__.py | 0 discord_tools/voice/encryption/adapters.py | 0 discord_tools/voice/encryption/utils.py | 0 discord_tools/voice/packets/__init__.py | 0 discord_tools/voice/packets/_types.py | 0 discord_tools/voice/packets/core.py | 0 docs/changelog.rst | 48 +++++++++++++++++++ pyproject.toml | 5 ++ 19 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 discord_tools/voice/__init__.py create mode 100644 discord_tools/voice/client.py create mode 100644 discord_tools/voice/encryption/__init__.py create mode 100644 discord_tools/voice/encryption/adapters.py create mode 100644 discord_tools/voice/encryption/utils.py create mode 100644 discord_tools/voice/packets/__init__.py create mode 100644 discord_tools/voice/packets/_types.py create mode 100644 discord_tools/voice/packets/core.py create mode 100644 docs/changelog.rst diff --git a/discord_tools/app_commands/context_menu.py b/discord_tools/app_commands/context_menu.py index efecff5..cc6a9d1 100644 --- a/discord_tools/app_commands/context_menu.py +++ b/discord_tools/app_commands/context_menu.py @@ -49,6 +49,8 @@ class CogContextMenuHolder(Generic[CogT]): """Represents a :class:`discord.ext.commands.Cog` or :class:`discord.ext.commands.GroupCog` context menu holder. + .. versionadded:: 1.0 + Parameters ---------- cog: Union[:class:`discord.ext.commands.Cog`, :class:`discord.ext.commands.GroupCog`] diff --git a/discord_tools/app_commands/i18n/translator.py b/discord_tools/app_commands/i18n/translator.py index 99c97fa..a4762b2 100644 --- a/discord_tools/app_commands/i18n/translator.py +++ b/discord_tools/app_commands/i18n/translator.py @@ -51,7 +51,12 @@ class Translator(BaseTranslator): These translations are all merged, so unique translation keys are recommended. - Examples can be found in the :resource:`repository `. + Examples can be found on the :resource:`repository `. + + .. versionchanged:: 1.0 + + This is now a subclass of :class:`~discord.app_commands.Translator` and does not require + the ``googletrans`` module. """ def __init__(self) -> None: @@ -60,7 +65,10 @@ def __init__(self) -> None: self._translations: dict[Locale, dict[str, str]] = {} def clear_translations(self) -> None: - """Clears all the translations.""" + """Clears all the translations. + + .. versionadded:: 1.0 + """ self._translations.clear() def update_translation( @@ -68,6 +76,8 @@ def update_translation( ) -> dict[Locale, dict[str, str]]: """Updates a locale's translation strings. + .. versionadded:: 1.0 + Parameters ---------- locale: :class:`discord.Locale` @@ -95,6 +105,8 @@ def update_translation( def delete_translation(self, locale: Locale) -> None: """Deletes a locale's translation strings. + .. versionadded:: 1.0 + .. note:: Note that this **removes** it from the cache and **does not clear** the strings. @@ -114,6 +126,8 @@ def delete_translation(self, locale: Locale) -> None: def clear_translation(self, locale: Locale) -> None: """Clears a locale's translation strings. + .. versionadded:: 1.0 + .. note:: This **does not** remove it from the cache but instead **removes** the translation strings. @@ -137,6 +151,8 @@ def add_translation(self, locale: Locale, data: dict[str, str]) -> None: For updating translations use :meth:`.update_translation`, for deleting translation use :meth:`.delete_translation`, and for clearing them use :meth:`.clear_translations`. + .. versionadded:: 1.0 + Raises ------ KeyError @@ -160,6 +176,8 @@ def load_translations( As this function could take a lot of time and block the event loop, it is recommended to call this function once and before starting any Async I/O operations. + .. versionadded:: 1.0 + Parameters ---------- path: Union[:class:`int`, :class:`str`, :class:`bytes`, :class:`os.PathLike`] @@ -275,6 +293,32 @@ def _save_po_data(self, data, locale: Locale) -> dict[Locale, dict[str, str]]: async def translate( self, string: locale_str, locale: Locale, context: TranslationContext ) -> str | None: + """Translates ``string`` into ``locale`` with the provided ``context``. + + .. versionchanged:: 1.0 + + This now takes ``locale`` and ``context`` so it is fully compatible with ``discord.py`` when setting + this translator as the :attr:`~discord.app_commands.CommandTree.translator`. + + Parameters + ---------- + string: :class:`~discord.app_commands.locale_str` + The string to translate. + locale: :class:`~discord.Locale` + The locale to translate the string to. + + .. versionadded:: 1.0 + context: :class:`~discord.app_commands.TranslationContext` + The translation context. + + .. versionadded:: 1.0 + + Returns + ------- + Optional[:class:`str`] + The translated string, or ``None`` if it could not be translated. This is handled by the library + when the translator is set as the :attr:`~discord.app_commands.CommandTree.translator`. + """ translations = self._translations.get(locale) if translations is None: return None # discord.py handles this diff --git a/discord_tools/converters.py b/discord_tools/converters.py index f0aa0a5..4d7ba99 100644 --- a/discord_tools/converters.py +++ b/discord_tools/converters.py @@ -42,6 +42,8 @@ class RegexConverter(Converter[re.Match[str]]): """A converter that finds a regex on an argument. + .. versionadded:: 1.0 + This converter can be used as it follows: .. code-block:: python3 diff --git a/discord_tools/errors.py b/discord_tools/errors.py index 2911171..5240b03 100644 --- a/discord_tools/errors.py +++ b/discord_tools/errors.py @@ -145,6 +145,8 @@ def __init__(self, author: Member, context: Context[Any], *args: Any) -> None: class StringDoesNotMatch(ConversionError): """An exception raised when the :class:`RegexConverter` fails to find an occurrence in a string. + .. versionadded:: 1.0 + Attributes ---------- pattern: :class:`re.Pattern` diff --git a/discord_tools/flags.py b/discord_tools/flags.py index 1b85c2c..5ba67e9 100644 --- a/discord_tools/flags.py +++ b/discord_tools/flags.py @@ -62,6 +62,8 @@ class Flag(BaseFlag): objects, but it is not necessary to do so. These cannot be constructed manually. + .. versionadded:: 1.0 + Attributes ---------- name: :class:`str` @@ -121,6 +123,8 @@ def flag( """Override default functionality and parameters of the underlying :class:`FlagConverter` class attributes. + .. versionadded:: 1.0 + Parameters ------------ name: :class:`str` @@ -180,6 +184,8 @@ class attributes. class ImplicitBoolFlagConverter(FlagConverter): """A custom :class:`discord.ext.commands.FlagConverter` subclass that allows boolean flags to not have a value. + .. versionadded:: 1.0 + For example: .. code-block:: python3 diff --git a/discord_tools/ipc/response.py b/discord_tools/ipc/response.py index c87de0d..e2a6f01 100644 --- a/discord_tools/ipc/response.py +++ b/discord_tools/ipc/response.py @@ -38,6 +38,8 @@ class Request: """Represents an IPC request. + .. versionadded:: 1.0 + .. container:: operations .. describe:: for ... in x diff --git a/discord_tools/ipc/route.py b/discord_tools/ipc/route.py index f2c3bf8..a151a77 100644 --- a/discord_tools/ipc/route.py +++ b/discord_tools/ipc/route.py @@ -39,6 +39,8 @@ class Route(Generic[R]): """Represents a server route. + .. versionadded:: 1.0 + .. container:: operations .. describe:: str(x) diff --git a/discord_tools/ipc/server.py b/discord_tools/ipc/server.py index aceed05..0e95e55 100644 --- a/discord_tools/ipc/server.py +++ b/discord_tools/ipc/server.py @@ -50,6 +50,8 @@ def route(name: str = MISSING): """A decorator that registers a coroutine as a server route. + .. versionadded:: 1.0 + Parameters ---------- name: :class:`str` @@ -70,6 +72,8 @@ def decorator(func: CoroFunc[C]) -> Route[C]: class Server(Generic[CT]): """The server used for the IPC. + .. versionadded:: 1.0 + Parameters ---------- client: :class:`~discord.Client` diff --git a/discord_tools/ipc/session.py b/discord_tools/ipc/session.py index 3c0c5e6..f426a52 100644 --- a/discord_tools/ipc/session.py +++ b/discord_tools/ipc/session.py @@ -45,6 +45,8 @@ class ClientSession: """A simple wrapper around an :class:`~aiohttp.ClientSession` for easy handling with an IPC server. + .. versionadded:: 1.0 + .. container:: operations .. describe:: async with x diff --git a/discord_tools/voice/__init__.py b/discord_tools/voice/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/discord_tools/voice/client.py b/discord_tools/voice/client.py new file mode 100644 index 0000000..e69de29 diff --git a/discord_tools/voice/encryption/__init__.py b/discord_tools/voice/encryption/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/discord_tools/voice/encryption/adapters.py b/discord_tools/voice/encryption/adapters.py new file mode 100644 index 0000000..e69de29 diff --git a/discord_tools/voice/encryption/utils.py b/discord_tools/voice/encryption/utils.py new file mode 100644 index 0000000..e69de29 diff --git a/discord_tools/voice/packets/__init__.py b/discord_tools/voice/packets/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/discord_tools/voice/packets/_types.py b/discord_tools/voice/packets/_types.py new file mode 100644 index 0000000..e69de29 diff --git a/discord_tools/voice/packets/core.py b/discord_tools/voice/packets/core.py new file mode 100644 index 0000000..e69de29 diff --git a/docs/changelog.rst b/docs/changelog.rst new file mode 100644 index 0000000..f13a091 --- /dev/null +++ b/docs/changelog.rst @@ -0,0 +1,48 @@ +.. currentmodule:: discord_tools + +.. _changelog: + +Changelog +========= + +All the changes of this project will be registered here. + +This format is based on `Keep A Changelog ` and this project adheres to +`Semantic Versioning `. + + +Unreleased +---------- + +This changes are available on the ``master`` branch, without any guarantee on functionality and stability. + +.. warning:: + + This version **contains breaking changes**. + +Added +~~~~~ + +- Added :class:`~discord_tools.app_commands.CogContextMenuHolder`, which allows creating context menus in cogs. +- Added :class:`RegexConverter` converter to allow using :class:`re.Match` objects as annotations in prefixed commands. + - Added :exc:`StringDoesNotMatch`. +- Added :class:`ImplicitBoolFlagConverter`. + - New :func:`flag` method to create implicit boolean flags. + - New :class:`Flag` subclass of :class:`~discord.ext.commands.Flag` which adds the implicit boolean functionality. +- Added a simple IPC. + - Added :class:`~discord_tools.ipc.Request`. + - Added :class:`~discord_tools.ipc.Route`. + - Added :class:`~discord_tools.ipc.Server`. + - Added :class:`~discord_tools.ipc.ClientSession`. + - Added :func:`~discord_tools.ipc.route`. +- Added various new methods to :class:`~discord_tools.app_commands.i18n.Translator`. + +Changed +~~~~~~~ + +- :class:`~discord_tools.app_commands.i18n.Translator` is now a subclass of :class:`~discord.app_commands.Translator`. + +Removed +~~~~~~~ + +- Removed :class:`~discord_tools.app_commands.i18n.Client`. diff --git a/pyproject.toml b/pyproject.toml index 4977a4e..aab7295 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,6 +51,11 @@ speed = [ "aiodns>=1.1; sys_platform != 'win32'", "Brotli", "cchardet==2.1.7; python_version < '3.10'", + "discord.py[speed]", +] +voice = [ + "discord.py[voice]", + "libnacl==1.6.0", ] [tool.setuptools]