aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTill Hoeppner2015-04-21 20:55:49 +0200
committerTill Hoeppner2015-04-21 20:55:49 +0200
commit1eb2262e100d264bd4eeb5fe050edbcbdb94ceca (patch)
tree167f5c0113491569138485acc3ae89f069a0d1e4
parent9bb27a5fd0ef62874762df6d0eb180de6f351a24 (diff)
downloadirsc-1eb2262e100d264bd4eeb5fe050edbcbdb94ceca.tar.gz
irsc-1eb2262e100d264bd4eeb5fe050edbcbdb94ceca.tar.xz
irsc-1eb2262e100d264bd4eeb5fe050edbcbdb94ceca.zip
No need for eventual
-rw-r--r--Cargo.toml2
-rw-r--r--examples/01.rs49
-rw-r--r--src/lib.rs1
3 files changed, 27 insertions, 25 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 661c8a5..2013c29 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,9 +10,9 @@ license = "MIT"
[dependencies]
log = "*"
+env_logger = "*"
regex = "*"
regex_macros = "*"
-eventual = "*"
[features]
ssl = ["openssl"]
diff --git a/examples/01.rs b/examples/01.rs
index eb662ca..5021aac 100644
--- a/examples/01.rs
+++ b/examples/01.rs
@@ -1,46 +1,49 @@
#![feature(plugin)]
#![plugin(regex_macros)]
-/*extern crate irsc;
+extern crate irsc;
+extern crate env_logger;
use std::borrow::ToOwned;
+use std::borrow::Cow::*;
-// use std::sync::{Once, ONCE_INIT};
-
-use irsc::server::Server;
+use irsc::client::Client;
use irsc::color::bold;
-use irsc::message::{ Message, Command };
+use irsc::*;
+use irsc::Command::*;
+use irsc::Reply::*;
static NAME: &'static str = "rusticbot";
static DESC: &'static str = "A bot, written in Rust.";
-// static START: Once = ONCE_INIT;
-
-fn callback(server: &mut Server, msg: &Message) {
+fn callback(server: &mut Client, msg: &Message) {
match Command::from_message(msg) {
- Some(Command::PrivMsg { from, content, .. }) => {
- let response = format!("You wrote: {}", bold(&content));
- server.msg(&from.unwrap(), &response).unwrap();
+ Some(PRIVMSG(to, content)) => {
+ let from = msg.prefix().and_then(Ident::parse).unwrap();
+ let response = match msg.msg_type {
+ MsgType::Irc => format!("{} wrote: {}", from.nickname, bold(&content)),
+ MsgType::Ctcp => format!("{} emoted: {}", from.nickname, bold(&content["ACTION ".len()..]))
+ };
+ server.send(PRIVMSG(to, Owned(response))).unwrap();
},
- _ => {}
+ _ => ()
}
- /*
- "001" => {
- START.call_once(|| {
- })
+ match Reply::from_message(msg) {
+ Some(RPL_WELCOME(_)) => {
+ server.send(JOIN(vec![Borrowed("#botzoo")], vec![])).unwrap();
},
_ => ()
- }*/
+ }
}
-*/
+
fn main() {
- /*let mut s = Server::new();
+ env_logger::init().unwrap();
+ let mut s = Client::new();
s.connect("irc.mozilla.org".to_owned(), 6667).unwrap();
- s.nick(NAME).unwrap();
- s.user(NAME, "*", "*", DESC).unwrap();
- s.join("#botzoo").unwrap();
+ s.send(NICK(Borrowed(NAME))).unwrap();
+ s.send(USER(Borrowed(NAME), Borrowed("*"), Borrowed("*"), Borrowed(DESC))).unwrap();
// Dedicate this thread to listening and event processing
- s.listen(&[callback]).unwrap();*/
+ s.listen(callback).unwrap();
}
diff --git a/src/lib.rs b/src/lib.rs
index 2ba5045..0875618 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,7 +4,6 @@
extern crate regex;
#[macro_use]
extern crate log;
-extern crate eventual;
pub mod client;
pub mod color;