From 17edc45c506927f48f1858e0ba67161a31708032 Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Thu, 11 Jun 2015 22:05:06 +0200 Subject: Implement more events for Energymech --- src/event.rs | 7 ++++++- src/format/energymech.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/event.rs b/src/event.rs index 0ecb6bc..a1c15c2 100644 --- a/src/event.rs +++ b/src/event.rs @@ -105,7 +105,12 @@ pub enum Type<'a> { topic: Cow<'a, str>, }, TopicChange { + nick: Option>, new_topic: Cow<'a, str>, }, - Mode + Mode { + nick: Option>, + mode: Cow<'a, str>, + masks: Cow<'a, str> + } } diff --git a/src/format/energymech.rs b/src/format/energymech.rs index e6f7d80..6e5d8ae 100644 --- a/src/format/energymech.rs +++ b/src/format/energymech.rs @@ -13,7 +13,7 @@ // limitations under the License. use std::io::{ BufRead, Write }; -use std::borrow::{ ToOwned }; +use std::borrow::{ ToOwned, Cow }; use std::iter::{ Iterator }; use event::{ Event, Type, Time }; @@ -58,10 +58,12 @@ impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { let tokens = self.buffer.split( |c: char| { if c.is_whitespace() { split_tokens.push(c); true } else { false } }).collect::>(); + if log_enabled!(Info) { info!("Original: `{}`", self.buffer); info!("Parsing: {:?}", tokens); } + match &tokens[..tokens.len() - 1] { [time, "*", nick, content..] => return Some(Ok(Event { ty: Type::Action { @@ -79,6 +81,15 @@ impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { time: parse_time(&self.context, time), channel: None })), + [time, "***", nick, "sets", "mode:", mode, masks..] => return Some(Ok(Event { + ty: Type::Mode { + nick: Some(nick.to_owned().into()), + mode: mode.to_owned().into(), + masks: rejoin(&masks, &split_tokens[6..]).to_owned().into() + }, + time: parse_time(&self.context, time), + channel: None + })), [time, "***", "Joins:", nick, host] => return Some(Ok(Event { ty: Type::Join { nick: nick.to_owned().into(), @@ -87,6 +98,15 @@ impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { time: parse_time(&self.context, time), channel: None })), + [time, "***", "Parts:", nick, host, reason..] => return Some(Ok(Event { + ty: Type::Part { + nick: nick.to_owned().into(), + mask: Some(strip_one(host).into()), + reason: Some(strip_one(&rejoin(reason, &split_tokens[5..])).into()) + }, + time: parse_time(&self.context, time), + channel: None + })), [time, "***", "Quits:", nick, host, reason..] => return Some(Ok(Event { ty: Type::Quit { nick: nick.to_owned().into(), @@ -96,6 +116,14 @@ impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { time: parse_time(&self.context, time), channel: None })), + [time, "***", nick, "changes", "topic", "to", topic..] => return Some(Ok(Event { + ty: Type::TopicChange { + nick: Some(nick.to_owned().into()), + new_topic: strip_one(&rejoin(topic, &split_tokens[6..])).into() + }, + time: parse_time(&self.context, time), + channel: None + })), [time, nick, content..] if nick.starts_with('<') && nick.ends_with('>') => return Some(Ok(Event { @@ -137,12 +165,35 @@ impl<'a, W> Encode<'a, W> for Energymech where W: Write { try!(writeln!(&mut output, "[{}] *** {} is now known as {}", time.with_format(&context.timezone, TIME_FORMAT), old_nick, new_nick)) }, + &Event { ty: Type::Mode { ref nick, ref mode, ref masks }, ref time, .. } => { + try!(writeln!(&mut output, "[{}] *** {} sets mode: {} {}", + time.with_format(&context.timezone, TIME_FORMAT), + nick.as_ref().expect("Nickname not present, but required."), + mode, masks)) + }, + &Event { ty: Type::Join { ref nick, ref mask }, ref time, .. } => { + try!(writeln!(&mut output, "[{}] *** Joins: {} ({})", + time.with_format(&context.timezone, TIME_FORMAT), nick, + mask.as_ref().expect("Mask not present, but required."))) + }, + &Event { ty: Type::Part { ref nick, ref mask, ref reason }, ref time, .. } => { + try!(writeln!(&mut output, "[{}] *** Parts: {} ({}) ({})", + time.with_format(&context.timezone, TIME_FORMAT), nick, + mask.as_ref().expect("Mask not present, but required."), + reason.as_ref().unwrap_or(&Cow::Borrowed("")))) + }, &Event { ty: Type::Quit { ref nick, ref mask, ref reason }, ref time, .. } => { try!(writeln!(&mut output, "[{}] *** Quits: {} ({}) ({})", time.with_format(&context.timezone, TIME_FORMAT), nick, mask.as_ref().expect("Mask not present, but required."), reason.as_ref().expect("Reason not present, but required."))) }, + &Event { ty: Type::TopicChange { ref nick, ref new_topic }, ref time, .. } => { + try!(writeln!(&mut output, "[{}] *** {} changes topic to '{}'", + time.with_format(&context.timezone, TIME_FORMAT), + nick.as_ref().expect("Nick not present, but required."), + new_topic)) + }, _ => () } Ok(()) -- cgit v1.2.3