irc-rs

A simple Rustlang IRC Lib optimized for bots
git clone git://archive.git.mtrnord.blog/MTRNord/irc-rs.git
Log | Files | Refs | README | LICENSE

commit 586348c791d2c9984d73abe52b8772141cb33d70
parent 870fed7283c029d86457f6ff841d7fa01589c5b5
Author: Marcel <mtrnord1@gmail.com>
Date:   Mon, 16 Jan 2017 11:18:28 +0100

(feature) add Ping handling

Diffstat:
Msrc/lib.rs | 19++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/lib.rs b/src/lib.rs @@ -2,7 +2,7 @@ extern crate bufstream; mod irc { fn connect(host: String, port: u16) { use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream}; - use std::io::Write; + use std::io::{Write, BufRead}; use bufstream::BufStream; let host_split: Vec<&str> = host.split('.').collect(); let ServerAddress = IpAddr::V4(Ipv4Addr::new(host_split[0].as_bytes()[0], host_split[1].as_bytes()[0], host_split[2].as_bytes()[0], host_split[3].as_bytes()[0])); // Connect to localhost @@ -14,5 +14,22 @@ mod irc { stream.write(b"NICK rustbot\r\n"); stream.write(b"USER rustbot 8 * :rustbot\r\n"); stream.flush(); + + let mut g = 1; + while g > 0 { + let mut r = String::new(); + while stream.read_line(&mut r).unwrap() > 0 { + if r.is_empty(){ + g = 0; + }else{ + if r.clone().contains("004") { + isConnected = true; + } else if r.clone().contains("PING") { + stream.write(b"PONG\r\n"); + stream.flush(); + } + } + } + } } }