use crate::model::prelude::*;
use chrono::{DateTime, Utc};
use serde_json::Value;
#[derive(Debug, Clone)]
pub struct CustomMessage {
msg: Message,
}
impl CustomMessage {
#[inline]
pub fn new() -> Self {
Self::default()
}
#[inline]
pub fn id(&mut self, id: MessageId) -> &mut Self {
self.msg.id = id;
self
}
#[inline]
pub fn attachments<It>(&mut self, attachments: It) -> &mut Self
where
It: IntoIterator<Item = Attachment>,
{
self.msg.attachments = attachments.into_iter().collect();
self
}
#[inline]
pub fn author(&mut self, user: User) -> &mut Self {
self.msg.author = user;
self
}
#[inline]
pub fn channel_id(&mut self, channel_id: ChannelId) -> &mut Self {
self.msg.channel_id = channel_id;
self
}
#[inline]
pub fn content<T: ToString>(&mut self, s: T) -> &mut Self {
self.msg.content = s.to_string();
self
}
#[inline]
pub fn edited_timestamp(&mut self, timestamp: DateTime<Utc>) -> &mut Self {
self.msg.edited_timestamp = Some(timestamp);
self
}
#[inline]
pub fn embeds<It>(&mut self, embeds: It) -> &mut Self
where
It: IntoIterator<Item = Embed>,
{
self.msg.embeds = embeds.into_iter().collect();
self
}
#[inline]
pub fn guild_id(&mut self, guild_id: GuildId) -> &mut Self {
self.msg.guild_id = Some(guild_id);
self
}
#[inline]
pub fn kind(&mut self, kind: MessageType) -> &mut Self {
self.msg.kind = kind;
self
}
#[inline]
pub fn member(&mut self, member: PartialMember) -> &mut Self {
self.msg.member = Some(member);
self
}
#[inline]
pub fn mention_everyone(&mut self, mentions: bool) -> &mut Self {
self.msg.mention_everyone = mentions;
self
}
#[inline]
pub fn mention_roles<It>(&mut self, roles: It) -> &mut Self
where
It: IntoIterator<Item = RoleId>,
{
self.msg.mention_roles = roles.into_iter().collect();
self
}
#[inline]
pub fn mentions<It>(&mut self, mentions: It) -> &mut Self
where
It: IntoIterator<Item = User>,
{
self.msg.mentions = mentions.into_iter().collect();
self
}
#[inline]
pub fn pinned(&mut self, pinned: bool) -> &mut Self {
self.msg.pinned = pinned;
self
}
#[inline]
pub fn reactions<It>(&mut self, reactions: It) -> &mut Self
where
It: IntoIterator<Item = MessageReaction>,
{
self.msg.reactions = reactions.into_iter().collect();
self
}
#[inline]
pub fn timestamp(&mut self, timestamp: DateTime<Utc>) -> &mut Self {
self.msg.timestamp = timestamp;
self
}
#[inline]
pub fn tts(&mut self, tts: bool) -> &mut Self {
self.msg.tts = tts;
self
}
#[inline]
pub fn webhook_id(&mut self, id: WebhookId) -> &mut Self {
self.msg.webhook_id = Some(id);
self
}
#[inline]
pub fn build(self) -> Message {
self.msg
}
}
impl Default for CustomMessage {
#[inline]
fn default() -> Self {
CustomMessage {
msg: dummy_message(),
}
}
}
#[inline]
fn dummy_message() -> Message {
Message {
id: MessageId::default(),
attachments: Vec::new(),
author: User {
id: UserId::default(),
avatar: None,
bot: false,
discriminator: 0x0000,
name: String::new(),
_nonexhaustive: (),
},
channel_id: ChannelId::default(),
content: String::new(),
edited_timestamp: None,
embeds: Vec::new(),
guild_id: None,
kind: MessageType::Regular,
member: None,
mention_everyone: false,
mention_roles: Vec::new(),
mention_channels: Vec::new(),
mentions: Vec::new(),
nonce: Value::Null,
pinned: false,
reactions: Vec::new(),
tts: false,
webhook_id: None,
timestamp: Utc::now(),
activity: None,
application: None,
message_reference: None,
flags: None,
_nonexhaustive: (),
}
}