Changes message_type to an Enum.
This commit is contained in:
parent
23081ad5d5
commit
bb406624d8
|
@ -32,7 +32,7 @@ struct MessageToIRC {
|
||||||
target: String,
|
target: String,
|
||||||
body: String,
|
body: String,
|
||||||
#[serde(default = "default_irc_message_type")]
|
#[serde(default = "default_irc_message_type")]
|
||||||
message_type: String
|
message_type: IRCMessageType
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
@ -42,8 +42,15 @@ struct MessageFromIRC {
|
||||||
body: String
|
body: String
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_irc_message_type() -> String {
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
"privmsg".to_string()
|
#[serde(rename_all = "lowercase")]
|
||||||
|
enum IRCMessageType {
|
||||||
|
Privmsg,
|
||||||
|
Notice
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_irc_message_type() -> IRCMessageType {
|
||||||
|
IRCMessageType::Privmsg
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -87,13 +94,15 @@ 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 {
|
||||||
if &msg.message_type == "notice" {
|
match msg.message_type {
|
||||||
|
IRCMessageType::Notice => {
|
||||||
server.send_notice(&msg.target, &msg.body).unwrap();
|
server.send_notice(&msg.target, &msg.body).unwrap();
|
||||||
}
|
}
|
||||||
else {
|
IRCMessageType::Privmsg => {
|
||||||
server.send_privmsg(&msg.target, &msg.body).unwrap();
|
server.send_privmsg(&msg.target, &msg.body).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"queue-publish", "", false, true, false, false, Table::new());
|
"queue-publish", "", false, true, false, false, Table::new());
|
||||||
println!("Starting consumer {:?}", consumer_name);
|
println!("Starting consumer {:?}", consumer_name);
|
||||||
|
|
Loading…
Reference in a new issue