use disruption_types::channel::{MessageApiType, MessageReferenceApiType};
use crate::{implementations::channel::Channel, internal::RestClient, Result};
#[derive(Debug, Clone)]
pub struct Message {
rest: RestClient,
msg: MessageApiType,
channel: Option<Channel>,
}
impl Message {
pub async fn new(rest: RestClient, msg: MessageApiType) -> Self {
let channel = Channel::from_id(rest.clone(), &msg.channel_id).await;
Message {
rest,
msg,
channel: channel.ok(),
}
}
pub fn content(&self) -> &str {
self.msg.content.as_str()
}
pub fn author(&self) -> &str {
self.msg.author.username.as_str()
}
pub fn channel(&self) -> &Option<Channel> {
&self.channel
}
pub async fn reply(&self, content: &str) -> Result<()> {
match self.channel() {
None => (),
Some(channel) => {
channel
.send(MessageApiType {
content: content.to_owned(),
message_reference: Some(MessageReferenceApiType {
message_id: Some(self.msg.id.clone()),
..Default::default()
}),
..Default::default()
})
.await?;
}
}
Ok(())
}
}