diff --git a/ircbot/src/bin/gateway.rs b/ircbot/src/bin/gateway.rs index 8e10135..18fef10 100644 --- a/ircbot/src/bin/gateway.rs +++ b/ircbot/src/bin/gateway.rs @@ -32,7 +32,7 @@ struct MessageToIRC { target: String, body: String, #[serde(default = "default_irc_message_type")] - message_type: String + message_type: IRCMessageType } #[derive(Serialize, Deserialize, Debug)] @@ -42,8 +42,15 @@ struct MessageFromIRC { body: String } -fn default_irc_message_type() -> String { - "privmsg".to_string() +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "lowercase")] +enum IRCMessageType { + Privmsg, + Notice +} + +fn default_irc_message_type() -> IRCMessageType { + IRCMessageType::Privmsg } fn main() { @@ -87,11 +94,13 @@ fn main() { move |_channel: &mut Channel, _deliver: Deliver, _headers: BasicProperties, body: Vec| { let msg: Result = serde_json::from_slice(&body); if let Ok(msg) = msg { - if &msg.message_type == "notice" { - server.send_notice(&msg.target, &msg.body).unwrap(); - } - else { - server.send_privmsg(&msg.target, &msg.body).unwrap(); + match msg.message_type { + IRCMessageType::Notice => { + server.send_notice(&msg.target, &msg.body).unwrap(); + } + IRCMessageType::Privmsg => { + server.send_privmsg(&msg.target, &msg.body).unwrap(); + } } } },