From 6ed12a0993d56330bb008adc86bfb5ebe4320583 Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Fri, 21 Nov 2014 11:31:55 +0100 Subject: Upload to crates.io plus fixes for changes in Rust --- Cargo.toml | 4 ++++ examples/01.rs | 38 ++++++++++++++++++++++++++++++++++++++ src/main.rs | 38 -------------------------------------- src/server.rs | 14 +++++++------- 4 files changed, 49 insertions(+), 45 deletions(-) create mode 100644 examples/01.rs delete mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml index b15999b..2e6bbb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,3 +3,7 @@ name = "irsc" version = "0.0.1" authors = ["Till Hoeppner "] +description = "A lightweight library for building IRC bots." +repository = "https://github.com/hoeppnertill/irsc" +keywords = ["irc", "internet", "protocol", "useless tags"] +license = "No decision yet." diff --git a/examples/01.rs b/examples/01.rs new file mode 100644 index 0000000..9756119 --- /dev/null +++ b/examples/01.rs @@ -0,0 +1,38 @@ +#![feature(globs, slicing_syntax)] + +extern crate irsc; + +use irsc::server::Server; +use irsc::color::bold; +use irsc::event; +use irsc::event::{ Event, ParseResult, PrivMsg }; + +static NAME: &'static str = "rusticbot"; +static DESC: &'static str = "A bot, written in Rust."; + +fn callback(arg: (Server, Event)) { + let (mut server, event) = arg; + match event.command[] { + event::PRIVMSG => { + let privmsg: PrivMsg = ParseResult::parse(event).unwrap(); + let response = format!("You wrote: {}", bold(privmsg.content[])); + server.msg(privmsg.from.nickname[], response[]).unwrap(); + }, + _ => () + } +} + +fn main() { + let mut s = Server::new(); + s.connect("irc.freenode.org".into_string(), 6667).unwrap(); + s.nick(NAME).unwrap(); + s.user(NAME, "*", "*", DESC).unwrap(); + s.join("#botzoo").unwrap(); + + s.msg("flan3002", "Hey, I'm your example bot!").unwrap(); + + s.events.lock().register(&callback); + + // Dedicate this thread to listening and event processing + s.listen().unwrap(); +} diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 865234a..0000000 --- a/src/main.rs +++ /dev/null @@ -1,38 +0,0 @@ -#![feature(globs, slicing_syntax)] - -extern crate irsc; - -use irsc::server::Server; -use irsc::color::bold; -use irsc::event; -use irsc::event::{ Event, ParseResult, PrivMsg }; - -static NAME: &'static str = "rusticbot"; -static DESC: &'static str = "A bot, written in Rust."; - -fn callback(arg: (Server, Event)) { - let (mut server, event) = arg; - match event.command[] { - event::PRIVMSG => { - let privmsg: PrivMsg = ParseResult::parse(event).unwrap(); - let response = format!("You wrote: {}", bold(privmsg.content[])); - server.msg(privmsg.from.nickname[], response[]).unwrap(); - }, - _ => () - } -} - -fn main() { - let mut s = Server::new(); - s.connect("irc.freenode.org".into_string(), 6667).unwrap(); - s.nick(NAME).unwrap(); - s.user(NAME, "*", "*", DESC).unwrap(); - s.join("#botzoo").unwrap(); - - s.msg("flan3002", "Hey!").unwrap(); - - s.events.lock().register(&callback); - - // Dedicate this thread to listening and event processing - s.listen().unwrap(); -} diff --git a/src/server.rs b/src/server.rs index b783a25..343cdee 100644 --- a/src/server.rs +++ b/src/server.rs @@ -48,10 +48,10 @@ impl Server { pub fn connect(&mut self, host: String, port: u16) -> Result<(), Failure> { let mut s = self.stream.lock(); - match *s { Some(_) => return Err(AlreadyConnected), _ => () }; + match *s { Some(_) => return Err(Failure::AlreadyConnected), _ => () }; *s = match TcpStream::connect((host.as_slice(), port)) { Ok(tcp) => Some(tcp), - Err(e) => return Err(Io(e)) + Err(e) => return Err(Failure::Io(e)) }; Ok(()) @@ -67,15 +67,15 @@ impl Server { Ok(_) => match { if newline { stream.write_str("\r\n") } else { Ok(()) } } { Ok(_) => match stream.flush() { Ok(_) => Ok(()), - Err(e) => return Err(Io(e)) + Err(e) => return Err(Failure::Io(e)) }, - Err(e) => return Err(Io(e)) + Err(e) => return Err(Failure::Io(e)) }, - Err(e) => return Err(Io(e)) + Err(e) => return Err(Failure::Io(e)) } }).unwrap() } else { - Err(NotConnected) + Err(Failure::NotConnected) } } @@ -104,7 +104,7 @@ impl Server { let lock = self.stream.lock(); match *lock { Some(ref s) => s.clone(), - None => return Err(NotConnected) + None => return Err(Failure::NotConnected) } }; -- cgit v1.2.3