use internal::prelude::*;
use model::channel::ReactionType;
use std::fmt::Display;
use super::CreateEmbed;
use utils::{self, VecMap};
#[derive(Clone, Debug)]
pub struct CreateMessage(pub VecMap<&'static str, Value>, pub Option<Vec<ReactionType>>);
impl CreateMessage {
#[inline]
pub fn content<D: Display>(self, content: D) -> Self {
self._content(content.to_string())
}
fn _content(mut self, content: String) -> Self {
self.0.insert("content", Value::String(content));
self
}
pub fn embed<F>(mut self, f: F) -> Self
where F: FnOnce(CreateEmbed) -> CreateEmbed {
let map = utils::vecmap_to_json_map(f(CreateEmbed::default()).0);
let embed = Value::Object(map);
self.0.insert("embed", embed);
self
}
pub fn tts(mut self, tts: bool) -> Self {
self.0.insert("tts", Value::Bool(tts));
self
}
#[inline]
pub fn reactions<R: Into<ReactionType>, It: IntoIterator<Item=R>>(self, reactions: It) -> Self {
self._reactions(reactions.into_iter().map(Into::into).collect())
}
fn _reactions(mut self, reactions: Vec<ReactionType>) -> Self {
self.1 = Some(reactions);
self
}
}
impl Default for CreateMessage {
fn default() -> CreateMessage {
let mut map = VecMap::new();
map.insert("tts", Value::Bool(false));
CreateMessage(map, None)
}
}