add more events, dry up event filter code

This commit is contained in:
Adrian Malacoda 2018-02-23 00:03:05 -06:00
parent 93ee23c831
commit 72eadd4549
2 changed files with 36 additions and 46 deletions

View File

@ -8,7 +8,11 @@ pub enum Event {
SelfQuit { channel: Channel }, // We quit a channel
UserJoin { channel: Channel, user: User }, // A user joins a channel
UserQuit { channel: Channel, user: User } // A user quits a channel
UserQuit { channel: Channel, user: User }, // A user quits a channel
UserKick { channel: Channel, user: User }, // A usre is kicked from a channel
UserBan { channel: Channel, user: User }, // A user is banned from a channel
TopicChange { channel: Channel } // Channel topic is changed
}
#[derive(Debug)]

View File

@ -258,80 +258,66 @@ impl EventFilter for AttributeEventFilter {
let mut result = true;
match &envelope.event {
&Event::Message { ref message } => {
match self.event_type {
Some(ref event_type) => result = result && event_type == "message",
None => {}
if let Some(ref event_type) = self.event_type {
result = result && event_type == "message";
}
match self.channel {
Some(ref channel_name) => {
match message.channel {
Some(ref channel) => result = result && channel_name == &channel.name,
None => result = false
}
},
None => {}
if let Some(ref channel_name) = self.channel {
match message.channel {
Some(ref channel) => result = result && channel_name == &channel.name,
None => result = false
}
}
match self.username {
Some(ref username) => result = result && &message.author.name == username,
None => {}
if let Some(ref username) = self.username {
result = result && &message.author.name == username;
}
},
&Event::SelfJoin { ref channel } => {
match self.event_type {
Some(ref event_type) => result = result && event_type == "selfjoin",
None => {}
if let Some(ref event_type) = self.event_type {
result = result && event_type == "selfjoin";
}
match self.channel {
Some(ref channel_name) => result = result && channel_name == &channel.name,
None => {}
if let Some(ref channel_name) = self.channel {
result = result && channel_name == &channel.name;
}
},
&Event::SelfQuit { ref channel } => {
match self.event_type {
Some(ref event_type) => result = result && event_type == "selfquit",
None => {}
if let Some(ref event_type) = self.event_type {
result = result && event_type == "selfquit";
}
match self.channel {
Some(ref channel_name) => result = result && channel_name == &channel.name,
None => {}
if let Some(ref channel_name) = self.channel {
result = result && channel_name == &channel.name;
}
},
&Event::UserJoin { ref channel, ref user } => {
match self.event_type {
Some(ref event_type) => result = result && event_type == "userjoin",
None => {}
if let Some(ref event_type) = self.event_type {
result = result && event_type == "userjoin";
}
match self.channel {
Some(ref channel_name) => result = result && channel_name == &channel.name,
None => {}
if let Some(ref channel_name) = self.channel {
result = result && channel_name == &channel.name;
}
match self.username {
Some(ref username) => result = result && &user.name == username,
None => {}
if let Some(ref username) = self.username {
result = result && &user.name == username;
}
},
&Event::UserQuit { ref channel, ref user } => {
match self.event_type {
Some(ref event_type) => result = result && event_type == "userquit",
None => {}
if let Some(ref event_type) = self.event_type {
result = result && event_type == "userquit";
}
match self.channel {
Some(ref channel_name) => result = result && channel_name == &channel.name,
None => {}
if let Some(ref channel_name) = self.channel {
result = result && channel_name == &channel.name;
}
match self.username {
Some(ref username) => result = result && &user.name == username,
None => {}
if let Some(ref username) = self.username {
result = result && &user.name == username;
}
}
},
_ => {}
}
result