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

[Feature] Onboarding updates #2729

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Discord.Net.Core/DiscordErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public enum DiscordErrorCode
StickerAnimationDurationTooLong = 170007,
#endregion

#region Guild Scheduled Events
#region Guild Scheduled Events (180XXX)
CannotUpdateFinishedEvent = 180000,
FailedStageCreation = 180002,
#endregion
Expand All @@ -245,5 +245,10 @@ public enum DiscordErrorCode
WebhookServicesCannotBeUsedInForumChannels = 220004,
MessageBlockedByHarmfulLinksFilter = 240000,
#endregion

#region Onboarding (350XXX)
CannotEnableOnboardingUnmetRequirements = 350000,
CannotUpdateOnboardingBelowRequirements = 350001
#endregion
}
}
8 changes: 8 additions & 0 deletions src/Discord.Net.Core/Entities/Guilds/IGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,5 +1317,13 @@ Task<IReadOnlyCollection<IApplicationCommand>> BulkOverwriteApplicationCommandsA
/// A task that represents the asynchronous creation operation. The task result contains the created <see cref="IGuildOnboarding"/>.
/// </returns>
Task<IGuildOnboarding> GetOnboardingAsync(RequestOptions options = null);

/// <summary>
/// Modifies the onboarding object configured for the guild.
/// </summary>
/// <returns>
/// A task that represents the asynchronous creation operation. The task result contains the modified <see cref="IGuildOnboarding"/>.
/// </returns>
Task<IGuildOnboarding> ModifyOnboardingAsync(Action<GuildOnboardingProperties> props, RequestOptions options = null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Discord;

/// <summary>
/// Defines the criteria used to satisfy Onboarding constraints that are required for enabling.
/// </summary>
public enum GuildOnboardingMode
{
/// <summary>
/// Counts only Default Channels towards constraints.
/// </summary>
Default = 0,

/// <summary>
/// Counts Default Channels and Questions towards constraints.
/// </summary>
Advanced = 1,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections.Generic;

namespace Discord;

/// <summary>
/// Represents properties used to create or modify guild onboarding prompt option.
/// </summary>
public class GuildOnboardingPromptOptionProperties
quinchs marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Gets or sets the Id of the prompt option. If the value is <see langword="null" /> a new prompt will be created.
/// The existing one will be updated otherwise.
/// </summary>
public ulong? Id { get; set; }

/// <summary>
/// Gets or set IDs for channels a member is added to when the option is selected.
/// </summary>
public ulong[] ChannelIds { get; set; }

/// <summary>
/// Gets or sets IDs for roles assigned to a member when the option is selected.
/// </summary>
public ulong[] RoleIds { get; set; }

/// <summary>
/// Gets or sets the emoji of the option.
/// </summary>
public Optional<IEmote> Emoji { get; set; }

/// <summary>
/// Gets or sets the title of the option.
/// </summary>
public string Title { get; set; }

/// <summary>
/// Gets or sets the description of the option.
/// </summary>
public string Description { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections.Generic;

namespace Discord;

/// <summary>
/// Represents properties used to create or modify guild onboarding prompt.
/// </summary>
public class GuildOnboardingPromptProperties
quinchs marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Gets or sets the Id of the prompt. If the value is <see langword="null" /> a new prompt will be created.
/// The existing one will be updated otherwise.
/// </summary>
public ulong? Id { get; set; }

/// <summary>
/// Gets or sets options available within the prompt.
/// </summary>
public GuildOnboardingPromptOptionProperties[] Options { get; set; }

/// <summary>
/// Gets or sets the title of the prompt.
/// </summary>
public string Title { get; set; }

/// <summary>
/// Gets or sets whether users are limited to selecting one option for the prompt.
/// </summary>
public bool IsSingleSelect { get; set; }

/// <summary>
/// Gets or sets whether the prompt is required before a user completes the onboarding flow.
/// </summary>
public bool IsRequired { get; set; }

/// <summary>
/// Gets or sets whether the prompt is present in the onboarding flow.
/// </summary>
public bool IsInOnboarding { get; set; }

/// <summary>
/// Gets or set the type of the prompt.
/// </summary>
public GuildOnboardingPromptType Type { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;

namespace Discord;

/// <summary>
/// Represents properties used to create or modify guild onboarding.
/// </summary>
public class GuildOnboardingProperties
{
/// <summary>
/// Gets or sets prompts shown during onboarding and in customize community.
/// </summary>
public Optional<GuildOnboardingPromptProperties[]> Prompts { get; set; }

/// <summary>
/// Gets or sets channel IDs that members get opted into automatically.
/// </summary>
public Optional<ulong[]> ChannelIds { get; set; }

/// <summary>
/// Gets or sets whether onboarding is enabled in the guild.
/// </summary>
public Optional<bool> IsEnabled { get; set; }

/// <summary>
/// Gets or sets current mode of onboarding.
/// </summary>
public Optional<GuildOnboardingMode> Mode { get; set;}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Discord;

Expand Down Expand Up @@ -31,4 +33,19 @@ public interface IGuildOnboarding
/// Gets whether onboarding is enabled in the guild.
/// </summary>
bool IsEnabled { get; }

/// <summary>
/// Gets the current mode of onboarding.
/// </summary>
GuildOnboardingMode Mode { get; }

/// <summary>
/// Gets whether the server does not meet requirements to enable guild onboarding.
/// </summary>
bool IsBelowRequirements { get; }

/// <summary>
/// Modifies the onboarding object.
/// </summary>
Task ModifyAsync(Action<GuildOnboardingProperties> props, RequestOptions options = null);
}
39 changes: 39 additions & 0 deletions src/Discord.Net.Core/Extensions/GuildOnboardingExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Linq;

namespace Discord;

public static class GuildOnboardingExtensions
{
public static GuildOnboardingProperties ToProperties(this IGuildOnboarding onboarding)
=> new ()
{
ChannelIds = onboarding.DefaultChannelIds.ToArray(),
IsEnabled = onboarding.IsEnabled,
Mode = onboarding.Mode,
Prompts = onboarding.Prompts.Select(x => x.ToProperties()).ToArray(),
};

public static GuildOnboardingPromptProperties ToProperties(this IGuildOnboardingPrompt prompt)
=> new()
{
Id = prompt.Id,
Type = prompt.Type,
IsInOnboarding = prompt.IsInOnboarding,
IsRequired = prompt.IsRequired,
IsSingleSelect = prompt.IsSingleSelect,
Title = prompt.Title,
Options = prompt.Options.Select(x => x.ToProperties()).ToArray()
};

public static GuildOnboardingPromptOptionProperties ToProperties(this IGuildOnboardingPromptOption option)
=> new()
{
Title = option.Title,
ChannelIds = option.ChannelIds.ToArray(),
Description = option.Description,
Emoji = Optional.Create(option.Emoji),
Id = option.Id,
RoleIds = option.RoleIds.ToArray(),
};

}
6 changes: 6 additions & 0 deletions src/Discord.Net.Rest/API/Common/GuildOnboarding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ internal class GuildOnboarding

[JsonProperty("enabled")]
public bool Enabled { get; set; }

[JsonProperty("mode")]
public GuildOnboardingMode Mode { get; set; }

[JsonProperty("below_requirements")]
public bool IsBelowRequirements { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ internal class GuildOnboardingPromptOption
public string Title { get; set; }

[JsonProperty("description")]
public Optional<string> Description { get; set; }
public string Description { get; set; }
}
71 changes: 71 additions & 0 deletions src/Discord.Net.Rest/API/Rest/ModifyGuildOnboardingParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Newtonsoft.Json;

namespace Discord.API.Rest;

internal class ModifyGuildOnboardingParams
{
[JsonProperty("prompts")]
public Optional<GuildOnboardingPromptParams[]> Prompts { get; set; }

[JsonProperty("default_channel_ids")]
public Optional<ulong[]> DefaultChannelIds { get; set; }

[JsonProperty("enabled")]
public Optional<bool> Enabled { get; set; }

[JsonProperty("mode")]
public Optional<GuildOnboardingMode> Mode { get; set; }
}


internal class GuildOnboardingPromptParams
{
[JsonProperty("id")]
public ulong Id { get; set; }

[JsonProperty("options")]
public GuildOnboardingPromptOptionParams[] 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; }
}


internal class GuildOnboardingPromptOptionParams
{
[JsonProperty("id")]
public Optional<ulong> Id { get; set; }

[JsonProperty("channel_ids")]
public ulong[] ChannelIds { get; set; }

[JsonProperty("role_ids")]
public ulong[] RoleIds { get; set; }

[JsonProperty("emoji_name")]
public string EmojiName { get; set; }

[JsonProperty("emoji_id")]
public ulong? EmojiId { get; set; }

[JsonProperty("emoji_animated")]
public bool? EmojiAnimated { get; set; }

[JsonProperty("title")]
public string Title { get; set; }

[JsonProperty("description")]
public string Description { get; set; }
}
9 changes: 9 additions & 0 deletions src/Discord.Net.Rest/DiscordRestApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,15 @@ public async Task<GuildOnboarding> GetGuildOnboardingAsync(ulong guildId, Reques
return await SendAsync<GuildOnboarding>("GET", () => $"guilds/{guildId}/onboarding", new BucketIds(guildId: guildId), options: options);
}

public async Task<GuildOnboarding> ModifyGuildOnboardingAsync(ulong guildId, ModifyGuildOnboardingParams args, RequestOptions options)
{
Preconditions.NotEqual(guildId, 0, nameof(guildId));

options = RequestOptions.CreateOrClone(options);

return await SendJsonAsync<GuildOnboarding>("PUT", () => $"guilds/{guildId}/onboarding", args, new BucketIds(guildId: guildId), options: options);
}

#endregion

#region Users
Expand Down
Loading