From cd708c3ef3f8c070f4b0c566575fb043c4eb1e8e Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Sun, 4 Jan 2015 23:34:37 +0100 Subject: I should make smaller commits. --- examples/01.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'examples') 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(); -- cgit v1.2.3 From bb94e44ed6ec5b55823270192c00904cbfb24b6b Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Sat, 18 Apr 2015 13:35:38 +0200 Subject: I forgot to keep track. Embarassing, huh? --- examples/01.rs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'examples') diff --git a/examples/01.rs b/examples/01.rs index 7cd7dc6..021fd2f 100644 --- a/examples/01.rs +++ b/examples/01.rs @@ -1,4 +1,6 @@ -#![feature(globs, slicing_syntax)] +#![allow(unstable)] +#![feature(plugin, slicing_syntax)] +#![plugin(regex_macros)] extern crate irsc; @@ -8,41 +10,41 @@ use std::sync::{Once, ONCE_INIT}; use irsc::server::Server; use irsc::color::bold; -use irsc::event; -use irsc::event::{ Event, ParseResult, PrivMsg }; +use irsc::message; +use irsc::message::{ Message, Command }; static NAME: &'static str = "rusticbot"; static DESC: &'static str = "A bot, written in Rust."; static START: Once = ONCE_INIT; -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 callback(server: &mut Server, 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(); }, - event::MODE => { - START.doit(|| { - server.msg("Syna", "Hey, I'm poking you! *pokes you*").unwrap(); + _ => {} + } + + /* + "001" => { + START.call_once(|| { + server.msg("Nalfon", "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.tulpa.info".to_owned(), 6667).unwrap(); + s.connect("irc.furnet.org".to_owned(), 6667).unwrap(); s.nick(NAME).unwrap(); s.user(NAME, "*", "*", DESC).unwrap(); s.join("#botzoo").unwrap(); - s.events.lock().register(&(callback as fn(&(Server, Event)))); - // Dedicate this thread to listening and event processing - s.listen().unwrap(); + s.listen(&[callback]).unwrap(); } -- cgit v1.2.3 From 3483b65e9173d9ef7ea709de898b3a7866045fbd Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Sat, 18 Apr 2015 15:12:41 +0200 Subject: Make tests/examples compile, not work though --- examples/01.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/01.rs b/examples/01.rs index 021fd2f..ee6c99a 100644 --- a/examples/01.rs +++ b/examples/01.rs @@ -1,5 +1,4 @@ -#![allow(unstable)] -#![feature(plugin, slicing_syntax)] +#![feature(plugin)] #![plugin(regex_macros)] extern crate irsc; @@ -10,7 +9,6 @@ use std::sync::{Once, ONCE_INIT}; use irsc::server::Server; use irsc::color::bold; -use irsc::message; use irsc::message::{ Message, Command }; static NAME: &'static str = "rusticbot"; @@ -30,8 +28,6 @@ fn callback(server: &mut Server, msg: &Message) { /* "001" => { START.call_once(|| { - server.msg("Nalfon", "Hey, I'm poking you! *pokes you*").unwrap(); - //server.msg("Xasin", "Hey, I'm poking you! *pokes you*").unwrap(); }) }, _ => () @@ -40,7 +36,7 @@ fn callback(server: &mut Server, msg: &Message) { fn main() { let mut s = Server::new(); - s.connect("irc.furnet.org".to_owned(), 6667).unwrap(); + s.connect("irc.mozilla.org".to_owned(), 6667).unwrap(); s.nick(NAME).unwrap(); s.user(NAME, "*", "*", DESC).unwrap(); s.join("#botzoo").unwrap(); -- cgit v1.2.3