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

refactor: enforce single param on sending/editing methods #5758

Merged
merged 35 commits into from Jun 9, 2021

Conversation

castdrian
Copy link
Contributor

@castdrian castdrian commented Jun 5, 2021

Please describe the changes this PR makes and why it should be merged:
This PR refactors the methods across the the lib's sending/editing methods to avoid inconsistent overloads by removing multiple param options and enforcing single param usage as laid out in #5771.

(and let's pretend that there isn't a typo in the branch name)
Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I pretend to know how to update typings and have done so, or typings don't need updating
  • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)

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.

I don't see a reason for this to be done, but either way the docs are wrong

src/structures/interfaces/InteractionResponses.js Outdated Show resolved Hide resolved
src/structures/interfaces/InteractionResponses.js Outdated Show resolved Hide resolved
src/structures/interfaces/InteractionResponses.js Outdated Show resolved Hide resolved
@castdrian castdrian changed the title refactor(InteractionResponses): only allow options as input refactor(Consistency): enforce options objects across the interaction/channel methods Jun 5, 2021
@castdrian castdrian marked this pull request as draft June 5, 2021 19:39
@monbrey
Copy link
Member

monbrey commented Jun 5, 2021

I like this change, it had been in the back of my mind for a while. I'd argue that we should do the same thing to <TextChannel>.send though, and enforce an object everywhere.

@castdrian
Copy link
Contributor Author

I like this change, it had been in the back of my mind for a while. I'd argue that we should do the same thing to <TextChannel>.send though, and enforce an object everywhere.

Yes same, refer to internals, I got the go from Crawl to refactor the rest, hence why I changed the title and converted to draft

@castdrian castdrian changed the title refactor(Consistency): enforce options objects across the interaction/channel methods refactor(Consistency): enforce options objects across the lib Jun 6, 2021
Copy link
Contributor Author

@castdrian castdrian left a comment

Choose a reason for hiding this comment

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

-refactored again, comment dismissed-

@castdrian castdrian marked this pull request as ready for review June 6, 2021 13:56
src/structures/Message.js Outdated Show resolved Hide resolved
@iCrawl iCrawl linked an issue Jun 6, 2021 that may be closed by this pull request
@ckohen
Copy link
Member

ckohen commented Jun 6, 2021

I think this would call for a refactor of APIMessage.create as well, since it would always be an options object, splitting it out no longer makes sense to me.

@castdrian
Copy link
Contributor Author

I think this would call for a refactor of APIMessage.create as well, since it would always be an options object, splitting it out no longer makes sense to me.

Actually probably not as I am currently refactoring to what the maintainers have internally decided upon, crawl laid it out in details in #5771

@castdrian castdrian changed the title refactor(Consistency): enforce options objects across the lib refactor(Consistency): enforce single param across the lib Jun 6, 2021
@ckohen
Copy link
Member

ckohen commented Jun 6, 2021

I did read the linked issue, it suggests only content should ever be provided standalone. meaning all the checks in APIMessage.transformOptions should never be hit, the whole purpose of those checks is to allow what is being removed here.
There will need to be a check whether options is a string though.

Something for the maintainers to address, should we still be able to pass an APIMessage to these methods still? I think it can be quite useful, but not sure if its wanted.

You can also just pass options to APIMessage.create already anyways, no need to options.content, options

@castdrian
Copy link
Contributor Author

Yeah I got a go on what to do, it's been discussed to pretty much do what the issue says and merge it into one param, and yeah I saw that the apimessage creation param is optional, will adress that :)

src/structures/Message.js Outdated Show resolved Hide resolved
typings/index.d.ts Outdated Show resolved Hide resolved
typings/index.d.ts Outdated Show resolved Hide resolved
typings/index.d.ts Outdated Show resolved Hide resolved
typings/index.d.ts Outdated Show resolved Hide resolved
castdrian and others added 5 commits June 8, 2021 17:28
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
Copy link
Member

@SpaceEEC SpaceEEC left a comment

Choose a reason for hiding this comment

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

Seems like I missed two:

typings/index.d.ts Outdated Show resolved Hide resolved
typings/index.d.ts Outdated Show resolved Hide resolved
castdrian and others added 2 commits June 9, 2021 13:01
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
@iCrawl iCrawl changed the title refactor(Consistency): enforce single param on sending/editing methods refactor: enforce single param on sending/editing methods Jun 9, 2021
@iCrawl iCrawl merged commit 0467a90 into discordjs:master Jun 9, 2021
@castdrian castdrian deleted the interaction-reponses branch June 9, 2021 12:35
@austr1an
Copy link
Contributor

austr1an commented Jun 9, 2021

Some examples were not changed :

* channel.send('This is an embed', {
* embed: {
* thumbnail: {
* url: 'attachment://file.jpg'
* }
* },
* files: [{
* attachment: 'entire/path/to/file.jpg',
* name: 'file.jpg'
* }]
* })
* .then(console.log)
* .catch(console.error);

I saw another but it got patched while I was writing this comment lol

@austr1an
Copy link
Contributor

austr1an commented Jun 9, 2021

same here :

* interaction.update("A button was clicked", { components: [] })
* .then(console.log)
* .catch(console.error);
*/

@kyranet
Copy link
Member

kyranet commented Jun 9, 2021

Are you able to open a PR fixing those docs, @AustrianDev?

If so, it'd be nice if you could work on those, otherwise let us know and a contributor will work on those 👍🏼

@austr1an
Copy link
Contributor

austr1an commented Jun 9, 2021

Ok, I will

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.

Changes to how sending messages works