-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial poll implementation * Added entity extensions. Added poll prefix to method name * Added poll dispatch handlers * Added poll permissions * Added REST error codes * Added poll intents * Added poll gateway events * Implemented local poll CreateFrom methods.
- Loading branch information
Showing
57 changed files
with
1,178 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents a poll. | ||
/// </summary> | ||
public interface IPoll : IEntity | ||
{ | ||
/// <summary> | ||
/// Gets the question of this poll. | ||
/// </summary> | ||
IPollMedia Question { get; } | ||
|
||
/// <summary> | ||
/// Gets the answers of this poll. | ||
/// </summary> | ||
IReadOnlyList<IPollAnswer> Answers { get; } | ||
|
||
/// <summary> | ||
/// Gets the expiry of this poll. | ||
/// </summary> | ||
DateTimeOffset? Expiry { get; } | ||
|
||
/// <summary> | ||
/// Gets whether this poll allows selection of multiple answers. | ||
/// </summary> | ||
bool AllowMultiselect { get; } | ||
|
||
/// <summary> | ||
/// Gets the layout type of this poll. | ||
/// </summary> | ||
PollLayoutType LayoutType { get; } | ||
|
||
/// <summary> | ||
/// Gets the results of this poll. | ||
/// </summary> | ||
IPollResults? Results { get; } | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Disqord.Core/Entities/Core/Message/User/Poll/IPollAnswer.cs
This file contains 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 @@ | ||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents a poll answer. | ||
/// </summary> | ||
public interface IPollAnswer : IEntity | ||
{ | ||
/// <summary> | ||
/// Gets the ID of the poll answer. This is used to match <see cref="IPollAnswerCount"/> based on the ID. | ||
/// </summary> | ||
int Id { get; } | ||
|
||
/// <summary> | ||
/// Gets the media of this poll answer. | ||
/// </summary> | ||
IPollMedia Media { get; } | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Disqord.Core/Entities/Core/Message/User/Poll/IPollAnswerCount.cs
This file contains 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 @@ | ||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents the vote count of a poll answer. | ||
/// </summary> | ||
public interface IPollAnswerCount : IEntity | ||
{ | ||
/// <summary> | ||
/// Gets the ID of the poll answer. | ||
/// </summary> | ||
int AnswerId { get; } | ||
|
||
/// <summary> | ||
/// Gets the amount of users that selected the poll answer. | ||
/// </summary> | ||
int Count { get; } | ||
|
||
/// <summary> | ||
/// Gets whether the bot has selected the poll answer. | ||
/// </summary> | ||
bool HasOwnVote { get; } | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Disqord.Core/Entities/Core/Message/User/Poll/IPollMedia.cs
This file contains 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 @@ | ||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents poll media. | ||
/// </summary> | ||
public interface IPollMedia : IEntity | ||
{ | ||
/// <summary> | ||
/// Gets the text of this poll media. | ||
/// </summary> | ||
string? Text { get; } | ||
|
||
/// <summary> | ||
/// Gets the emoji of this poll media. | ||
/// </summary> | ||
IEmoji? Emoji { get; } | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Disqord.Core/Entities/Core/Message/User/Poll/IPollResults.cs
This file contains 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,19 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Disqord; | ||
|
||
/// <summary> | ||
/// Represents the results of a poll. | ||
/// </summary> | ||
public interface IPollResults : IEntity | ||
{ | ||
/// <summary> | ||
/// Gets whether the votes have been precisely counted. | ||
/// </summary> | ||
bool IsFinalized { get; } | ||
|
||
/// <summary> | ||
/// Gets the vote counts of each answer. | ||
/// </summary> | ||
IReadOnlyList<IPollAnswerCount> AnswerCounts { get; } | ||
} |
This file contains 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 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
14 changes: 14 additions & 0 deletions
14
src/Disqord.Core/Entities/Local/Message/Poll/Extensions/LocalPollAnswerExtensions.cs
This file contains 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.ComponentModel; | ||
|
||
namespace Disqord; | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public static class LocalPollAnswerExtensions | ||
{ | ||
public static TPollAnswer WithMedia<TPollAnswer>(this TPollAnswer answer, LocalPollMedia media) | ||
where TPollAnswer : LocalPollAnswer | ||
{ | ||
answer.Media = media; | ||
return answer; | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/Disqord.Core/Entities/Local/Message/Poll/Extensions/LocalPollExtensions.cs
This file contains 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,91 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using Qommon; | ||
|
||
namespace Disqord; | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public static class LocalPollExtensions | ||
{ | ||
public static TPoll WithQuestion<TPoll>(this TPoll poll, string text) | ||
where TPoll : LocalPoll | ||
{ | ||
var media = new LocalPollMedia() | ||
{ | ||
Text = text | ||
}; | ||
|
||
return poll.WithQuestion(media); | ||
} | ||
|
||
public static TPoll WithQuestion<TPoll>(this TPoll poll, LocalPollMedia question) | ||
where TPoll : LocalPoll | ||
{ | ||
poll.Question = question; | ||
return poll; | ||
} | ||
|
||
public static TPoll AddAnswer<TPoll>(this TPoll poll, string text, LocalEmoji? emoji = null) | ||
where TPoll : LocalPoll | ||
{ | ||
var media = new LocalPollMedia | ||
{ | ||
Text = text, | ||
Emoji = Optional.FromNullable(emoji) | ||
}; | ||
|
||
var answer = new LocalPollAnswer() | ||
{ | ||
Media = media | ||
}; | ||
|
||
return poll.AddAnswer(answer); | ||
} | ||
|
||
public static TPoll AddAnswer<TPoll>(this TPoll poll, LocalPollAnswer answer) | ||
where TPoll : LocalPoll | ||
{ | ||
if (poll.Answers.Add(answer, out var list)) | ||
poll.Answers = new(list); | ||
|
||
return poll; | ||
} | ||
|
||
public static TPoll WithAnswers<TPoll>(this TPoll poll, IEnumerable<LocalPollAnswer> answers) | ||
where TPoll : LocalPoll | ||
{ | ||
Guard.IsNotNull(answers); | ||
|
||
if (poll.Answers.With(answers, out var list)) | ||
poll.Answers = new(list); | ||
|
||
return poll; | ||
} | ||
|
||
public static TPoll WithAnswers<TPoll>(this TPoll poll, params LocalPollAnswer[] answers) | ||
where TPoll : LocalPoll | ||
{ | ||
return poll.WithAnswers(answers as IEnumerable<LocalPollAnswer>); | ||
} | ||
|
||
public static TPoll WithDuration<TPoll>(this TPoll poll, int duration) | ||
where TPoll : LocalPoll | ||
{ | ||
poll.Duration = duration; | ||
return poll; | ||
} | ||
|
||
public static TPoll WithAllowMultiselect<TPoll>(this TPoll poll, bool allowMultiselect = true) | ||
where TPoll : LocalPoll | ||
{ | ||
poll.AllowMultiselect = allowMultiselect; | ||
return poll; | ||
} | ||
|
||
public static TPoll WithLayoutType<TPoll>(this TPoll poll, PollLayoutType layoutType) | ||
where TPoll : LocalPoll | ||
{ | ||
poll.LayoutType = layoutType; | ||
return poll; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Disqord.Core/Entities/Local/Message/Poll/Extensions/LocalPollMediaExtensions.cs
This file contains 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 System.ComponentModel; | ||
|
||
namespace Disqord; | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public static class LocalPollMediaExtensions | ||
{ | ||
public static TPollMedia WithText<TPollMedia>(this TPollMedia media, string text) | ||
where TPollMedia : LocalPollMedia | ||
{ | ||
media.Text = text; | ||
return media; | ||
} | ||
|
||
public static TPollMedia WithEmoji<TPollMedia>(this TPollMedia media, LocalEmoji emoji) | ||
where TPollMedia : LocalPollMedia | ||
{ | ||
media.Emoji = emoji; | ||
return media; | ||
} | ||
} |
Oops, something went wrong.