rustirc

Crates.iorustirc
lib.rsrustirc
version0.1.0
sourcesrc
created_at2021-01-16 12:56:08.484575
updated_at2021-01-16 12:56:08.484575
descriptionA fully async IRC library and protocol implementation
homepage
repositoryhttps://github.com/theonlyartz/rustirc/
max_upload_size
id342782
size23,621
Amit Katz (TheOnlyArtz)

documentation

README

rustirc

A fully asynchronous IRC client written in Rust

A fully working echo bot example

use rustirc::{
    client::{Client, ClientState},
    event_handler::EventHandler,
    message_parser,
};

struct Handler;

#[async_trait::async_trait]
impl EventHandler for Handler {
    async fn on_message_sent(&self, client: &mut Client, message: message_parser::Message) {
        println!(
            "Message content => {} | sent by: {}",
            message.parameters[1],
            message.source.unwrap()
        );

        // That means we're in a channel and we can send a message
        match client.state {
            ClientState::InChannel(_) => {
                client
                    .send_message(message.parameters[1])
                    .await;
            }
            _ => {}
        }
    }
    
    // Fires an unimplemented raw event
    async fn on_unimplemented(&self, client: &mut Client, message: message_parser::Message) {
        // Do as you you'd like
    }
    
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut c = Client::new("localhost", 6667)
        .handler(Handler)
        .connect()
        .await?;

    c.start().await?;
    Ok(())
}
Commit count: 15

cargo fmt