Updated command parser

This commit is contained in:
famfo 2022-01-12 20:56:10 +01:00
parent f336537670
commit e416d161bb

View file

@ -230,9 +230,7 @@ impl Command {
let parts: Vec<&str> = new.split_whitespace().collect();
if parts.get(0) == Some(&"PING") {
let command = parts[1].to_string();
return Self::PING(command);
return Self::PING(parts[1].to_string());
}
match parts.get(1) {
@ -243,7 +241,7 @@ impl Command {
let index = nick_realname.chars().position(|c| c == '!');
if let Some(index) = index {
if index > 0 {
nick = String::from(&nick_realname[1..index]);
nick = (nick_realname[1..index]).to_string();
} else {
nick = String::new();
}
@ -251,34 +249,24 @@ impl Command {
nick = String::new();
}
let target = parts[2];
let msg = parts[3..].join(" ");
Self::PRIVMSG(nick, target.to_string(), (msg[1..]).to_string())
Self::PRIVMSG(nick, parts[2].to_string(), (msg[1..]).to_string())
}
Some(&"331") | Some(&"332") => {
let channel = parts[3];
let topic = parts[4..].join(" ");
Self::TOPIC(channel.to_string(), (topic[1..]).to_string())
Self::TOPIC(parts[3].to_string(), (topic[1..]).to_string())
}
Some(&"333") => {
let user = parts[4];
let time = parts[5];
Self::TOPIC_BY(user.to_string(), time.to_string())
Self::TOPIC_BY(parts[4].to_string(), parts[5].to_string())
}
Some(&"353") => {
let channel = parts[4];
let user = parts[5..].join(" ");
Self::NAMES(channel.to_string(), (user[1..]).to_string())
Self::NAMES(parts[4].to_string(), (user[1..]).to_string())
}
Some(&"PONG") => {
let pong = parts[2];
let server = parts[3];
Self::PONG(pong.to_string(), (server[1..]).to_string())
Self::PONG(parts[2].to_string(), (server[1..]).to_string())
}
_ => Self::OTHER(new.to_string()),
}