@@ -40,4 +40,17 @@ public class WelcomeScreenChannel : ISnowflakeEntity | |||||
Emoji = null; | Emoji = null; | ||||
} | } | ||||
/// <summary> | |||||
/// Initializes a new instance of <see cref="WelcomeScreenChannel"/> to be used to modify one. | |||||
/// </summary> | |||||
/// <param name="id"></param> | |||||
/// <param name="description"></param> | |||||
/// <param name="emoji"></param> | |||||
public WelcomeScreenChannel(ulong id, string description, IEmote emoji) | |||||
{ | |||||
Id = id; | |||||
Description = description; | |||||
Emoji = emoji; | |||||
} | |||||
} | } |
@@ -0,0 +1,17 @@ | |||||
using Newtonsoft.Json; | |||||
namespace Discord.API.Rest; | |||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||||
internal class ModifyGuildWelcomeScreenParams | |||||
{ | |||||
[JsonProperty("enabled")] | |||||
public Optional<bool> Enabled { get; set; } | |||||
[JsonProperty("welcome_channels")] | |||||
public Optional<WelcomeScreenChannel> Channels { get; set; } | |||||
[JsonProperty("description")] | |||||
public Optional<string> Description { get; set; } | |||||
} |
@@ -1589,18 +1589,6 @@ namespace Discord.API | |||||
var ids = new BucketIds(guildId: guildId); | var ids = new BucketIds(guildId: guildId); | ||||
return await SendAsync<GetGuildPruneCountResponse>("GET", () => $"guilds/{guildId}/prune?days={args.Days}{endpointRoleIds}", ids, options: options).ConfigureAwait(false); | return await SendAsync<GetGuildPruneCountResponse>("GET", () => $"guilds/{guildId}/prune?days={args.Days}{endpointRoleIds}", ids, options: options).ConfigureAwait(false); | ||||
} | } | ||||
public async Task<WelcomeScreen> GetGuildWelcomeScreenAsync(ulong guildId, RequestOptions options = null) | |||||
{ | |||||
Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||||
options = RequestOptions.CreateOrClone(options); | |||||
try | |||||
{ | |||||
var ids = new BucketIds(guildId: guildId); | |||||
return await SendAsync<WelcomeScreen>("GET", () => $"guilds/{guildId}/welcome-screen", ids, options: options).ConfigureAwait(false); | |||||
} | |||||
catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } | |||||
} | |||||
#endregion | #endregion | ||||
#region Guild Bans | #region Guild Bans | ||||
@@ -2109,6 +2097,35 @@ namespace Discord.API | |||||
#endregion | #endregion | ||||
#region Guild Welcome Screen | |||||
public async Task<WelcomeScreen> GetGuildWelcomeScreenAsync(ulong guildId, RequestOptions options = null) | |||||
{ | |||||
Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||||
options = RequestOptions.CreateOrClone(options); | |||||
try | |||||
{ | |||||
var ids = new BucketIds(guildId: guildId); | |||||
return await SendAsync<WelcomeScreen>("GET", () => $"guilds/{guildId}/welcome-screen", ids, options: options).ConfigureAwait(false); | |||||
} | |||||
catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } | |||||
} | |||||
public async Task<WelcomeScreen> ModifyGuildWelcomeScreenAsync(ModifyGuildWelcomeScreenParams args, ulong guildId, RequestOptions options = null) | |||||
{ | |||||
Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||||
Preconditions.NotNull(args, nameof(args)); | |||||
options = RequestOptions.CreateOrClone(options); | |||||
var ids = new BucketIds(guildId: guildId); | |||||
return await SendJsonAsync<WelcomeScreen>("PATCH", () => $"guilds/{guildId}/welcome-screen", args, ids, options: options).ConfigureAwait(false); | |||||
} | |||||
#endregion | |||||
#region Users | #region Users | ||||
public async Task<User> GetUserAsync(ulong userId, RequestOptions options = null) | public async Task<User> GetUserAsync(ulong userId, RequestOptions options = null) | ||||
{ | { | ||||
@@ -393,16 +393,6 @@ namespace Discord.Rest | |||||
return RestInviteMetadata.Create(client, guild, null, inviteModel); | return RestInviteMetadata.Create(client, guild, null, inviteModel); | ||||
} | } | ||||
public static async Task<WelcomeScreen> GetWelcomeScreenAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) | |||||
{ | |||||
var model = await client.ApiClient.GetGuildWelcomeScreenAsync(guild.Id, options); | |||||
return new WelcomeScreen(model.Description.GetValueOrDefault(null), model.WelcomeChannels.Select( | |||||
x => new WelcomeScreenChannel( | |||||
x.ChannelId, x.Description, | |||||
x.EmojiName.GetValueOrDefault(null), | |||||
x.EmojiId.GetValueOrDefault(0))).ToList()); | |||||
} | |||||
#endregion | #endregion | ||||
#region Roles | #region Roles | ||||
@@ -954,5 +944,31 @@ namespace Discord.Rest | |||||
} | } | ||||
#endregion | #endregion | ||||
#region Welcome Screen | |||||
public static async Task<WelcomeScreen> GetWelcomeScreenAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) | |||||
{ | |||||
var model = await client.ApiClient.GetGuildWelcomeScreenAsync(guild.Id, options); | |||||
return new WelcomeScreen(model.Description.GetValueOrDefault(null), model.WelcomeChannels.Select( | |||||
x => new WelcomeScreenChannel( | |||||
x.ChannelId, x.Description, | |||||
x.EmojiName.GetValueOrDefault(null), | |||||
x.EmojiId.GetValueOrDefault(0))).ToList()); | |||||
} | |||||
public static async Task<WelcomeScreen> ModifyWelcomeScreenAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) | |||||
{ | |||||
var model = await client.ApiClient.ModifyGuildWelcomeScreenAsync(null, guild.Id, options); | |||||
return new WelcomeScreen(model.Description.GetValueOrDefault(null), model.WelcomeChannels.Select( | |||||
x => new WelcomeScreenChannel( | |||||
x.ChannelId, x.Description, | |||||
x.EmojiName.GetValueOrDefault(null), | |||||
x.EmojiId.GetValueOrDefault(0))).ToList()); | |||||
} | |||||
#endregion | |||||
} | } | ||||
} | } |