Skip to content

Commit

Permalink
Fix some mistakes, refactor some rest methods
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherZane committed Jul 30, 2024
1 parent 4096118 commit 5b532e5
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/Disqord.Bot/Bot/Base/Setup/DiscordBotBase.Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ protected virtual ValueTask AddTypeParsers(DefaultTypeParserProvider typeParserP
typeParserProvider.AddParser(new GuildChannelTypeParser<IStageChannel>());
typeParserProvider.AddParser(new GuildChannelTypeParser<IThreadChannel>());
typeParserProvider.AddParser(new GuildChannelTypeParser<IForumChannel>());
typeParserProvider.AddParser(new GuildChannelTypeParser<IMediaChannel>());
typeParserProvider.AddParser(new MemberTypeParser());
typeParserProvider.AddParser(new RoleTypeParser());
return default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Disqord;
/// <summary>
/// Represents a guild forum channel.
/// </summary>
public interface IForumChannel : IThreadParentChannel, ITopicChannel, ISlowmodeChannel
public interface IForumChannel : IMediaChannel
{
/// <summary>
/// Gets the default layout of posts in this channel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected TransientGuildChannel(IClient client, ChannelJsonModel model)
return new TransientForumChannel(client, model);

case ChannelType.Media:
return new TransientForumChannel(client, model);
return new TransientMediaChannel(client, model);
}

return new TransientUnknownGuildChannel(client, model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Disqord.Rest.Api;

public class CreateForumThreadJsonRestRequestContent : CreateThreadJsonRestRequestContent, IAttachmentRestRequestContent
public class CreateThreadPostJsonRestRequestContent : CreateThreadJsonRestRequestContent, IAttachmentRestRequestContent
{
[JsonProperty("message")]
public CreateMessageJsonRestRequestContent Message = null!;
Expand Down
12 changes: 6 additions & 6 deletions src/Disqord.Rest.Api/Methods/RestApiClientExtensions.Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,19 +278,19 @@ public static Task<ChannelJsonModel> CreateThreadAsync(this IRestApiClient clien
return client.ExecuteAsync<ChannelJsonModel>(route, content, options, cancellationToken);
}

public static Task<ChannelJsonModel> CreateForumThreadAsync(this IRestApiClient client,
Snowflake channelId, CreateForumThreadJsonRestRequestContent content,
public static Task<ChannelJsonModel> CreateThreadPostAsync(this IRestApiClient client,
Snowflake channelId, CreateThreadPostJsonRestRequestContent content,
IRestRequestOptions? options = null, CancellationToken cancellationToken = default)
{
var route = Format(Route.Channel.StartForumThread, channelId);
var route = Format(Route.Channel.CreateThreadPost, channelId);
return client.ExecuteAsync<ChannelJsonModel>(route, content, options, cancellationToken);
}

public static Task<ChannelJsonModel> CreateForumThreadAsync(this IRestApiClient client,
Snowflake channelId, AttachmentJsonPayloadRestRequestContent<CreateForumThreadJsonRestRequestContent> content,
public static Task<ChannelJsonModel> CreateThreadPostAsync(this IRestApiClient client,
Snowflake channelId, AttachmentJsonPayloadRestRequestContent<CreateThreadPostJsonRestRequestContent> content,
IRestRequestOptions? options = null, CancellationToken cancellationToken = default)
{
var route = Format(Route.Channel.StartForumThread, channelId);
var route = Format(Route.Channel.CreateThreadPost, channelId);
return client.ExecuteAsync<ChannelJsonModel>(route, content, options, cancellationToken);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static class Channel

public static readonly Route StartThread = Post("channels/{0:channel_id}/threads");

public static readonly Route StartForumThread = Post("channels/{0:channel_id}/threads");
public static readonly Route CreateThreadPost = Post("channels/{0:channel_id}/threads");

public static readonly Route JoinThread = Put("channels/{0:channel_id}/thread-members/@me");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ public static Task<IThreadChannel> CreatePrivateThreadAsync(this ITextChannel ch
return client.CreatePrivateThreadAsync(channel.Id, name, action, options, cancellationToken);
}

public static Task<IThreadChannel> CreateThreadAsync(this IForumChannel channel,
public static Task<IThreadChannel> CreateThreadPostAsync(this IMediaChannel channel,
string name, LocalMessage message, Action<CreateThreadChannelActionProperties>? action = null,
IRestRequestOptions? options = null, CancellationToken cancellationToken = default)
{
var client = channel.GetRestClient();
return client.CreateForumThreadAsync(channel.Id, name, message, action, options, cancellationToken);
return client.CreateThreadPostAsync(channel.Id, name, message, action, options, cancellationToken);
}

public static Task JoinAsync(this IThreadChannel thread,
Expand Down
10 changes: 5 additions & 5 deletions src/Disqord.Rest/Extensions/RestClientExtensions.Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ public static async Task<IThreadChannel> CreatePrivateThreadAsync(this IRestClie
return new TransientThreadChannel(client, model);
}

public static async Task<IThreadChannel> CreateForumThreadAsync(this IRestClient client,
public static async Task<IThreadChannel> CreateThreadPostAsync(this IRestClient client,
Snowflake channelId, string name, LocalMessage message, Action<CreateThreadChannelActionProperties>? action = null,
IRestRequestOptions? options = null, CancellationToken cancellationToken = default)
{
Expand All @@ -668,7 +668,7 @@ public static async Task<IThreadChannel> CreateForumThreadAsync(this IRestClient
EnforceNonce = message.ShouldEnforceNonce
};

var forumContent = new CreateForumThreadJsonRestRequestContent
var postContent = new CreateThreadPostJsonRestRequestContent
{
Name = name,
AutoArchiveDuration = Optional.Convert(properties.AutomaticArchiveDuration, x => (int) x.TotalMinutes),
Expand All @@ -682,12 +682,12 @@ public static async Task<IThreadChannel> CreateForumThreadAsync(this IRestClient
{
// If there are attachments, we must send them via multipart HTTP content.
// Our `messageContent` will be serialized into a "payload_json" form data field.
var content = new AttachmentJsonPayloadRestRequestContent<CreateForumThreadJsonRestRequestContent>(forumContent, attachments);
task = client.ApiClient.CreateForumThreadAsync(channelId, content, options, cancellationToken);
var content = new AttachmentJsonPayloadRestRequestContent<CreateThreadPostJsonRestRequestContent>(postContent, attachments);
task = client.ApiClient.CreateThreadPostAsync(channelId, content, options, cancellationToken);
}
else
{
task = client.ApiClient.CreateForumThreadAsync(channelId, forumContent, options, cancellationToken);
task = client.ApiClient.CreateThreadPostAsync(channelId, postContent, options, cancellationToken);
}

var model = await task.ConfigureAwait(false);
Expand Down

0 comments on commit 5b532e5

Please sign in to comment.