From 7bc2be1498ab81bc8aacb7467699b72dfd95bdef Mon Sep 17 00:00:00 2001 From: samhza Date: Fri, 25 Jun 2021 15:29:14 -0400 Subject: [PATCH] api: Add search endpoint (#236) Co-authored-by: Terra Brown --- api/search.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 api/search.go diff --git a/api/search.go b/api/search.go new file mode 100644 index 0000000..96a025d --- /dev/null +++ b/api/search.go @@ -0,0 +1,37 @@ +package api + +import ( + "github.com/diamondburned/arikawa/v3/discord" + "github.com/diamondburned/arikawa/v3/utils/httputil" + "github.com/diamondburned/arikawa/v3/utils/json/option" +) + +type SearchData struct { + Offset option.Uint `schema:"offset,omitempty"` + Content string `schema:"content,omitempty"` + Has string `schema:"has,omitempty"` + SortBy string `schema:"sort_by,omitempty"` + SortOrder string `schema:"sort_order,omitempty"` + ChannelID discord.ChannelID `schema:"channel_id,omitempty"` + AuthorID discord.UserID `schema:"author_id,omitempty"` + Mentions discord.UserID `schema:"mentions,omitempty"` + MaxID discord.MessageID `schema:"max_id,omitempty"` + MinID discord.MessageID `schema:"min_id,omitempty"` +} + +type SearchResponse struct { + AnalyticsID string `json:"analytics_id"` + Messages [][]discord.Message `json:"messages"` + TotalResults uint `json:"total_results"` +} + +// Search searches through a guild's messages. It only works for user accounts. +func (c *Client) Search(guildID discord.GuildID, data SearchData) (SearchResponse, error) { + var resp SearchResponse + + return resp, c.RequestJSON( + &resp, "GET", + EndpointGuilds+guildID.String()+"/messages/search", + httputil.WithSchema(c, data), + ) +}