aboutsummaryrefslogtreecommitdiff
path: root/src/event.rs
diff options
context:
space:
mode:
authorTill Hoeppner2014-11-03 16:50:28 +0100
committerTill Hoeppner2014-11-03 16:50:28 +0100
commitfe1e048e42865a57b7bfd6e78cf44aefb1269a11 (patch)
tree14dea63644e3e2165f21bf776d2306abcabfee7f /src/event.rs
parent55b915a75f49957eaddefa74cbbf572ad186ee2f (diff)
downloadirsc-fe1e048e42865a57b7bfd6e78cf44aefb1269a11.tar.gz
irsc-fe1e048e42865a57b7bfd6e78cf44aefb1269a11.tar.xz
irsc-fe1e048e42865a57b7bfd6e78cf44aefb1269a11.zip
Proper PRIVMSG parsing
Diffstat (limited to 'src/event.rs')
-rw-r--r--src/event.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/event.rs b/src/event.rs
index 7e280a9..aef34f9 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -4,15 +4,28 @@ use ident::Ident;
pub struct Event {
pub prefix: String,
pub command: String,
- pub content: String
+ pub content: Vec<String>
}
pub trait ParseResult {
fn parse(event: Event) -> Option<Self>;
}
+pub const PING: &'static str = "PING";
+
pub const PRIVMSG: &'static str = "PRIVMSG";
+fn join(v: Vec<String>, from: uint) -> String {
+ let mut msg = if v[from].chars().next().unwrap() == ':' {
+ v[from][][1..].into_string()
+ } else { v[from].clone() };
+ for m in v.iter().skip(from + 1) {
+ msg.push_str(" ");
+ msg.push_str(m.trim_right());
+ }
+ msg
+}
+
pub struct PrivMsg {
pub from: Ident,
pub to: String,
@@ -22,10 +35,12 @@ pub struct PrivMsg {
impl ParseResult for PrivMsg {
fn parse(event: Event) -> Option<PrivMsg> {
let from = Ident::parse(event.prefix[]);
+ let to = event.content[0].clone();
match from {
Some(from) => Some(PrivMsg {
from: from,
- content: event.content
+ to: to,
+ content: join(event.content, 1)
}),
None => None
}