fn parse_json_to_command(bot_name: &str, json_str: &str) -> Option<UserCommand> {
        let data: Value = serde_json::from_str(json_str).unwrap();
        let message = data.as_object().unwrap();

        if let Some(&Value::String(ref ty)) = message.get("type") {
            if ty == "message" {
                if let Some(&Value::String(ref text)) = message.get("text") {
                    let bang_command = "!".to_owned() + bot_name;
                    if text.starts_with(&bang_command[..]) {
                        let mut command_pieces = text.split_whitespace().skip(1);
                        let (command, args) = match command_pieces.next() {
                            Some(c) => (c, command_pieces.map(|arg| arg.to_owned()).collect::<Vec<_>>()),
                            None => ("help", vec![])
                        };

                        if let Some(&Value::String(ref user_id)) = message.get("user") {
                            if let Some(&Value::String(ref channel)) = message.get("channel") {
                                return Some(UserCommand {
                                    command: command.to_owned(),
                                    args: args,
                                    user_id: user_id.to_owned(),
                                    channel: channel.to_owned()
                                });
                            }
                        }
                    }
                }
            }
        }
        None
    }
// TODO: Replace lots of this with proper serde deserialization
Replace lots of this with proper serde deserialization
Replace lots of this with proper serde deserialization
fn parse_json_to_command(bot_name: &str, json_str: &str) -> Option<UserCommand> {
        let data: Value = serde_json::from_str(json_str).unwrap();
        let message = data.as_object().unwrap();
        if let Some(&Value::String(ref ty)) = message.get("type") {
            if ty == "message" {
                if let Some(&Value::String(ref text)) = message.get("text") {
                    let bang_command = "!".to_owned() + bot_name;
                    if text.starts_with(&bang_command[..]) {
                        let mut command_pieces = text.split_whitespace().skip(1);
                        let (command, args) = match command_pieces.next() {
                            Some(c) => (c, command_pieces.map(|arg| arg.to_owned()).collect::<Vec<_>>()),
                            None => ("help", vec![])
                        };
                        if let Some(&Value::String(ref user_id)) = message.get("user") {
                            if let Some(&Value::String(ref channel)) = message.get("channel") {
                                return Some(UserCommand {
                                    command: command.to_owned(),
                                    args: args,
                                    user_id: user_id.to_owned(),
                                    channel: channel.to_owned()
                                });
                            }
                        }
                    }
                }
            }
        }
        None
    }
fn parse_json_to_command ( bot_name : & str , json_str : & str ) -> Option < UserCommand > { let data : Value = serde_json :: from_str ( json_str ) . unwrap ( ) ; let message = data . as_object ( ) . unwrap ( ) ; if let Some ( & Value :: String ( ref ty ) ) = message . get ( " " ) { if ty == " " { if let Some ( & Value :: String ( ref text ) ) = message . get ( " " ) { let bang_command = " " . to_owned ( ) + bot_name ; if text . starts_with ( & bang_command [ .. ] ) { let mut command_pieces = text . split_whitespace ( ) . skip ( 1 ) ; let ( command , args ) = match command_pieces . next ( ) { Some ( c ) => ( c , command_pieces . map ( | arg | arg . to_owned ( ) ) . collect :: < Vec < _ > > ( ) ) , None => ( " " , vec ! [ ] ) } ; if let Some ( & Value :: String ( ref user_id ) ) = message . get ( " " ) { if let Some ( & Value :: String ( ref channel ) ) = message . get ( " " ) { return Some ( UserCommand { command : command . to_owned ( ) , args : args , user_id : user_id . to_owned ( ) , channel : channel . to_owned ( ) } ) ; } } } } } } None }
TODO: Replace lots of this with proper serde deserialization
TODO : Replace lots of this with proper serde deserialization
bot_name
&str
json_str
&str
bot_name
&str
json_str
&str