Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.
/ rust-relay Public archive

An IRC(v3) client library written in (an old version of) Rust

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING
Notifications You must be signed in to change notification settings

M2Ys4U/rust-relay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust-Relay

Rust-Relay is an IRC(v3) client library written in a really old version of Rust. You almost certainly don't want to use this.

Components

This is a brief overview of the components provided by this library. For full details, see the generated RustDoc files.

BasicClient Struct

This is, as the name suggests, a basic IRC client. It can connect to an IRC server, perform IRCv3 capability negotiation and keep the connection live by responding to PING commands.

Implements the IrcMethods trait for convenience.

Connection Struct

Represents a connection to an IRC server.

Implements the IrcMethods traid for convenience.

IrcMethods Trait

Convenience methods that can be applied to any Writer to send IRC commands (or at least the ones defined in RFC 1459 and the IRCv3 extensions.

Parser Struct

Reads IRC messages from a Reader and produces Messages.

Project Status

This is a rough first-draft implementation.

Handing Messages is a little messy as they are currently backed by MaybeOwneds to avoid allocations for certain use-cases. I expect this will get easier as the Rust stdlib stablises.

Feedback on the APIs would be much appreciated.

Example code

Here is a very crude CLI IRC client implemented using the library:

extern crate relay;

use std::collections::HashSet;
use std::io::stdio::stdin;
use std::comm::{Empty, Disconnected};

use relay::{Message, BasicClient, Capability, MessageErr};

fn main() {
    let mut caps = HashSet::new();
    caps.insert(Capability::from_str("multi-prefix").unwrap());

    let mut client = BasicClient::new("Relay_Test", "relay", "relay", caps);
    match client.connect_to("media-server.local:6667") {
        Err(e) => {
            panic!(e);
        },
        Ok(_) =>{}
    }
    let mut stream = client.get_stream().clone();

    let (tx, rx) = channel();
    spawn(proc() {
        let tx = tx;
        loop {
            match client.read_message() {
                Ok(msg_opt) => {
                    match msg_opt {
                        Some(msg) => {
                            tx.send(msg);
                        },
                        None => {}
                    }
                },
                Err(e) => {
                    panic!(e);
                }
            }
        }
    });

    let mut std_in = stdin();
    loop {
        'dance: loop {
            match rx.try_recv() {
                Ok(msg) => {
                    print!("-> {}", msg);
                },
                Err(e) => {
                    match e {
                        Empty => {
                            break 'dance;
                        },
                        Disconnected => {
                            return;
                        }
                    }
                }
            }
        }
        match Message::from_str(std_in.read_line().unwrap().as_slice()) {
            Ok(msg) => {
                let _ = write!(stream, "{}", msg);
            },
            Err(e) => {
                match e {
                    MessageErr::EmptyInput => {},
                    _ => {
                        println!("{}", e);
                    }
                }
            }
        }
    }

}

License

Rust-Relay is licenced under version 3 of the GNU Lesser General Public License (GNU LGPL) or any later version. See the COPYING and COPYING.LESSER files for more information.

About

An IRC(v3) client library written in (an old version of) Rust

Resources

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages