Adds a message_type field to MessageFromIRC.

The `message_type` allows switching to `notice` type messages.

It defaults to `privmsg` and any other (string) values will have the
same effect than using `privmsg`.

No code should need to be updated after this change.
This commit is contained in:
Samuel Dionne-Riel 2018-02-08 22:36:42 -05:00
parent 29b5035fdf
commit 23081ad5d5

View file

@ -30,7 +30,9 @@ use std::env;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
struct MessageToIRC { struct MessageToIRC {
target: String, target: String,
body: String body: String,
#[serde(default = "default_irc_message_type")]
message_type: String
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@ -40,6 +42,10 @@ struct MessageFromIRC {
body: String body: String
} }
fn default_irc_message_type() -> String {
"privmsg".to_string()
}
fn main() { fn main() {
if let Err(_) = env::var("RUST_LOG") { if let Err(_) = env::var("RUST_LOG") {
env::set_var("RUST_LOG", "info"); env::set_var("RUST_LOG", "info");
@ -81,7 +87,12 @@ fn main() {
move |_channel: &mut Channel, _deliver: Deliver, _headers: BasicProperties, body: Vec<u8>| { move |_channel: &mut Channel, _deliver: Deliver, _headers: BasicProperties, body: Vec<u8>| {
let msg: Result<MessageToIRC, serde_json::Error> = serde_json::from_slice(&body); let msg: Result<MessageToIRC, serde_json::Error> = serde_json::from_slice(&body);
if let Ok(msg) = msg { if let Ok(msg) = msg {
server.send_privmsg(&msg.target, &msg.body).unwrap(); if &msg.message_type == "notice" {
server.send_notice(&msg.target, &msg.body).unwrap();
}
else {
server.send_privmsg(&msg.target, &msg.body).unwrap();
}
} }
}, },
"queue-publish", "", false, true, false, false, Table::new()); "queue-publish", "", false, true, false, false, Table::new());