From 1984f8c5daa8a7807425929e661e7da3cef3040c Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Tue, 22 Aug 2023 14:01:03 +0200 Subject: [PATCH] Add MessageSearchEndpoint Enum and MessageSearchQuery schema struct --- src/types/schema/message.rs | 51 ++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/types/schema/message.rs b/src/types/schema/message.rs index e1abdf7..94a5884 100644 --- a/src/types/schema/message.rs +++ b/src/types/schema/message.rs @@ -3,8 +3,9 @@ use serde::{Deserialize, Serialize}; use crate::types::entities::{ AllowedMention, Component, Embed, MessageReference, PartialDiscordFileAttachment, }; +use crate::types::Snowflake; -#[derive(Debug, Default, Deserialize, Serialize)] +#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq)] #[serde(rename_all = "snake_case")] pub struct MessageSendSchema { #[serde(rename = "type")] @@ -19,3 +20,51 @@ pub struct MessageSendSchema { pub sticker_ids: Option>, pub attachments: Option>, } + +pub enum MessageSearchEndpoint { + GuildChannel(Snowflake), + Channel(Snowflake), +} + +impl std::fmt::Display for MessageSearchEndpoint { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + MessageSearchEndpoint::Channel(id) => { + write!(f, "channels/{}", &id.to_string()) + } + MessageSearchEndpoint::GuildChannel(id) => { + write!(f, "guilds/{}", &id.to_string()) + } + } + } +} + +#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq, PartialOrd, Ord)] +/// Represents a Message Search Query JSON Body. +/// The `channel_id` field is not applicable when using the `GET /channels/{channel.id}/messages/search` endpoint. +/// +/// # Reference: +/// See +pub struct MessageSearchQuery { + attachment_extension: Option>, + attachment_filename: Option>, + author_id: Option>, + author_type: Option>, + channel_id: Option>, + command_id: Option>, + content: Option, + embed_provider: Option>, + embed_type: Option>, + has: Option>, + include_nsfw: Option, + limit: Option, + link_hostname: Option>, + max_id: Option, + mention_everyone: Option, + mentions: Option>, + min_id: Option, + offset: Option, + pinned: Option, + sort_by: Option, + sort_order: Option, +}