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

Improve request progress ID check #266

Merged
merged 4 commits into from
Aug 14, 2022
Merged

Conversation

dericksonmark
Copy link
Member

@dericksonmark dericksonmark commented Jul 22, 2022

Purpose

Improve the request progress message ID check. Currently, 100003893070974167M is accepted as a valid message ID, because the string is simply tested for containing an 18-digit number.

Approach

Ensure the message ID takes up the entire string, and allow for 18- and 19-digit message IDs (and above).

@@ -12,7 +12,7 @@ export default class InternalProgressEventHandler implements EventHandler<'messa
private logger = log4js.getLogger( 'InternalProgressEventHandler' );

private isValidId( id: string ): id is Snowflake {
return !!id.match( /[0-9]{18}/ );
return /^[0-9]{18,19}$/.test( id );
Copy link
Member

Choose a reason for hiding this comment

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

The length limit seems unnecessary and error-prone; could we not just have a + instead?

Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering why we need this function in the first place, I'd assume discord.js would provide something similar by itself

Copy link
Member

Choose a reason for hiding this comment

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

Checked the documentation and apparently that isn't a thing. Huh.

Copy link
Member Author

@dericksonmark dericksonmark Jul 26, 2022

Choose a reason for hiding this comment

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

SPGoding: I've kept the minimum 18 digits – is this okay then? Unless something changes greatly in the future of Discord data, the message IDs that show up in the channels will never be 17 digits or less.

violine1101, sort of in reply to your messages: At the moment, if an invalid ID is used here, there is still a try-catch to make sure the bot doesn't crash. However, when doing this, a less informative error message is provided. So no, the function isn't really necessary, but it is if informing the user of an invalid ID is desired.

@violine1101 violine1101 merged commit c29cdf9 into master Aug 14, 2022
@violine1101 violine1101 deleted the improve-message-id-check branch August 14, 2022 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants