Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning to [p]set api if <>s are included in secret #6265

Open
wants to merge 5 commits into
base: V3/develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion redbot/core/core_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3633,8 +3633,22 @@ async def _set_api(
else:
if ctx.bot_permissions.manage_messages:
await ctx.message.delete()
embed = discord.Embed()
for api_service_name, token in tokens.items():
if token.startswith("<") and token.endswith(">"):
angle_bracket_warning = (
"You may have failed to properly format your {api_service_name}. If you were told to enter a key"
" with an example such as [p]set api {service} api_key <your_api_key_here>, and your API key"
" was HREDFGWE, make sure to run [p]set api {service} api_key HREDFGWE, and not "
" [p]set api {service} api_key <HREDFGWE>"
Comment on lines +3640 to +3643
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping the command examples with inline marks may be appropriate to improve readability.

Suggested change
"You may have failed to properly format your {api_service_name}. If you were told to enter a key"
" with an example such as [p]set api {service} api_key <your_api_key_here>, and your API key"
" was HREDFGWE, make sure to run [p]set api {service} api_key HREDFGWE, and not "
" [p]set api {service} api_key <HREDFGWE>"
"You may have failed to properly format your {api_service_name}. If you were told to enter a key"
" with an example such as `[p]set api {service} api_key <your_api_key_here>`, and your API key"
" was `HREDFGWE`, make sure to run `[p]set api {service} api_key HREDFGWE` and not "
" `[p]set api {service} api_key <HREDFGWE>`."

).format(api_service_name=api_service_name, service=service)
log.warning(angle_bracket_warning)
Kreusada marked this conversation as resolved.
Show resolved Hide resolved
embed.add_field(name=_("Warning"), value=_(angle_bracket_warning))
await ctx.bot.set_shared_api_tokens(service, **tokens)
await ctx.send(_("`{service}` API tokens have been set.").format(service=service))
await ctx.send(
_("`{service}` API tokens have been set.").format(service=service),
embed=embed if len(embed.fields) > 0 else None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't necessary to give this warning inside of an embed, when there is already text content (it would make things more complicated, such as having to check if an embed is requested in the current channel). Instead, you could add line breaks under the original message and put the warning text there. Something like this would suffice:

angle_bracket_warning = None # define this before iterating through tokens
for api_service_name, token in tokens.items():
    ...
message = _("`{service}` API tokens have been set.").format(service=service)
if angle_bracket_warning:
    message += "\n\n" + _("**Warning:** ") + _(angle_bracket_warning)
await ctx.send(message)

Remember to remove the embed definition on line 3636.

)

@_set_api.command(name="list")
async def _set_api_list(self, ctx: commands.Context):
Expand Down
Loading