Updated command parser
This commit is contained in:
parent
041922dae8
commit
f336537670
|
@ -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();
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue