aboutsummaryrefslogtreecommitdiff
path: root/examples/01.rs
diff options
context:
space:
mode:
authorTill Höppner2015-04-18 15:29:14 +0200
committerTill Höppner2015-04-18 15:29:14 +0200
commit057d3e0bdb4bb46749267b45223281fd9afc956d (patch)
treef6994ad12dd7d765d58958599705fb3d9d2c4d16 /examples/01.rs
parent326b5d9d96a5f45fa8b371f2a78394bcd87030e0 (diff)
parent4eea7cdff640f31f6595ec880d5405665fbd5c55 (diff)
downloadirsc-057d3e0bdb4bb46749267b45223281fd9afc956d.tar.gz
irsc-057d3e0bdb4bb46749267b45223281fd9afc956d.tar.xz
irsc-057d3e0bdb4bb46749267b45223281fd9afc956d.zip
Merge pull request #3 from tilpner/refactor
Refactor
Diffstat (limited to 'examples/01.rs')
-rw-r--r--examples/01.rs42
1 files changed, 25 insertions, 17 deletions
diff --git a/examples/01.rs b/examples/01.rs
index 0bf51f5..ee6c99a 100644
--- a/examples/01.rs
+++ b/examples/01.rs
@@ -1,38 +1,46 @@
-#![feature(globs, slicing_syntax)]
+#![feature(plugin)]
+#![plugin(regex_macros)]
extern crate irsc;
+use std::borrow::ToOwned;
+
+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::{ Message, Command };
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();
+static START: Once = ONCE_INIT;
+
+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();
},
- _ => ()
+ _ => {}
}
+
+ /*
+ "001" => {
+ START.call_once(|| {
+ })
+ },
+ _ => ()
+ }*/
}
fn main() {
let mut s = Server::new();
- s.connect("irc.freenode.org".into_string(), 6667).unwrap();
+ s.connect("irc.mozilla.org".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))));
-
// Dedicate this thread to listening and event processing
- s.listen().unwrap();
+ s.listen(&[callback]).unwrap();
}