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

feat(MessageAttachment): allow files to be marked as spoilers #6509

Merged
merged 7 commits into from Aug 24, 2021
Merged

feat(MessageAttachment): allow files to be marked as spoilers #6509

merged 7 commits into from Aug 24, 2021

Conversation

J-Human
Copy link
Contributor

@J-Human J-Human commented Aug 23, 2021

Please describe the changes this PR makes and why it should be merged:

This allows users to mark media as spoilers before sending them to Discord's API. The motivation behind this is for convenience, as in, users not needing to place the SPOILER_ string.

You'll see a validation if the given argument is false, as it's possible to have the spoiler string inside the string itself, hence removing the title users would expect.

I have adapted this PR from #6473 but I didn't make it an equivalent setter as the function is more easy to use.

Resolves #6473

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating
  • This PR changes the library's interface (methods or parameters added)

Copy link
Member

@Jiralite Jiralite left a comment

Choose a reason for hiding this comment

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

Has this been tested? This method is calling the spoiler getter, which returns the basename utility method and passes the URL across. But that won't exist via instantiating this class and will throw an error?

@ImRodry
Copy link
Contributor

ImRodry commented Aug 23, 2021

I suggested the brackets exactly because of that. You should install eslint locally so that it tells you about these errors before pushing.

Copy link
Contributor

@ImRodry ImRodry left a comment

Choose a reason for hiding this comment

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

Imo you only need 1 return at the end, the others are redundant. Otherwise LGTM

@Jiralite
Copy link
Member

This is a bit strange now. If a user runs .setSpoiler(), the attachment will be marked as a spoiler that is yet to be sent. If they decide to run the .spoiler getter to see if it's been marked as a spoiler, it'll throw an error because it's expecting a URL. Right now it's valid only for received messages... maybe it should be adjusted for to-be messages also?

@ImRodry
Copy link
Contributor

ImRodry commented Aug 23, 2021

This is a bit strange now. If a user runs .setSpoiler(), the attachment will be marked as a spoiler that is yet to be sent. If they decide to run the .spoiler getter to see if it's been marked as a spoiler, it'll throw an error because it's expecting a URL. Right now it's valid only for received messages... maybe it should be adjusted for to-be messages also?

Tbh it should’ve been like that from the beginning, and it’s as simple as adding ?? this.name inside the Util.basename call

@J-Human
Copy link
Contributor Author

J-Human commented Aug 24, 2021

This is a bit strange now. If a user runs .setSpoiler(), the attachment will be marked as a spoiler that is yet to be sent. If they decide to run the .spoiler getter to see if it's been marked as a spoiler, it'll throw an error because it's expecting a URL. Right now it's valid only for received messages... maybe it should be adjusted for to-be messages also?

Tbh it should’ve been like that from the beginning, and it’s as simple as adding ?? this.name inside the Util.basename call

Yeah, I actually agree with this idea since it's the shortest approach to do and it simplifies the job and any future tasks that needs name validation. I'll commit this, along with the if/else-if thing, as it was suggested to be removed by ckohen earlier on.

Copy link
Contributor

@NotSugden NotSugden left a comment

Choose a reason for hiding this comment

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

remove x === boolean in favour of x and !x

@J-Human
Copy link
Contributor Author

J-Human commented Aug 24, 2021

Done, suggestions have been committed

src/structures/MessageAttachment.js Outdated Show resolved Hide resolved
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
@J-Human J-Human requested a review from kyranet August 24, 2021 10:31
@J-Human
Copy link
Contributor Author

J-Human commented Aug 24, 2021

This is unusual. It seems all 4 checks failed to request npm. Kindly rerun them again later. 😄

@kyranet
Copy link
Member

kyranet commented Aug 24, 2021

It seems like npm hates you. I'll be re-running until it goes through.

@J-Human
Copy link
Contributor Author

J-Human commented Aug 24, 2021

Done

@iCrawl iCrawl added this to the Version 13.2 milestone Aug 24, 2021
@iCrawl iCrawl merged commit 96e26c4 into discordjs:main Aug 24, 2021
@J-Human J-Human deleted the feat/attachment-setspoiler branch August 24, 2021 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set MessageAttachment as spoiler for remote file
10 participants