mirror of
https://onedev.fprog.nl/DiscordClient
synced 2026-03-23 12:34:09 +01:00
Unified way of searching for messages.
This commit is contained in:
parent
6fc8a1bea8
commit
a147856013
|
|
@ -2,7 +2,7 @@ using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace DiscordClient.Data;
|
namespace DiscordClient.Data;
|
||||||
|
|
||||||
public class GuildMessageSearchResponse
|
public class MessageSearchResponse
|
||||||
{
|
{
|
||||||
[JsonPropertyName("total_results")]
|
[JsonPropertyName("total_results")]
|
||||||
public int TotalMessages { get; set; }
|
public int TotalMessages { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,14 @@ public class DiscordUserClient
|
||||||
|
|
||||||
public async Task<(
|
public async Task<(
|
||||||
HttpResponseMessage Response,
|
HttpResponseMessage Response,
|
||||||
ChannelMessagesResponse[]? JsonData
|
MessageSearchResponse? JsonData
|
||||||
)> GetChannelMessages(string channelId, int offset = 0, string? authorId = null, int limit = 50)
|
)> GetChannelMessages(string channelId, int offset = 0, string? authorId = null, int limit = 50)
|
||||||
{
|
{
|
||||||
string authorQuery = authorId is not null ? $"&author_id={authorId}" : "";
|
string authorQuery = authorId is not null ? $"&author_id={authorId}" : "";
|
||||||
string url =
|
string url =
|
||||||
$"https://discord.com/api/v9/channels/{channelId}/messages?limit={limit}&offset={offset}{authorQuery}";
|
$"https://discord.com/api/v9/channels/{channelId}/messages/search?limit={limit}&offset={offset}{authorQuery}";
|
||||||
HttpResponseMessage response = await _httpClient.GetAsync(url);
|
HttpResponseMessage response = await _httpClient.GetAsync(url);
|
||||||
return (response, await response.Content.ReadFromJsonAsync<ChannelMessagesResponse[]>());
|
return (response, await response.Content.ReadFromJsonAsync<MessageSearchResponse>());
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class MessageContent
|
sealed class MessageContent
|
||||||
|
|
@ -68,13 +68,13 @@ public class DiscordUserClient
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<(
|
public async Task<(
|
||||||
HttpResponseMessage Response,
|
HttpResponseMessage Response,
|
||||||
GuildMessageSearchResponse? JsonData
|
MessageSearchResponse? JsonData
|
||||||
)> SearchGuildMessages(string guildId, int offset, string? authorId = null)
|
)> SearchGuildMessages(string guildId, int offset, string? authorId = null)
|
||||||
{
|
{
|
||||||
string authorQuery = authorId is not null ? $"&author_id={authorId}" : "";
|
string authorQuery = authorId is not null ? $"&author_id={authorId}" : "";
|
||||||
string url =
|
string url =
|
||||||
$"https://discord.com/api/v9/guilds/{guildId}/messages/search?offset={offset}{authorQuery}";
|
$"https://discord.com/api/v9/guilds/{guildId}/messages/search?offset={offset}{authorQuery}";
|
||||||
HttpResponseMessage response = await _httpClient.GetAsync(url);
|
HttpResponseMessage response = await _httpClient.GetAsync(url);
|
||||||
return (response, await response.Content.ReadFromJsonAsync<GuildMessageSearchResponse>());
|
return (response, await response.Content.ReadFromJsonAsync<MessageSearchResponse>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue