use crate::{
error::Result,
http::HttpClient,
models::{guild::GuildMember, user::User},
};
use super::Embed;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct Message {
id: String,
channel_id: String,
guild_id: Option<String>,
author: User,
member: Option<GuildMember>,
content: String,
timestamp: String,
edited_timestamp: Option<String>,
tts: bool,
mention_everyone: bool,
mentions: Vec<User>,
mention_roles: Vec<String>,
#[serde(default)]
embed: Vec<Embed>,
nonce: Option<String>,
pinned: bool,
webhook_id: Option<String>,
#[serde(rename = "type")]
kind: Option<u64>, flags: Option<u64>,
}
impl Message {
pub fn id(&self) -> &str {
&self.id
}
pub fn channel_id(&self) -> &str {
&self.channel_id
}
pub fn guild_id(&self) -> Option<&str> {
self.guild_id.as_ref().map(|s| s.as_str())
}
pub fn author(&self) -> &User {
&self.author
}
pub fn member(&self) -> Option<&GuildMember> {
self.member.as_ref()
}
pub fn content(&self) -> &str {
&self.content
}
pub fn timestamp(&self) -> &str {
&self.timestamp
}
pub fn edited_timestamp(&self) -> Option<&str> {
self.edited_timestamp.as_ref().map(|v| v.as_str())
}
pub fn tts(&self) -> bool {
self.tts
}
pub fn mention_everyone(&self) -> bool {
self.mention_everyone
}
pub fn mentions(&self) -> &[User] {
&self.mentions
}
pub fn mention_roles(&self) -> &[String] {
&self.mention_roles
}
pub fn embed(&self) -> &[Embed] {
&self.embed
}
pub fn nonce(&self) -> Option<&str> {
self.nonce.as_ref().map(|s| s.as_str())
}
pub fn pinned(&self) -> bool {
self.pinned
}
pub fn webhook_id(&self) -> Option<&str> {
self.webhook_id.as_ref().map(|v| v.as_str())
}
pub fn kind(&self) -> Option<u64> {
self.kind
}
pub fn flags(&self) -> Option<u64> {
self.flags
}
pub async fn send_message(&self, http: &HttpClient, content: impl AsRef<str>) -> Result<Message> {
http.send_message(self.channel_id(), content).await
}
pub async fn send_embed(&self, http: &HttpClient, embed: super::Embed) -> Result<Message> {
http.send_embed(self.channel_id(), embed).await
}
}