aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-03-03 18:02:36 +0100
committerJokler <jokler.contact@gmail.com>2018-03-03 18:02:36 +0100
commit7304240fb50458c64d63eb784967d9dbde75eae6 (patch)
treee51bae69715524c9ded49d26459549380df3b555 /src
parent0b4131e8cf91ed10f24d3faed341034d518aea53 (diff)
downloadfrippy-7304240fb50458c64d63eb784967d9dbde75eae6.tar.gz
frippy-7304240fb50458c64d63eb784967d9dbde75eae6.zip
Make tells caase insensitive and only check JOINs
Diffstat (limited to 'src')
-rw-r--r--src/plugin.rs2
-rw-r--r--src/plugins/tell/mod.rs42
2 files changed, 25 insertions, 19 deletions
diff --git a/src/plugin.rs b/src/plugin.rs
index e57f072..bc428d5 100644
--- a/src/plugin.rs
+++ b/src/plugin.rs
@@ -45,7 +45,7 @@ pub trait Plugin: PluginName + Send + Sync + fmt::Debug {
/// #[derive(PluginName)]
/// struct Foo;
/// ```
-pub trait PluginName: Send + Sync + fmt::Debug {
+pub trait PluginName {
/// Returns the name of the `Plugin`.
fn name(&self) -> &str;
}
diff --git a/src/plugins/tell/mod.rs b/src/plugins/tell/mod.rs
index 7052b3e..4f6bfa0 100644
--- a/src/plugins/tell/mod.rs
+++ b/src/plugins/tell/mod.rs
@@ -38,22 +38,27 @@ impl<T: Database> Tell<T> {
}
}
- fn tell_command(&self, client: &IrcClient, command: &PluginCommand) -> Result<&str, String> {
+ fn tell_command(&self, client: &IrcClient, command: PluginCommand) -> Result<&str, String> {
if command.tokens.len() < 2 {
return Err(self.invalid_command(client));
}
- let receiver = command.tokens[0].to_string();
- let sender = command.source.to_owned();
+ let receiver = &command.tokens[0];
+ let sender = command.source;
- if receiver == sender {
+ if receiver.eq_ignore_ascii_case(&sender) {
return Err(String::from("That's your name!"));
}
- if command.source != command.target {
- if let Some(users) = client.list_users(&command.target) {
- if users.iter().any(|u| u.get_nickname() == receiver) {
- return Err(format!("{} is in this channel.", receiver));
+ if let Some(channels) = client.list_channels() {
+ for channel in channels {
+ if let Some(users) = client.list_users(&channel) {
+ if users
+ .iter()
+ .any(|u| u.get_nickname().eq_ignore_ascii_case(&receiver))
+ {
+ return Err(format!("{} is online in another channel.", receiver));
+ }
}
}
}
@@ -62,7 +67,7 @@ impl<T: Database> Tell<T> {
let message = command.tokens[1..].join(" ");
let tell = database::NewTellMessage {
sender: &sender,
- receiver: &receiver,
+ receiver: &receiver.to_lowercase(),
time: NaiveDateTime::from_timestamp(tm.sec, 0u32),
message: &message,
};
@@ -73,9 +78,9 @@ impl<T: Database> Tell<T> {
}
}
- fn send_tell(&self, client: &IrcClient, receiver: &str) -> ExecutionStatus {
+ fn send_tells(&self, client: &IrcClient, receiver: &str) -> ExecutionStatus {
let mut tells = try_lock!(self.tells);
- if let Some(tell_messages) = tells.get_tells(receiver) {
+ if let Some(tell_messages) = tells.get_tells(&receiver.to_lowercase()) {
for tell in tell_messages {
let now = Duration::new(time::now().to_timespec().sec as u64, 0);
let dur = now - Duration::new(tell.time.timestamp() as u64, 0);
@@ -96,7 +101,8 @@ impl<T: Database> Tell<T> {
);
}
}
- tells.delete_tells(receiver);
+ tells.delete_tells(&receiver.to_lowercase());
+
ExecutionStatus::Done
}
@@ -120,9 +126,7 @@ impl<T: Database> Tell<T> {
impl<T: Database> Plugin for Tell<T> {
fn execute(&self, client: &IrcClient, message: &Message) -> ExecutionStatus {
match message.command {
- Command::JOIN(_, _, _) | Command::PRIVMSG(_, _) => {
- self.send_tell(client, message.source_nickname().unwrap())
- }
+ Command::JOIN(_, _, _) => self.send_tells(client, message.source_nickname().unwrap()),
_ => ExecutionStatus::Done,
}
}
@@ -138,16 +142,18 @@ impl<T: Database> Plugin for Tell<T> {
.context(FrippyErrorKind::Connection)?);
}
+ let sender = command.source.to_owned();
+
Ok(match command.tokens[0].as_ref() {
"help" => client
.send_notice(&command.source, &self.help(client))
.context(FrippyErrorKind::Connection),
- _ => match self.tell_command(client, &command) {
+ _ => match self.tell_command(client, command) {
Ok(msg) => client
- .send_notice(&command.source, msg)
+ .send_notice(&sender, msg)
.context(FrippyErrorKind::Connection),
Err(msg) => client
- .send_notice(&command.source, &msg)
+ .send_notice(&sender, &msg)
.context(FrippyErrorKind::Connection),
},
}?)