macro_rules! impl_event { ($name:ident; $first:expr, $second:ident) => { impl Event for $name { fn get_event_data(self) -> (String, String) { ($first.into(), self.$second.to_string()) } } } } macro_rules! impl_true_event { ($name:ident; $first:expr) => { impl Event for $name { fn get_event_data(self) -> (String, String) { ($first.into(), "true".to_string()) } } } } /// Your structs have to implement this in order to be accepted by `client.send_event`. pub trait Event { /// A function returning a tuple containing the event name as used by analyticord and a comma ///separated list of data. fn get_event_data(self) -> (String, String); } /// Struct representing `messages` event. #[derive(Debug)] pub struct Messages { /// The amount of messages you received since the last Messages event sent. pub amount: usize, } /// Struct representing `guildLeave` event. #[derive(Debug)] pub struct GuildLeave {} /// Struct representing `error` event. #[derive(Debug)] pub struct Error { /// Your custom error message you want to submit. pub message: String, } /// Struct representing `disconnect` event. #[derive(Debug)] pub struct Disconnect {} /// Struct representing `voiceChannelJoin` event. #[derive(Debug)] pub struct VoiceChannelJoin {} /// Struct representing `guildDetails` event. #[derive(Debug)] pub struct GuildDetails { /// The guild ID this event refers to. pub guild: String, /// The amount of users in said guild. pub user_count: usize, /// The amount of channels in said guild. pub channel_count: usize, } /// Struct representing `mentions` event. #[derive(Debug)] pub struct Mention {} /// Struct representing `commands_used` event. #[derive(Debug)] pub struct CommandUsed { /// The command used to trigger this event. pub command: String, } impl_event!(Error; "error", message); impl_event!(Messages; "messages", amount); impl_event!(CommandUsed; "commands_used", command); impl_true_event!(Mention; "mentions"); impl_true_event!(GuildLeave; "guildLeave"); impl_true_event!(Disconnect; "disconnect"); impl_true_event!(VoiceChannelJoin; "voiceChannelJoin"); #[cfg(test)] mod test { use super::*; #[test] fn error() { assert_eq!( Error { message: "e".into(), }.get_event_data(), ("error".into(), "e".into()) ); } #[test] fn messages() { assert_eq!( Messages { amount: 10 }.get_event_data(), ("messages".into(), "10".into()) ); } #[test] fn command_used() { assert_eq!( CommandUsed { command: "c".into(), }.get_event_data(), ("commands_used".into(), "c".into()) ); } #[test] fn mention() { assert_eq!( Mention {}.get_event_data(), ("mentions".into(), "true".into()) ); } #[test] fn guild_leave() { assert_eq!( GuildLeave {}.get_event_data(), ("guildLeave".into(), "true".into()) ); } #[test] fn disconnect() { assert_eq!( Disconnect {}.get_event_data(), ("disconnect".into(), "true".into()) ); } #[test] fn voice_channel_join() { assert_eq!( VoiceChannelJoin {}.get_event_data(), ("voiceChannelJoin".into(), "true".into()) ); } }