From 9826d256eec94144469e27c159e0ec4642b2fda6 Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Fri, 3 Apr 2015 00:18:35 +0200 Subject: More event types --- src/format/weechat3.rs | 20 ++++++++++++++++---- src/lib.rs | 2 +- src/main.rs | 6 ++++-- 3 files changed, 21 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/format/weechat3.rs b/src/format/weechat3.rs index 40445a1..dfe2868 100644 --- a/src/format/weechat3.rs +++ b/src/format/weechat3.rs @@ -58,14 +58,23 @@ impl Iterator for Iter where R: BufRead { nick: nick.to_owned(), channel: channel.to_owned(), mask: mask(host), time: timestamp(date, time) })), - [date, time, "<--", nick, host, "has", "left", channel, reason, _..] => return Some(Ok(Event::Part { + [date, time, "<--", nick, host, "has", "left", channel, reason..] => return Some(Ok(Event::Part { nick: nick.to_owned(), channel: channel.to_owned(), mask: mask(host), - reason: reason.to_owned(), time: timestamp(date, time) + reason: mask(&join(reason)), time: timestamp(date, time) + })), + [date, time, "--", notice, content..] + if notice.starts_with("Notice(") + => return Some(Ok(Event::Notice { + nick: notice["Notice(".len()..notice.len() - 2].to_owned(), + content: join(content), + time: timestamp(date, time) })), [date, time, "--", "irc:", "disconnected", "from", "server", _..] => return Some(Ok(Event::Disconnect { time: timestamp(date, time) })), - [date, time, "*", nick, msg..] => return Some(Ok(Event::Action { + [date, time, sp, "*", nick, msg..] + if sp.is_empty() + => return Some(Ok(Event::Action { from: nick.to_owned(), content: join(msg), time: timestamp(date, time) })), @@ -159,7 +168,7 @@ impl Encode for Weechat3 where W: Write { try!(writeln!(&mut output, "{}\t{}\t{}", date(*time), from, content)) }, &Event::Action { ref from, ref content, ref time } => { - try!(writeln!(&mut output, "{}\t*\t{} {}", date(*time), from, content)) + try!(writeln!(&mut output, "{}\t *\t{} {}", date(*time), from, content)) }, &Event::Join { ref nick, ref mask, ref channel, ref time } => { try!(writeln!(&mut output, "{}\t-->\t{} ({}) has joined {}", @@ -183,6 +192,9 @@ impl Encode for Weechat3 where W: Write { &Event::Disconnect { ref time } => { try!(writeln!(&mut output, "{}\t--\tirc: disconnected from server", date(*time))) }, + &Event::Notice { ref nick, ref content, ref time } => { + try!(writeln!(&mut output, "{}\t--\tNotice({}): {}", date(*time), nick, content)) + }, _ => () } Ok(()) diff --git a/src/lib.rs b/src/lib.rs index 1cceb27..ac89c95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(plugin, slice_patterns, convert, core)] +#![feature(plugin, str_char, slice_patterns, convert, core)] #![plugin(regex_macros)] extern crate regex; extern crate chrono; diff --git a/src/main.rs b/src/main.rs index be86652..53c3527 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,8 @@ extern crate docopt; extern crate rustc_serialize; extern crate libc; extern crate regex; +#[macro_use] +extern crate log; extern crate env_logger; use std::fs::File; @@ -59,8 +61,8 @@ fn main() { for file in args.arg_file { let f: BufReader = BufReader::new(File::open(file).unwrap()); let iter = parser.decode(f); - let events: Vec<_> = iter.collect(); - for e in events { + for e in iter { + info!("Parsed: {:?}", e); drop(parser.encode(io::stdout(), &e.unwrap())); } } -- cgit v1.2.3