Onboarding updates (#2729)
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
|
||||
@@ -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
src/Discord.Net.Rest/API/Rest/ModifyGuildOnboardingParams.cs
Normal file
71
src/Discord.Net.Rest/API/Rest/ModifyGuildOnboardingParams.cs
Normal file
@@ -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; }
|
||||
}
|
||||
@@ -2252,6 +2252,15 @@ namespace Discord.API
|
||||
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
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
using Discord.API;
|
||||
using Discord.API.Rest;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ImageModel = Discord.API.Image;
|
||||
using Model = Discord.API.Guild;
|
||||
using RoleModel = Discord.API.Role;
|
||||
@@ -757,7 +759,7 @@ namespace Discord.Rest
|
||||
Preconditions.AtLeast(description.Length, 2, nameof(description));
|
||||
Preconditions.AtMost(description.Length, 100, nameof(description));
|
||||
}
|
||||
|
||||
|
||||
var tagString = string.Join(", ", tags);
|
||||
|
||||
Preconditions.AtLeast(tagString.Length, 1, nameof(tags));
|
||||
@@ -1125,7 +1127,7 @@ namespace Discord.Rest
|
||||
}
|
||||
|
||||
if (args.TriggerType.Value is AutoModTriggerType.Keyword)
|
||||
Preconditions.AtLeast(args.KeywordFilter.GetValueOrDefault(Array.Empty<string>()).Length + args.RegexPatterns.GetValueOrDefault(Array.Empty<string>()).Length, 1, "KeywordFilter & RegexPatterns","Auto moderation rule must have at least 1 keyword or regex pattern");
|
||||
Preconditions.AtLeast(args.KeywordFilter.GetValueOrDefault(Array.Empty<string>()).Length + args.RegexPatterns.GetValueOrDefault(Array.Empty<string>()).Length, 1, "KeywordFilter & RegexPatterns", "Auto moderation rule must have at least 1 keyword or regex pattern");
|
||||
|
||||
if (args.AllowList.IsSpecified)
|
||||
{
|
||||
@@ -1243,13 +1245,13 @@ namespace Discord.Rest
|
||||
|| args.MentionLimit.IsSpecified
|
||||
|| args.RegexPatterns.IsSpecified
|
||||
|| args.AllowList.IsSpecified ? new API.TriggerMetadata
|
||||
{
|
||||
KeywordFilter = args.KeywordFilter.IsSpecified ? args.KeywordFilter : rule.KeywordFilter.ToArray(),
|
||||
RegexPatterns = args.RegexPatterns.IsSpecified ? args.RegexPatterns : rule.RegexPatterns.ToArray(),
|
||||
AllowList = args.AllowList.IsSpecified ? args.AllowList : rule.AllowList.ToArray(),
|
||||
MentionLimit = args.MentionLimit.IsSpecified ? args.MentionLimit : rule.MentionTotalLimit ?? Optional<int>.Unspecified,
|
||||
Presets = args.Presets.IsSpecified ? args.Presets : rule.Presets.ToArray(),
|
||||
} : Optional<API.TriggerMetadata>.Unspecified
|
||||
{
|
||||
KeywordFilter = args.KeywordFilter.IsSpecified ? args.KeywordFilter : rule.KeywordFilter.ToArray(),
|
||||
RegexPatterns = args.RegexPatterns.IsSpecified ? args.RegexPatterns : rule.RegexPatterns.ToArray(),
|
||||
AllowList = args.AllowList.IsSpecified ? args.AllowList : rule.AllowList.ToArray(),
|
||||
MentionLimit = args.MentionLimit.IsSpecified ? args.MentionLimit : rule.MentionTotalLimit ?? Optional<int>.Unspecified,
|
||||
Presets = args.Presets.IsSpecified ? args.Presets : rule.Presets.ToArray(),
|
||||
} : Optional<API.TriggerMetadata>.Unspecified
|
||||
};
|
||||
|
||||
return client.ApiClient.ModifyGuildAutoModRuleAsync(rule.GuildId, rule.Id, apiArgs, options);
|
||||
@@ -1264,6 +1266,46 @@ namespace Discord.Rest
|
||||
public static async Task<GuildOnboarding> GetGuildOnboardingAsync(IGuild guild, BaseDiscordClient client, RequestOptions options)
|
||||
=> await client.ApiClient.GetGuildOnboardingAsync(guild.Id, options);
|
||||
|
||||
public static async Task<GuildOnboarding> ModifyGuildOnboardingAsync(IGuild guild, Action<GuildOnboardingProperties> func, BaseDiscordClient client, RequestOptions options)
|
||||
{
|
||||
var props = new GuildOnboardingProperties();
|
||||
func(props);
|
||||
|
||||
var args = new ModifyGuildOnboardingParams
|
||||
{
|
||||
DefaultChannelIds = props.ChannelIds.IsSpecified
|
||||
? props.ChannelIds.Value.ToArray()
|
||||
: Optional<ulong[]>.Unspecified,
|
||||
Enabled = props.IsEnabled,
|
||||
Mode = props.Mode,
|
||||
Prompts = props.Prompts.IsSpecified ? props.Prompts.Value?
|
||||
.Select(prompt => new GuildOnboardingPromptParams
|
||||
{
|
||||
Id = prompt.Id ?? 0,
|
||||
Type = prompt.Type,
|
||||
IsInOnboarding = prompt.IsInOnboarding,
|
||||
IsRequired = prompt.IsRequired,
|
||||
IsSingleSelect = prompt.IsSingleSelect,
|
||||
Title = prompt.Title,
|
||||
Options = prompt.Options?
|
||||
.Select(option => new GuildOnboardingPromptOptionParams
|
||||
{
|
||||
Title = option.Title,
|
||||
ChannelIds = option.ChannelIds?.ToArray(),
|
||||
RoleIds = option.RoleIds?.ToArray(),
|
||||
Description = option.Description,
|
||||
EmojiName = option.Emoji.GetValueOrDefault(null)?.Name,
|
||||
EmojiId = option.Emoji.GetValueOrDefault(null) is Emote emote ? emote.Id : null,
|
||||
EmojiAnimated = option.Emoji.GetValueOrDefault(null) is Emote emt ? emt.Animated : null,
|
||||
Id = option.Id ?? Optional<ulong>.Unspecified,
|
||||
}).ToArray(),
|
||||
}).ToArray()
|
||||
: Optional<GuildOnboardingPromptParams[]>.Unspecified,
|
||||
};
|
||||
|
||||
return await client.ApiClient.ModifyGuildOnboardingAsync(guild.Id, args, options);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.GuildOnboarding;
|
||||
|
||||
namespace Discord.Rest;
|
||||
@@ -9,6 +10,8 @@ namespace Discord.Rest;
|
||||
/// <inheritdoc />
|
||||
public class RestGuildOnboarding : IGuildOnboarding
|
||||
{
|
||||
internal BaseDiscordClient Discord;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ulong GuildId { get; private set; }
|
||||
|
||||
@@ -21,17 +24,38 @@ public class RestGuildOnboarding : IGuildOnboarding
|
||||
/// <inheritdoc />
|
||||
public bool IsEnabled { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public GuildOnboardingMode Mode { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsBelowRequirements { get; private set; }
|
||||
|
||||
/// <inheritdoc cref="IGuildOnboarding.Prompts"/>
|
||||
public IReadOnlyCollection<RestGuildOnboardingPrompt> Prompts { get; private set; }
|
||||
|
||||
internal RestGuildOnboarding(BaseDiscordClient discord, Model model, RestGuild guild = null)
|
||||
{
|
||||
Discord = discord;
|
||||
Guild = guild;
|
||||
Update(model);
|
||||
}
|
||||
|
||||
internal void Update(Model model)
|
||||
{
|
||||
GuildId = model.GuildId;
|
||||
DefaultChannelIds = model.DefaultChannelIds.ToImmutableArray();
|
||||
IsEnabled = model.Enabled;
|
||||
Mode = model.Mode;
|
||||
IsBelowRequirements = model.IsBelowRequirements;
|
||||
Prompts = model.Prompts.Select(prompt => new RestGuildOnboardingPrompt(Discord, prompt.Id, prompt)).ToImmutableArray();
|
||||
}
|
||||
|
||||
Guild = guild;
|
||||
Prompts = model.Prompts.Select(prompt => new RestGuildOnboardingPrompt(discord, prompt.Id, prompt)).ToImmutableArray();
|
||||
///<inheritdoc/>
|
||||
public async Task ModifyAsync(Action<GuildOnboardingProperties> props, RequestOptions options = null)
|
||||
{
|
||||
var model = await GuildHelper.ModifyGuildOnboardingAsync(Guild, props, Discord, options);
|
||||
|
||||
Update(model);
|
||||
}
|
||||
|
||||
#region IGuildOnboarding
|
||||
|
||||
@@ -32,7 +32,7 @@ public class RestGuildOnboardingPromptOption : RestEntity<ulong>, IGuildOnboardi
|
||||
ChannelIds = model.ChannelIds.ToImmutableArray();
|
||||
RoleIds = model.RoleIds.ToImmutableArray();
|
||||
Title = model.Title;
|
||||
Description = model.Description.IsSpecified ? model.Description.Value : null;
|
||||
Description = model.Description;
|
||||
|
||||
if (model.Emoji.Id.HasValue)
|
||||
{
|
||||
|
||||
@@ -1246,6 +1246,14 @@ namespace Discord.Rest
|
||||
return new RestGuildOnboarding(Discord, model, this);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IGuild.ModifyOnboardingAsync"/>
|
||||
public async Task<RestGuildOnboarding> ModifyOnboardingAsync(Action<GuildOnboardingProperties> props, RequestOptions options = null)
|
||||
{
|
||||
var model = await GuildHelper.ModifyGuildOnboardingAsync(this, props, Discord, options);
|
||||
|
||||
return new RestGuildOnboarding(Discord, model, this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IGuild
|
||||
@@ -1609,6 +1617,10 @@ namespace Discord.Rest
|
||||
async Task<IGuildOnboarding> IGuild.GetOnboardingAsync(RequestOptions options)
|
||||
=> await GetOnboardingAsync(options);
|
||||
|
||||
/// <inheritdoc/>
|
||||
async Task<IGuildOnboarding> IGuild.ModifyOnboardingAsync(Action<GuildOnboardingProperties> props, RequestOptions options)
|
||||
=> await ModifyOnboardingAsync(props, options);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user