diff options
author | Till Hoeppner | 2015-01-04 23:34:37 +0100 |
---|---|---|
committer | Till Hoeppner | 2015-01-04 23:34:37 +0100 |
commit | cd708c3ef3f8c070f4b0c566575fb043c4eb1e8e (patch) | |
tree | c600c8399d87fe18c4da05ad121f710ea11d2bac /examples/01.rs | |
parent | 326b5d9d96a5f45fa8b371f2a78394bcd87030e0 (diff) | |
download | irsc-cd708c3ef3f8c070f4b0c566575fb043c4eb1e8e.tar.gz irsc-cd708c3ef3f8c070f4b0c566575fb043c4eb1e8e.tar.xz irsc-cd708c3ef3f8c070f4b0c566575fb043c4eb1e8e.zip |
I should make smaller commits.
Diffstat (limited to 'examples/01.rs')
-rw-r--r-- | examples/01.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/examples/01.rs b/examples/01.rs index 0bf51f5..7cd7dc6 100644 --- a/examples/01.rs +++ b/examples/01.rs @@ -2,6 +2,10 @@ extern crate irsc; +use std::borrow::ToOwned; + +use std::sync::{Once, ONCE_INIT}; + use irsc::server::Server; use irsc::color::bold; use irsc::event; @@ -10,7 +14,9 @@ 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)) { +static START: Once = ONCE_INIT; + +fn callback(arg: &(Server, Event)) { let (mut server, event) = arg; match event.command[] { event::PRIVMSG => { @@ -18,20 +24,24 @@ fn callback(arg: (Server, Event)) { let response = format!("You wrote: {}", bold(privmsg.content[])); server.msg(privmsg.from.nickname[], response[]).unwrap(); }, + event::MODE => { + START.doit(|| { + server.msg("Syna", "Hey, I'm poking you! *pokes you*").unwrap(); + //server.msg("Xasin", "Hey, I'm poking you! *pokes you*").unwrap(); + }) + }, _ => () } } fn main() { let mut s = Server::new(); - s.connect("irc.freenode.org".into_string(), 6667).unwrap(); + s.connect("irc.tulpa.info".to_owned(), 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 as fn((Server,Event)))); + s.events.lock().register(&(callback as fn(&(Server, Event)))); // Dedicate this thread to listening and event processing s.listen().unwrap(); |