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

Closed
giplgwm wants to merge 5 commits from anglebracket-check into V3/develop
giplgwm commented 2023-11-01 02:40:55 +01:00 (Migrated from github.com)

Description of the changes

Closes #6253
For every given secret, check if its wrapped in <>, if it is, add a message to an embed with a warning that that secret may not be set properly. I tested this on a local instance of the bot and it seems to be working as expected. The warning is also logged

Have the changes in this PR been tested?

Yes

### Description of the changes Closes #6253 For every given secret, check if its wrapped in <>, if it is, add a message to an embed with a warning that that secret may not be set properly. I tested this on a local instance of the bot and it seems to be working as expected. The warning is also logged ### Have the changes in this PR been tested? <!-- Choose one (remove the line that doesn't apply): --> Yes <!-- If the question doesn't apply (for example, it's not a code change), choose Yes. Please respond to this question truthfully. We do not delay nor reject PRs based on the answer to this question but it allows to better review this PR. -->
Drapersniper (Migrated from github.com) reviewed 2023-11-01 02:40:55 +01:00
Drapersniper (Migrated from github.com) reviewed 2023-11-02 15:49:04 +01:00
@ -3633,8 +3633,22 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
else:
Drapersniper (Migrated from github.com) commented 2023-11-02 15:41:03 +01:00

This will be always the case with this command so this check is obsolete

You merge the card.send to send both the string and the new embed by specifying keyword arguments in that function

This will be always the case with this command so this check is obsolete You merge the card.send to send both the string and the new embed by specifying keyword arguments in that function
Drapersniper (Migrated from github.com) commented 2023-11-02 15:42:56 +01:00

You should explicitly clarify that it is wrapped by <> current sentence implies that < or > is found in the token/key

You should explicitly clarify that it is wrapped by <> current sentence implies that < or > is found in the token/key
Drapersniper (Migrated from github.com) commented 2023-11-02 15:44:11 +01:00

For translatable strings, I would personally suggest naming the formatting variable something contextual so that translators are better aware of the translation context for example "api_service_name"

For translatable strings, I would personally suggest naming the formatting variable something contextual so that translators are better aware of the translation context for example "api_service_name"
Drapersniper (Migrated from github.com) commented 2023-11-02 15:48:03 +01:00

Field name should be translated

Field name should be translated
@ -3636,0 +3642,4 @@
" 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)
Drapersniper (Migrated from github.com) commented 2023-11-02 15:42:00 +01:00

Log messages shouldn't be translated and should remain on the same language as the software

Log messages shouldn't be translated and should remain on the same language as the software
giplgwm commented 2023-11-16 01:24:43 +01:00 (Migrated from github.com)

@Drapersniper I added the changes requested in your comments as another commit on the PR, thanks

@Drapersniper I added the changes requested in your comments as another commit on the PR, thanks
Kreusada (Migrated from github.com) requested changes 2024-11-17 17:52:41 +01:00
Kreusada (Migrated from github.com) left a comment

Just a couple of suggested changes to improve readability.

Just a couple of suggested changes to improve readability.
@ -3636,0 +3640,4 @@
"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>"
Kreusada (Migrated from github.com) commented 2024-11-17 17:34:13 +01:00

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

                        "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>`."
Wrapping the command examples with inline marks may be appropriate to improve readability. ```suggestion "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>`." ```
@ -3638,0 +3648,4 @@
await ctx.send(
_("`{service}` API tokens have been set.").format(service=service),
embed=embed if len(embed.fields) > 0 else None,
)
Kreusada (Migrated from github.com) commented 2024-11-17 17:45:31 +01:00

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.

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: ```py angle_bracket_warning = None # define this before iterating through tokens for api_service_name, token in tokens.items(): ... ``` ```py 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.
Jackenmen commented 2026-05-21 04:36:59 +02:00 (Migrated from github.com)

Superseded by #6651

Superseded by #6651

Pull request closed

Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!6265
No description provided.