Skip to content

Commit

Permalink
chore: Added changelog and missing versionadded's and versionchanged's
Browse files Browse the repository at this point in the history
  • Loading branch information
DA-344 committed Dec 14, 2024
1 parent 37a4567 commit 18bf9a3
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 2 deletions.
2 changes: 2 additions & 0 deletions discord_tools/app_commands/context_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
Expand Down
48 changes: 46 additions & 2 deletions discord_tools/app_commands/i18n/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>`.
Examples can be found on the :resource:`repository <examples>`.
.. 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:
Expand All @@ -60,14 +65,19 @@ 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(
self, locale: Locale, data: dict[str, str]
) -> dict[Locale, dict[str, str]]:
"""Updates a locale's translation strings.
.. versionadded:: 1.0
Parameters
----------
locale: :class:`discord.Locale`
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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`]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions discord_tools/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions discord_tools/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 6 additions & 0 deletions discord_tools/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions discord_tools/ipc/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
class Request:
"""Represents an IPC request.
.. versionadded:: 1.0
.. container:: operations
.. describe:: for ... in x
Expand Down
2 changes: 2 additions & 0 deletions discord_tools/ipc/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
class Route(Generic[R]):
"""Represents a server route.
.. versionadded:: 1.0
.. container:: operations
.. describe:: str(x)
Expand Down
4 changes: 4 additions & 0 deletions discord_tools/ipc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand Down
2 changes: 2 additions & 0 deletions discord_tools/ipc/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file added discord_tools/voice/__init__.py
Empty file.
Empty file added discord_tools/voice/client.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
48 changes: 48 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -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 <https://keepachangelog.com/en/1.1.0/>` and this project adheres to
`Semantic Versioning <https://semver.org/spec/v2.0.0.html>`.


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`.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 18bf9a3

Please sign in to comment.