-
-
Notifications
You must be signed in to change notification settings - Fork 4k
feat: polls overhaul #10328
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
Merged
Merged
feat: polls overhaul #10328
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
e5a5966
feat(Managers): add PollAnswerVoterManager
uhKevinMC ea2cb46
feat(Partials): make Polls partial-safe
uhKevinMC 9370828
types: add typings
uhKevinMC f311a41
chore: add tests
uhKevinMC e33342c
fix: use fetch method in manager instead
uhKevinMC c4c7806
chore: add tests for manager
uhKevinMC 068d17a
feat: add partial support to poll actions
uhKevinMC ed3104a
style: formatting
uhKevinMC 648f767
Merge branch 'discordjs:main' into main
uhKevinMC 6db874e
fix: change all .users references to .voters
uhKevinMC 43930c1
refactor: add additional logic for partials
uhKevinMC 01fca07
fix: actually add the partials
uhKevinMC 08061e6
fix: fixed issue where event does not emit on first event
uhKevinMC 056fb3c
fix: align property type with DAPI documentation
uhKevinMC 7113c56
fix: resolve additional bugs with partials
uhKevinMC c1c848a
typings: update typings to reflect property type change
uhKevinMC f4686f0
fix: tests
uhKevinMC 2c4bc44
chore: rebase branch
uhKevinMC e241cea
fix: adjust tests
uhKevinMC 316e7cc
refactor: combine partials logic into one statement
uhKevinMC f4b2911
docs: mark getter as readonly
uhKevinMC 4203f09
refactor: apply suggestions
uhKevinMC e16401e
refactor(Actions): apply suggestions
uhKevinMC ec18c50
refactor(PollAnswerVoterManager): apply suggestions
uhKevinMC 598fbfd
refactor(Message): check for existing poll before creating a poll
uhKevinMC 8780adb
refactor(Polls): apply suggestions
uhKevinMC fa4dc3f
revert(types): remove unused method from Poll class
uhKevinMC bfbb377
refactor(Actions): consolidate poll creation logic into action class
uhKevinMC 2eec293
refactor(PollAnswerVoterManager): set default for fetch parameter
uhKevinMC 6e632ba
refactor(Message): apply suggestion
uhKevinMC 4857a94
fix: remove partial setter
uhKevinMC bb2a2ad
refactor(Polls): apply suggestions
uhKevinMC 418c23b
types: apply suggestions
uhKevinMC 2e54eff
Merge branch 'discordjs:main' into main
uhKevinMC 2f85ad8
refactor: remove clones
uhKevinMC 93f2a36
docs: spacing
uhKevinMC c25c650
refactor: move setters from constructor to _patch
uhKevinMC 060cc52
types: adjust partials for poll classes
uhKevinMC cea18b0
test: add more tests for polls
uhKevinMC 46f55e4
refactor: move updates around, more correct partial types
almeidx 4c65504
fix: handle more cases
almeidx a82f3a3
refactor: requested changes
almeidx 1ddb5ab
Merge branch 'main' into main
almeidx 71f1c65
Merge branch 'main' into main
almeidx f72c1f6
Merge branch 'main' into main
almeidx d103cd9
fix: missing imports
almeidx a8a4f29
Merge branch 'main' into main
almeidx ba19104
Merge branch 'main' into main
almeidx 955cf6a
fix: update imports
almeidx 6e73d7b
Merge branch 'main' into main
almeidx fa0244a
fix: require file extensions
almeidx 908f2a3
Merge branch 'main' into main
Qjuh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/discord.js/src/managers/PollAnswerVoterManager.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const { Collection } = require('@discordjs/collection'); | ||
const { makeURLSearchParams } = require('@discordjs/rest'); | ||
const { Routes } = require('discord-api-types/v10'); | ||
const { CachedManager } = require('./CachedManager.js'); | ||
const { User } = require('../structures/User.js'); | ||
|
||
/** | ||
* Manages API methods for users who voted on a poll and stores their cache. | ||
* @extends {CachedManager} | ||
*/ | ||
class PollAnswerVoterManager extends CachedManager { | ||
constructor(answer) { | ||
super(answer.client, User); | ||
|
||
/** | ||
* The poll answer that this manager belongs to | ||
* @type {PollAnswer} | ||
*/ | ||
this.answer = answer; | ||
} | ||
|
||
/** | ||
* The cache of this manager | ||
* @type {Collection<Snowflake, User>} | ||
* @name PollAnswerVoterManager#cache | ||
*/ | ||
|
||
/** | ||
* Fetches the users that voted on this poll answer. Resolves with a collection of users, mapped by their ids. | ||
* @param {BaseFetchPollAnswerVotersOptions} [options={}] Options for fetching the users | ||
* @returns {Promise<Collection<Snowflake, User>>} | ||
*/ | ||
async fetch({ after, limit } = {}) { | ||
const poll = this.answer.poll; | ||
const query = makeURLSearchParams({ limit, after }); | ||
const data = await this.client.rest.get(Routes.pollAnswerVoters(poll.channelId, poll.messageId, this.answer.id), { | ||
query, | ||
}); | ||
|
||
return data.users.reduce((coll, rawUser) => { | ||
const user = this.client.users._add(rawUser); | ||
this.cache.set(user.id, user); | ||
return coll.set(user.id, user); | ||
}, new Collection()); | ||
} | ||
} | ||
|
||
exports.PollAnswerVoterManager = PollAnswerVoterManager; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.