diff --git a/changelog.d/3134.docs.rst b/changelog.d/3134.docs.rst new file mode 100644 index 000000000..2b294cb65 --- /dev/null +++ b/changelog.d/3134.docs.rst @@ -0,0 +1 @@ +Add event reference for ``on_red_api_tokens_update`` event in Shared API Keys docs. \ No newline at end of file diff --git a/changelog.d/3134.feature.rst b/changelog.d/3134.feature.rst new file mode 100644 index 000000000..272a2c0b3 --- /dev/null +++ b/changelog.d/3134.feature.rst @@ -0,0 +1 @@ +New event ``on_red_api_tokens_update`` is now dispatched when shared api keys for the service are updated. \ No newline at end of file diff --git a/docs/framework_apikeys.rst b/docs/framework_apikeys.rst index 3d68854cd..b27d2e713 100644 --- a/docs/framework_apikeys.rst +++ b/docs/framework_apikeys.rst @@ -46,3 +46,17 @@ Basic Usage if youtube_keys.get("api_key") is None: return await ctx.send("The YouTube API key has not been set.") # Use the API key to access content as you normally would + + +*************** +Event Reference +*************** + +.. function:: on_red_api_tokens_update(service_name, api_tokens) + + Dispatched when service's api keys are updated. + + :param service_name: Name of the service. + :type service_name: :class:`str` + :param api_tokens: New Mapping of token names to tokens. This contains api tokens that weren't changed too. + :type api_tokens: Mapping[:class:`str`, :class:`str`] diff --git a/redbot/core/bot.py b/redbot/core/bot.py index d2d26cd70..18e57055d 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -8,6 +8,7 @@ from enum import Enum from importlib.machinery import ModuleSpec from pathlib import Path from typing import Optional, Union, List, Dict, NoReturn +from types import MappingProxyType import discord from discord.ext.commands import when_mentioned_or @@ -582,6 +583,7 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: d async with self._config.custom(SHARED_API_TOKENS, service_name).all() as group: group.update(tokens) + self.dispatch("red_api_tokens_update", service_name, MappingProxyType(group)) async def remove_shared_api_tokens(self, service_name: str, *token_names: str): """