mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-05 17:02:32 -05:00
[Core] Improve API token converter (#2692)
* improve api converter * make usage more clear
This commit is contained in:
@@ -45,6 +45,8 @@ log = logging.getLogger("red")
|
||||
|
||||
_ = i18n.Translator("Core", __file__)
|
||||
|
||||
TokenConverter = commands.get_dict_converter(delims=[" ", ",", ";"])
|
||||
|
||||
|
||||
class CoreLogic:
|
||||
def __init__(self, bot: "Red"):
|
||||
@@ -1063,7 +1065,7 @@ class Core(commands.Cog, CoreLogic):
|
||||
|
||||
@_set.command()
|
||||
@checks.is_owner()
|
||||
async def api(self, ctx: commands.Context, service: str, *tokens: commands.converter.APIToken):
|
||||
async def api(self, ctx: commands.Context, service: str, *, tokens: TokenConverter):
|
||||
"""Set various external API tokens.
|
||||
|
||||
This setting will be asked for by some 3rd party cogs and some core cogs.
|
||||
@@ -1076,8 +1078,7 @@ class Core(commands.Cog, CoreLogic):
|
||||
"""
|
||||
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.bot.db.api_tokens.set_raw(service, value=tokens)
|
||||
await ctx.send(_("`{service}` API tokens have been set.").format(service=service))
|
||||
|
||||
@commands.group()
|
||||
|
||||
Reference in New Issue
Block a user