-
-
Notifications
You must be signed in to change notification settings - Fork 737
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Guild Onboarding support (#2616)
* api models * moar models * complete models * modelsss * forgot to push * oh lol forgot this too * api & rest guild method * revert VS being VS & formatting to file scoped namespace * socket entities * yup * fix xml doc * changes
- Loading branch information
Showing
18 changed files
with
574 additions
and
3 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
17 changes: 17 additions & 0 deletions
17
src/Discord.Net.Core/Entities/Guilds/Onboarding/GuildOnboardingPromptType.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 Discord; | ||
|
||
/// <summary> | ||
/// Represents the guild onboarding option type. | ||
/// </summary> | ||
public enum GuildOnboardingPromptType | ||
{ | ||
/// <summary> | ||
/// The prompt accepts multiple choices. | ||
/// </summary> | ||
MultipleChoice = 0, | ||
|
||
/// <summary> | ||
/// The prompt uses a dropdown menu. | ||
/// </summary> | ||
Dropdown = 1, | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Discord.Net.Core/Entities/Guilds/Onboarding/IGuildOnboarding.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,34 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Discord; | ||
|
||
/// <summary> | ||
/// Represents the guild onboarding flow. | ||
/// </summary> | ||
public interface IGuildOnboarding | ||
{ | ||
/// <summary> | ||
/// Gets the ID of the guild this onboarding is part of. | ||
/// </summary> | ||
ulong GuildId { get; } | ||
|
||
/// <summary> | ||
/// Gets the guild this onboarding is part of. | ||
/// </summary> | ||
IGuild Guild { get; } | ||
|
||
/// <summary> | ||
/// Gets prompts shown during onboarding and in customize community. | ||
/// </summary> | ||
IReadOnlyCollection<IGuildOnboardingPrompt> Prompts { get; } | ||
|
||
/// <summary> | ||
/// Gets IDs of channels that members get opted into automatically. | ||
/// </summary> | ||
IReadOnlyCollection<ulong> DefaultChannelIds { get; } | ||
|
||
/// <summary> | ||
/// Gets whether onboarding is enabled in the guild. | ||
/// </summary> | ||
bool IsEnabled { get; } | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Discord.Net.Core/Entities/Guilds/Onboarding/IGuildOnboardingPrompt.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,40 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Discord; | ||
|
||
/// <summary> | ||
/// Represents the guild onboarding prompt. | ||
/// </summary> | ||
public interface IGuildOnboardingPrompt : ISnowflakeEntity | ||
{ | ||
/// <summary> | ||
/// Gets options available within the prompt. | ||
/// </summary> | ||
IReadOnlyCollection<IGuildOnboardingPromptOption> Options { get; } | ||
|
||
/// <summary> | ||
/// Gets the title of the prompt. | ||
/// </summary> | ||
string Title { get; } | ||
|
||
/// <summary> | ||
/// Indicates whether users are limited to selecting one option for the prompt. | ||
/// </summary> | ||
bool IsSingleSelect { get; } | ||
|
||
/// <summary> | ||
/// Indicates whether the prompt is required before a user completes the onboarding flow. | ||
/// </summary> | ||
bool IsRequired { get; } | ||
|
||
/// <summary> | ||
/// Indicates whether the prompt is present in the onboarding flow. | ||
/// If <see langword="false"/>, the prompt will only appear in the Channels and Roles tab. | ||
/// </summary> | ||
bool IsInOnboarding { get; } | ||
|
||
/// <summary> | ||
/// Gets the type of the prompt. | ||
/// </summary> | ||
GuildOnboardingPromptType Type { get; } | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Discord.Net.Core/Entities/Guilds/Onboarding/IGuildOnboardingPromptOption.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,34 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Discord; | ||
|
||
/// <summary> | ||
/// Represents the guild onboarding prompt option. | ||
/// </summary> | ||
public interface IGuildOnboardingPromptOption : ISnowflakeEntity | ||
{ | ||
/// <summary> | ||
/// Gets IDs of channels a member is added to when the option is selected. | ||
/// </summary> | ||
IReadOnlyCollection<ulong> ChannelIds { get; } | ||
|
||
/// <summary> | ||
/// Gets IDs of roles assigned to a member when the option is selected. | ||
/// </summary> | ||
IReadOnlyCollection<ulong> RoleIds { get; } | ||
|
||
/// <summary> | ||
/// Gets the emoji of the option. <see langword="null"/> if none is set. | ||
/// </summary> | ||
IEmote Emoji { get; } | ||
|
||
/// <summary> | ||
/// Gets the title of the option. | ||
/// </summary> | ||
string Title { get; } | ||
|
||
/// <summary> | ||
/// Gets the description of the option. <see langword="null"/> if none is set. | ||
/// </summary> | ||
string Description { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Discord.API; | ||
|
||
internal class GuildOnboarding | ||
{ | ||
[JsonProperty("guild_id")] | ||
public ulong GuildId { get; set; } | ||
|
||
[JsonProperty("prompts")] | ||
public GuildOnboardingPrompt[] Prompts { get; set; } | ||
|
||
[JsonProperty("default_channel_ids")] | ||
public ulong[] DefaultChannelIds { get; set; } | ||
|
||
[JsonProperty("enabled")] | ||
public bool Enabled { get; set; } | ||
} |
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,27 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Discord.API; | ||
|
||
internal class GuildOnboardingPrompt | ||
{ | ||
[JsonProperty("id")] | ||
public ulong Id { get; set; } | ||
|
||
[JsonProperty("options")] | ||
public GuildOnboardingPromptOption[] Options { get; set; } | ||
|
||
[JsonProperty("title")] | ||
public string Title { get; set; } | ||
|
||
[JsonProperty("single_select")] | ||
public bool IsSingleSelect { get; set; } | ||
|
||
[JsonProperty("required")] | ||
public bool IsRequired { get; set; } | ||
|
||
[JsonProperty("in_onboarding")] | ||
public bool IsInOnboarding { get; set; } | ||
|
||
[JsonProperty("type")] | ||
public GuildOnboardingPromptType Type { get; set; } | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Discord.Net.Rest/API/Common/GuildOnboardingPromptOption.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,24 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Discord.API; | ||
|
||
internal class GuildOnboardingPromptOption | ||
{ | ||
[JsonProperty("id")] | ||
public ulong Id { get; set; } | ||
|
||
[JsonProperty("channel_ids")] | ||
public ulong[] ChannelIds { get; set; } | ||
|
||
[JsonProperty("role_ids")] | ||
public ulong[] RoleIds { get; set; } | ||
|
||
[JsonProperty("emoji")] | ||
public Emoji Emoji { get; set; } | ||
|
||
[JsonProperty("title")] | ||
public string Title { get; set; } | ||
|
||
[JsonProperty("description")] | ||
public Optional<string> Description { get; set; } | ||
} |
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
46 changes: 46 additions & 0 deletions
46
src/Discord.Net.Rest/Entities/Guilds/Onboarding/RestGuildOnboarding.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,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using Model = Discord.API.GuildOnboarding; | ||
|
||
namespace Discord.Rest; | ||
|
||
/// <inheritdoc /> | ||
public class RestGuildOnboarding : IGuildOnboarding | ||
{ | ||
/// <inheritdoc /> | ||
public ulong GuildId { get; private set; } | ||
|
||
/// <inheritdoc cref="IGuildOnboarding.Guild" /> | ||
public RestGuild Guild { get; private set; } | ||
|
||
/// <inheritdoc /> | ||
public IReadOnlyCollection<ulong> DefaultChannelIds { get; private set; } | ||
|
||
/// <inheritdoc /> | ||
public bool IsEnabled { get; private set; } | ||
|
||
/// <inheritdoc cref="IGuildOnboarding.Prompts"/> | ||
public IReadOnlyCollection<RestGuildOnboardingPrompt> Prompts { get; private set; } | ||
|
||
internal RestGuildOnboarding(BaseDiscordClient discord, Model model, RestGuild guild = null) | ||
{ | ||
GuildId = model.GuildId; | ||
DefaultChannelIds = model.DefaultChannelIds.ToImmutableArray(); | ||
IsEnabled = model.Enabled; | ||
|
||
Guild = guild; | ||
Prompts = model.Prompts.Select(prompt => new RestGuildOnboardingPrompt(discord, prompt.Id, prompt)).ToImmutableArray(); | ||
} | ||
|
||
#region IGuildOnboarding | ||
|
||
/// <inheritdoc /> | ||
IReadOnlyCollection<IGuildOnboardingPrompt> IGuildOnboarding.Prompts => Prompts; | ||
|
||
/// <inheritdoc /> | ||
IGuild IGuildOnboarding.Guild => Guild; | ||
|
||
#endregion | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Discord.Net.Rest/Entities/Guilds/Onboarding/RestGuildOnboardingPrompt.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,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using Model = Discord.API.GuildOnboardingPrompt; | ||
|
||
namespace Discord.Rest; | ||
|
||
/// <inheritdoc cref="IGuildOnboardingPrompt"/> | ||
public class RestGuildOnboardingPrompt : RestEntity<ulong>, IGuildOnboardingPrompt | ||
{ | ||
/// <inheritdoc /> | ||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); | ||
|
||
/// <inheritdoc cref="IGuildOnboardingPrompt.Options"/> | ||
public IReadOnlyCollection<RestGuildOnboardingPromptOption> Options { get; private set; } | ||
|
||
/// <inheritdoc /> | ||
public string Title { get; private set; } | ||
|
||
/// <inheritdoc /> | ||
public bool IsSingleSelect { get; private set; } | ||
|
||
/// <inheritdoc /> | ||
public bool IsRequired { get; private set; } | ||
|
||
/// <inheritdoc /> | ||
public bool IsInOnboarding { get; private set; } | ||
|
||
/// <inheritdoc /> | ||
public GuildOnboardingPromptType Type { get; private set; } | ||
|
||
internal RestGuildOnboardingPrompt(BaseDiscordClient discord, ulong id, Model model) : base(discord, id) | ||
{ | ||
Title = model.Title; | ||
IsSingleSelect = model.IsSingleSelect; | ||
IsInOnboarding = model.IsInOnboarding; | ||
IsRequired = model.IsRequired; | ||
Type = model.Type; | ||
|
||
Options = model.Options.Select(option => new RestGuildOnboardingPromptOption(discord, option.Id, option)).ToImmutableArray(); | ||
} | ||
|
||
#region IGuildOnboardingPrompt | ||
|
||
/// <inheritdoc /> | ||
IReadOnlyCollection<IGuildOnboardingPromptOption> IGuildOnboardingPrompt.Options => Options; | ||
|
||
#endregion | ||
} |
Oops, something went wrong.