-
-
Notifications
You must be signed in to change notification settings - Fork 40
Feat: Adding poll support #18
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
Changes from 6 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
f006023
Added data-structures for REST API
budgetdevv 15a093c
Added MessagePollAnswer.Id
budgetdevv 73c758a
Added MessagePollAnswerCount.cs and MessagePollResults.cs
budgetdevv 3188942
Avoid hiding JsonEntity.Id, renamed to AnswerId
budgetdevv 44514ac
Made some properties `required`
budgetdevv d3e400c
- Removed MessagePollBase.cs ( Kuba said send / receive shouldn't mix )
budgetdevv 429ea12
Get rid of required keyword
budgetdevv 267ef99
- Added JsonMessagePollAnswerCount.cs
budgetdevv 9994050
Get rid of null! usage
budgetdevv b5ba61c
Fixed formatting
budgetdevv 13586cf
- Remove required keyword, suppress using null! ( Rider seems to comp…
budgetdevv 2e315cc
- Added MessagePoll.Results
budgetdevv b0935b4
Don't use null!
budgetdevv 7520a04
Added MessagePollMediaProperties.cs and MessagePollAnswerProperties.cs
budgetdevv 7233eae
Added constructor to MessagePollAnswerProperties.cs
budgetdevv 0ec3f2d
Optimize namespace
budgetdevv 4eac4c0
Added comments
budgetdevv 01f0810
Added RestClient.Undocumented.ExpirePollAsync(). Not too sure if it w…
budgetdevv e5e0b78
Removed property in JsonMessagePollResults.cs
budgetdevv b514da3
Removed initializer
budgetdevv e98a32f
Removed MessagePoll's setters
budgetdevv cfbf103
Read values from JsonModel instead of storing them
budgetdevv ce54d61
Removed SetsRequiredMembers attribute
budgetdevv d0802d0
- Convert more constructors to primary ones.
budgetdevv 20db56e
MessagePoll.cs:
budgetdevv a070dae
Prefer IEnumerable over array.
budgetdevv 6d834de
Removed redundant partial keyword
budgetdevv ab2643e
Revert change to IReadOnlyList
budgetdevv 8ee04f0
Use IReadOnlyList
budgetdevv 5d3e369
Fixed JsonMessagePollResults.cs
budgetdevv aceb052
Revert back to IReadOnlyList for MessagePollResults.Answers, it seems…
budgetdevv db3c355
Made AnswerId a uint
budgetdevv 6ad8d6a
Renamed ExpireAt to ExpiresAt for consistency
budgetdevv 64107c9
AnswerId is now a uint for MessagePollAnswer.cs ( And its JSON variant )
budgetdevv 014772c
It seems like MessagePollResults.Answers is is not nullable. An empty…
budgetdevv dd2a05d
AnswerId should be uint
budgetdevv 4161b6e
It seems like this is only sent via gateway, commenting out for now...
budgetdevv 2d1db6a
Fixed RestMessage.ExpirePollAsync() ( Hopefully )
budgetdevv eff9175
Make MessagePollProperties.LayoutType nullable.
budgetdevv ca75062
Re-included MessagePollResults.ContainsAnswers
budgetdevv 43a66e4
Made ids signed integer
budgetdevv 618cc09
Optimize namespace
budgetdevv 77549ee
Added InteractionMessageProperties.Poll
budgetdevv 564dfcf
- Implemented RestMessage.GetPollAnswerVoters() ( Need to figure out …
budgetdevv 67f9876
- Added JsonGetPollAnswerVotersResult.cs
budgetdevv eb4e1d3
Made afterUserId an optional parameter
budgetdevv a65e33f
Default DurationInHours to 1 ( Via optional ctor param )
budgetdevv acf5846
Fixed HttpMethod for RestMessage.GetPollAnswerVotersAsync() ( How doe…
budgetdevv de9f793
Added convenience API for constructing MessagePollAnswerProperties.cs
budgetdevv 6b65212
Made params in primary ctor optional
budgetdevv dbef41a
Merge branch 'NetCordDev:alpha' into polls
budgetdevv ea917d7
Added MESSAGE_POLL_VOTE_ADD and MESSAGE_POLL_VOTE_REMOVE gateway even…
budgetdevv bbf4fd1
Added poll intents, made intents less complicated
budgetdevv 03d0345
Added Poll field to WebhookMessageProperties.cs
budgetdevv 22e617d
Merge branch 'NetCordDev:alpha' into polls
budgetdevv 8e9c1c0
Adapt [GenerateAlias] to new NetCord commit
budgetdevv 2105555
Added Poll property to IPartialMessage / PartialMessage
budgetdevv 21ff69a
Source generate ExpirePollAsync() and GetPollAnswerVotersAsync() for …
budgetdevv 9a2ecda
Message poll results are nullable
budgetdevv e73720a
Improvements
KubaZ2 c1cbfd9
Merge branch 'alpha' into polls
KubaZ2 3d31888
Work
KubaZ2 5dabdc0
Cleanup
KubaZ2 4662f06
Delete a comment
KubaZ2 3008a9b
Add missing `GenerateAliasAttribute`s
KubaZ2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| using NetCord.JsonModels; | ||
|
|
||
| namespace NetCord.Rest.JsonModels; | ||
|
|
||
| public partial class JsonMessagePoll: JsonEntity | ||
| { | ||
| [JsonPropertyName("question")] | ||
| public JsonMessagePollMedia Question { get; set; } = null!; | ||
|
budgetdevv marked this conversation as resolved.
Outdated
|
||
|
|
||
| [JsonPropertyName("answers")] | ||
| public JsonMessagePollAnswer[] Answers { get; set; } = null!; | ||
|
budgetdevv marked this conversation as resolved.
Outdated
|
||
|
|
||
| [JsonPropertyName("allow_multiselect")] | ||
| public bool AllowMultiselect { get; set; } | ||
|
|
||
| [JsonPropertyName("layout_type")] | ||
| public MessagePollLayoutType LayoutType { get; set; } | ||
|
|
||
| // Non-expiring posts are possible in the future, see: https://github.com/discord/discord-api-docs/blob/e4bdf50f11f9ca61ace2636285e029a2b3dfd0ec/docs/resources/Poll.md#poll-object | ||
| [JsonPropertyName("expiry")] | ||
| public DateTimeOffset? ExpireAt { get; set; } | ||
| } | ||
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,14 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| using NetCord.JsonModels; | ||
|
|
||
| namespace NetCord.Rest.JsonModels; | ||
|
|
||
| public partial class JsonMessagePollAnswer : JsonEntity | ||
| { | ||
| [JsonPropertyName("answer_id")] | ||
| public ulong AnswerId { get; set; } | ||
|
|
||
| [JsonPropertyName("poll_media")] | ||
| public required JsonMessagePollMedia PollMedia { get; set; } | ||
| } |
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,14 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| using NetCord.JsonModels; | ||
|
|
||
| namespace NetCord.Rest.JsonModels; | ||
|
|
||
| public class JsonMessagePollMedia : JsonEntity | ||
| { | ||
| [JsonPropertyName("text")] | ||
| public string? Text { get; set; } | ||
|
|
||
| [JsonPropertyName("emoji")] | ||
| public JsonEmoji? Emoji { get; set; } | ||
| } |
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,16 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| using NetCord.JsonModels; | ||
|
|
||
| namespace NetCord.Rest.JsonModels; | ||
|
|
||
| public partial class JsonMessagePollResults : JsonEntity | ||
| { | ||
| [JsonPropertyName("is_finalized")] | ||
| public bool IsFinalized { get; set; } | ||
|
|
||
| [JsonPropertyName("answer_counts")] | ||
| public MessagePollAnswerCount[]? Answers { get; set; } | ||
|
|
||
| public bool ContainsAnswers => Answers != null; | ||
| } |
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,24 @@ | ||
| using NetCord.Rest.JsonModels; | ||
|
|
||
| namespace NetCord.Rest; | ||
|
|
||
| public partial class MessagePoll : IJsonModel<JsonMessagePoll> | ||
| { | ||
| public JsonMessagePoll JsonModel { get; } | ||
| public MessagePollMedia Question { get; set; } = null!; | ||
| public MessagePollAnswer[] Answers { get; } | ||
| public bool AllowMultiselect { get; set; } | ||
| public MessagePollLayoutType LayoutType { get; set; } | ||
| // Non-expiring posts are possible in the future, see: https://github.com/discord/discord-api-docs/blob/e4bdf50f11f9ca61ace2636285e029a2b3dfd0ec/docs/resources/Poll.md#poll-object | ||
| public DateTimeOffset? ExpireAt { get; } | ||
|
|
||
| public MessagePoll(JsonMessagePoll jsonModel, ulong guildId, RestClient client) | ||
| { | ||
| JsonModel = jsonModel; | ||
| Question = new(jsonModel.Question, guildId, client); | ||
| Answers = jsonModel.Answers.Select(x => new MessagePollAnswer(x, guildId, client)).ToArray(); | ||
| AllowMultiselect = jsonModel.AllowMultiselect; | ||
| LayoutType = jsonModel.LayoutType; | ||
| ExpireAt = jsonModel.ExpireAt; | ||
| } | ||
| } |
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,20 @@ | ||
| using System.Diagnostics.CodeAnalysis; | ||
|
|
||
| using NetCord.Rest.JsonModels; | ||
|
|
||
| namespace NetCord.Rest; | ||
|
|
||
| public partial class MessagePollAnswer : IJsonModel<JsonMessagePollAnswer> | ||
| { | ||
| public JsonMessagePollAnswer JsonModel { get; } | ||
| public ulong AnswerId { get; set; } | ||
| public required MessagePollMedia PollMedia { get; set; } | ||
|
|
||
| [SetsRequiredMembers] | ||
| public MessagePollAnswer(JsonMessagePollAnswer jsonModel, ulong guildId, RestClient client) | ||
| { | ||
| JsonModel = jsonModel; | ||
| AnswerId = jsonModel.AnswerId; | ||
| PollMedia = new(jsonModel.PollMedia, guildId, client); | ||
| } | ||
| } |
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,17 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| using NetCord.JsonModels; | ||
|
|
||
| namespace NetCord.Rest; | ||
|
|
||
| public partial class MessagePollAnswerCount : JsonEntity | ||
| { | ||
| [JsonPropertyName("id")] | ||
| public int AnswerId { get; set; } | ||
|
budgetdevv marked this conversation as resolved.
|
||
|
|
||
| [JsonPropertyName("count")] | ||
| public int Count { get; set; } | ||
|
|
||
| [JsonPropertyName("me_voted")] | ||
| public bool MeVoted { get; set; } | ||
| } | ||
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,6 @@ | ||
| namespace NetCord.Rest; | ||
|
|
||
| public enum MessagePollLayoutType | ||
| { | ||
| Default = 1, | ||
| } |
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,22 @@ | ||
| using NetCord.Rest.JsonModels; | ||
|
|
||
| namespace NetCord.Rest; | ||
|
|
||
| public class MessagePollMedia : IJsonModel<JsonMessagePollMedia> | ||
| { | ||
| public JsonMessagePollMedia JsonModel { get; } | ||
|
|
||
| public string? Text { get; } | ||
|
|
||
| public Emoji? Emoji { get; } | ||
|
|
||
| public MessagePollMedia(JsonMessagePollMedia jsonModel, ulong guildId, RestClient client) | ||
| { | ||
| JsonModel = jsonModel; | ||
| Text = jsonModel.Text; | ||
|
|
||
| var emoji = jsonModel.Emoji; | ||
| if (emoji != null) | ||
| Emoji = Emoji.CreateFromJson(emoji, guildId, client); | ||
| } | ||
| } |
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,24 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| using NetCord.JsonModels; | ||
| using NetCord.Rest.JsonModels; | ||
|
|
||
| namespace NetCord.Rest; | ||
|
|
||
| public partial class MessagePollProperties : JsonEntity | ||
| { | ||
| [JsonPropertyName("question")] | ||
| public required JsonMessagePollMedia Question { get; set; } | ||
|
|
||
| [JsonPropertyName("answers")] | ||
| public required JsonMessagePollAnswer[] Answers { get; set; } | ||
|
|
||
| [JsonPropertyName("allow_multiselect")] | ||
| public bool AllowMultiselect { get; set; } | ||
|
|
||
| [JsonPropertyName("layout_type")] | ||
| public MessagePollLayoutType LayoutType { get; set; } | ||
|
|
||
| [JsonPropertyName("duration")] | ||
| public required int DurationInHours { get; set; } | ||
| } |
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,21 @@ | ||
| using NetCord.Rest.JsonModels; | ||
|
|
||
| namespace NetCord.Rest; | ||
|
|
||
| public partial class MessagePollResults : IJsonModel<JsonMessagePollResults> | ||
| { | ||
| public JsonMessagePollResults JsonModel { get; } | ||
|
|
||
| public bool IsFinalized { get; } | ||
|
|
||
| public MessagePollAnswerCount[]? Answers { get; } | ||
|
|
||
| public bool ContainsAnswers => Answers != null; | ||
|
|
||
| public MessagePollResults(JsonMessagePollResults jsonModel) | ||
| { | ||
| JsonModel = jsonModel; | ||
| IsFinalized = jsonModel.IsFinalized; | ||
| Answers = jsonModel.Answers; | ||
| } | ||
| } |
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
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.