Browse Source

more changes

pull/2510/head
Misha133 2 years ago
parent
commit
453c497c4c
4 changed files with 85 additions and 22 deletions
  1. +13
    -0
      src/Discord.Net.Core/Entities/Guilds/WelcomeScreenChannel.cs
  2. +17
    -0
      src/Discord.Net.Rest/API/Rest/ModifyGuildWelcomeScreenParams.cs
  3. +29
    -12
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  4. +26
    -10
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs

+ 13
- 0
src/Discord.Net.Core/Entities/Guilds/WelcomeScreenChannel.cs View File

@@ -40,4 +40,17 @@ public class WelcomeScreenChannel : ISnowflakeEntity
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;
}
}

+ 17
- 0
src/Discord.Net.Rest/API/Rest/ModifyGuildWelcomeScreenParams.cs View File

@@ -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; }
}

+ 29
- 12
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -1589,18 +1589,6 @@ namespace Discord.API
var ids = new BucketIds(guildId: guildId);
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

#region Guild Bans
@@ -2109,6 +2097,35 @@ namespace Discord.API

#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
public async Task<User> GetUserAsync(ulong userId, RequestOptions options = null)
{


+ 26
- 10
src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs View File

@@ -393,16 +393,6 @@ namespace Discord.Rest
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

#region Roles
@@ -954,5 +944,31 @@ namespace Discord.Rest
}

#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
}
}

Loading…
Cancel
Save