mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-26 04:33:00 -05:00
Allow central storage of API keys (#2389)
This creates a central location to store external API tokens that can be used between cogs without requiring each cog to be loaded for it to work. A new set option for `[p]set api` is created to assist in forming bot readable API token locations. This also updates the Streams cog to utilize the central database. Tokens are moved from the old data locations in core cogs on load.
This commit is contained in:
committed by
Toby Harradine
parent
722aaa225b
commit
3f1d416526
@@ -1036,6 +1036,25 @@ class Core(commands.Cog, CoreLogic):
|
||||
else:
|
||||
await ctx.bot.send(_("Characters must be fewer than 1024."))
|
||||
|
||||
@_set.command()
|
||||
@checks.is_owner()
|
||||
async def api(self, ctx: commands.Context, service: str, *tokens: commands.converter.APIToken):
|
||||
"""Set various external API tokens.
|
||||
|
||||
This setting will be asked for by some 3rd party cogs and some core cogs.
|
||||
|
||||
To add the keys provide the service name and the tokens as a comma separated
|
||||
list of key,values as described by the cog requesting this command.
|
||||
|
||||
Note: API tokens are sensitive and should only be used in a private channel
|
||||
or in DM with the bot.
|
||||
"""
|
||||
if ctx.channel.permissions_for(ctx.me).manage_messages:
|
||||
await ctx.message.delete()
|
||||
entry = {k: v for t in tokens for k, v in t.items()}
|
||||
await ctx.bot.db.api_tokens.set_raw(service, value=entry)
|
||||
await ctx.send(_("`{service}` API tokens have been set.").format(service=service))
|
||||
|
||||
@commands.group()
|
||||
@checks.is_owner()
|
||||
async def helpset(self, ctx: commands.Context):
|
||||
|
||||
Reference in New Issue
Block a user