Updated command parser

This commit is contained in:
famfo 2022-01-11 18:50:44 +01:00
parent 041922dae8
commit f336537670
2 changed files with 3 additions and 3 deletions

View file

@ -219,12 +219,12 @@ pub enum Command {
}
impl Command {
/// Creates a Command from a `&str`. Currently only `[PING]` and `[PRIVMSG]` are supported.
/// Creates a Command from a `&str`. Currently `[PRIVMSG]` `[TOPIC]` `[NAMES]` and `[PONG]` are supported.
///
/// # Panics
/// This function will panic if the ``IRCd`` sends malformed messages. Please contact the
/// maintainer of your ``IRCd`` if this happens.
pub async fn command_from_str(s: &str) -> Self {
pub async fn command_from_str(s: String) -> Self {
let new = s.trim();
tracing::trace!("{}", new);
let parts: Vec<&str> = new.split_whitespace().collect();

View file

@ -216,7 +216,7 @@ impl Client {
/// Returns IO errors from the TcpStream.
pub async fn read(&mut self) -> Result<Option<commands::Command>, tokio::io::Error> {
if let Some(string) = self.read_string().await? {
let command = commands::Command::command_from_str(&string).await;
let command = commands::Command::command_from_str(string).await;
if let commands::Command::PING(command) = command {
if let Err(_e) = self.pong(&command).await {