|
|
@ -215,7 +215,7 @@ public class DiscordClient
|
|
|
|
|
|
|
|
|
|
|
|
var channelsJson = response
|
|
|
|
var channelsJson = response
|
|
|
|
.EnumerateArray()
|
|
|
|
.EnumerateArray()
|
|
|
|
.OrderBy(c => c.GetProperty("position").GetInt32())
|
|
|
|
.OrderBy(j => j.GetProperty("position").GetInt32())
|
|
|
|
.ThenBy(j => j.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse))
|
|
|
|
.ThenBy(j => j.GetProperty("id").GetNonWhiteSpaceString().Pipe(Snowflake.Parse))
|
|
|
|
.ToArray();
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
|
@ -349,7 +349,7 @@ public class DiscordClient
|
|
|
|
return response?.Pipe(j => Member.Parse(j, guildId));
|
|
|
|
return response?.Pipe(j => Member.Parse(j, guildId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async ValueTask<Invite?> TryGetGuildInviteAsync(
|
|
|
|
public async ValueTask<Invite?> TryGetInviteAsync(
|
|
|
|
string code,
|
|
|
|
string code,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -357,33 +357,24 @@ public class DiscordClient
|
|
|
|
return response?.Pipe(Invite.Parse);
|
|
|
|
return response?.Pipe(Invite.Parse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async ValueTask<Channel?> TryGetChannelAsync(
|
|
|
|
public async ValueTask<Channel> GetChannelAsync(
|
|
|
|
Snowflake channelId,
|
|
|
|
Snowflake channelId,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var response = await TryGetJsonResponseAsync($"channels/{channelId}", cancellationToken);
|
|
|
|
var response = await GetJsonResponseAsync($"channels/{channelId}", cancellationToken);
|
|
|
|
if (response is null)
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var parentId = response
|
|
|
|
var parentId = response
|
|
|
|
.Value
|
|
|
|
|
|
|
|
.GetPropertyOrNull("parent_id")?
|
|
|
|
.GetPropertyOrNull("parent_id")?
|
|
|
|
.GetNonWhiteSpaceStringOrNull()?
|
|
|
|
.GetNonWhiteSpaceStringOrNull()?
|
|
|
|
.Pipe(Snowflake.Parse);
|
|
|
|
.Pipe(Snowflake.Parse);
|
|
|
|
|
|
|
|
|
|
|
|
var parent = parentId is not null
|
|
|
|
var parent = parentId is not null
|
|
|
|
? await TryGetChannelAsync(parentId.Value, cancellationToken)
|
|
|
|
? await GetChannelAsync(parentId.Value, cancellationToken)
|
|
|
|
: null;
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
|
|
return Channel.Parse(response.Value, parent);
|
|
|
|
return Channel.Parse(response, parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async ValueTask<Channel> GetChannelAsync(
|
|
|
|
|
|
|
|
Snowflake channelId,
|
|
|
|
|
|
|
|
CancellationToken cancellationToken = default) =>
|
|
|
|
|
|
|
|
await TryGetChannelAsync(channelId, cancellationToken) ??
|
|
|
|
|
|
|
|
throw new InvalidOperationException($"Channel {channelId} not found.");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async ValueTask<Message?> TryGetLastMessageAsync(
|
|
|
|
private async ValueTask<Message?> TryGetLastMessageAsync(
|
|
|
|
Snowflake channelId,
|
|
|
|
Snowflake channelId,
|
|
|
|
Snowflake? before = null,
|
|
|
|
Snowflake? before = null,
|
|
|
|