aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTill Hoeppner2015-04-18 13:35:38 +0200
committerTill Hoeppner2015-04-18 13:35:38 +0200
commitbb94e44ed6ec5b55823270192c00904cbfb24b6b (patch)
tree4fad16b94a5ef93a2f268fef8382aa20c884746b /examples
parent8b7500ea4c766ca96d2e65a8f19e595d6021f4fa (diff)
downloadirsc-bb94e44ed6ec5b55823270192c00904cbfb24b6b.tar.gz
irsc-bb94e44ed6ec5b55823270192c00904cbfb24b6b.tar.xz
irsc-bb94e44ed6ec5b55823270192c00904cbfb24b6b.zip
I forgot to keep track. Embarassing, huh?
Diffstat (limited to 'examples')
-rw-r--r--examples/01.rs38
1 files changed, 20 insertions, 18 deletions
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();
}