Version 0.2.0 #2

Merged
Thelie merged 15 commits from garbage into main 2021-05-23 22:47:43 +02:00
3 changed files with 50 additions and 34 deletions
Showing only changes of commit 66ca846ebb - Show all commits

8
Cargo.lock generated
View file

@ -309,9 +309,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "lettre" name = "lettre"
version = "0.9.5" version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "338d9a248c4b3ef60c51941c678bb8f64e244c0a98f1eb71db027d1e777a5700" checksum = "86ed8677138975b573ab4949c35613931a4addeadd0a8a6aa0327e2a979660de"
dependencies = [ dependencies = [
"base64", "base64",
"bufstream", "bufstream",
@ -583,9 +583,9 @@ checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171"
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.125" version = "1.0.126"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View file

@ -26,9 +26,8 @@ use std::{
sync::mpsc::channel, sync::mpsc::channel,
thread, thread,
}; };
use lettre::{ use lettre::{
Message, SendmailTransport,
SendmailTransport,
Transport Transport
}; };
@ -80,27 +79,27 @@ fn main() {
); );
} }
let mailer = SendmailTransport::new(); let mut mailer = SendmailTransport::new();
loop { loop {
match rx.recv() { match rx.recv() {
Ok(data) => println!("{},{},{},{}", Ok(data) => {
data[0], let mail = lettre::SendableEmail::new(
data[1], lettre::Envelope::new(
data[2], Some("m2m.chaostreff-alzye.de".parse().unwrap()),
data[3]), vec![data[0].parse().unwrap()]
// let mail = Message::Builder() ).unwrap(),
// .from("m2m.chaostreff-alzye.de".parse().unwrap()) format!("You were mentioned in {} on {}", data[2], data[1])
// .to("Put adress here") .parse().unwrap(),
// .subject("You were mentioned in Channel on Server") format!("{}: {}", data[3], data[4]).into()
// .message("Put mention here"); );
// match mailer.send(&email) { match mailer.send(mail) {
// Ok(_) => println!("Email sent successfully!"), Ok(_) => println!("Email sent successfully!"),
// Err(e) => panic!("Could not send email: {:?}", e), Err(e) => panic!("Could not send email: {:?}", e),
// } }
}
Err(_e) => (), Err(_e) => (),
} }
} }
} }

View file

@ -23,7 +23,10 @@ use irc_proto::command::{
CapSubCommand, CapSubCommand,
Command, Command,
}; };
use toml::map::Map; use toml::map::{
Map,
Keys
};
use irc_proto::message::Message; use irc_proto::message::Message;
use toml::value::Value; use toml::value::Value;
@ -101,8 +104,8 @@ fn get_irc_join_messages(config: &Value, queue: VecDeque<Message>)
Ok(queue) Ok(queue)
} }
fn handle_message(message: Message, nick: &String) fn handle_message(message: Message, nick: &String, client_names: Keys)
-> (Option<Message>, Option<[String; 3]>) { -> (Option<Message>, Option<[String; 4]>) {
let sender = match message.clone().source_nickname() { let sender = match message.clone().source_nickname() {
Some(s) => String::from(s), Some(s) => String::from(s),
None => String::from("anonymous") None => String::from("anonymous")
@ -130,21 +133,34 @@ fn handle_message(message: Message, nick: &String)
None None
) )
} }
return (None, Some([rec.clone(), sender.clone(), msg.clone()])) for c_name in client_names {
if msg.contains(c_name) {
return (None, Some([c_name.clone(),
rec.clone(),
sender.clone(),
msg.clone()
]))
}
}
}, },
_ => println!("{}", message.clone().to_string()) _ => println!("{}", message.clone().to_string())
} }
return (None, None) return (None, None)
} }
pub fn handle_server(config: Value, tx: Sender<[String; 4]>) pub fn handle_server(config: Value, tx: Sender<[String; 5]>)
-> Result<(), Box<dyn std::error::Error>> { -> Result<(), Box<dyn std::error::Error>> {
let server_name = config.get("server").unwrap().as_str() let server_name = config.get("server").unwrap().as_str()
.ok_or("Could not get server adress from config")?; .ok_or("Could not get server adress from config")?;
let nick = config.get("nickname").unwrap().as_str() let nick = config.get("nickname").unwrap().as_str()
.ok_or("Could not get nickname from config")?.to_owned(); .ok_or("Could not get nickname from config")?.to_owned();
let clients = config.get("clients").unwrap().as_table()
.get_or_insert(&Map::new()); let clients;
match config.get("clients").unwrap().as_table() {
Some(t) => clients = t.clone(),
None => clients = Map::new(),
}
let mut stream = super::connect::connect_irc(&config).unwrap(); let mut stream = super::connect::connect_irc(&config).unwrap();
let mut message_queue = get_irc_identify_messages(&config).unwrap(); let mut message_queue = get_irc_identify_messages(&config).unwrap();
@ -174,20 +190,21 @@ pub fn handle_server(config: Value, tx: Sender<[String; 4]>)
// Handle all incoming messages after joining the channels. // Handle all incoming messages after joining the channels.
loop { loop {
let message = stream.read()?; let message = stream.read()?;
let (answer, data) = handle_message(message, &nick); let (answer, data) = handle_message(message, &nick, clients.keys());
match answer { match answer {
Some(a) => stream.write(a).unwrap(), Some(a) => stream.write(a).unwrap(),
None => () None => ()
} }
match data { match data {
Some(d) => match clients.get(d[0].clone()) { Some(d) => match clients.get(&d[0]) {
Some(addr) => { Some(addr) => {
// There must be a better way to do this… // There must be a better way to do this…
let out = [ let out = [
addr.to_string(),
server_name.to_owned(), server_name.to_owned(),
d[0].clone(),
d[1].clone(), d[1].clone(),
d[2].clone(), d[2].clone(),
d[3].clone(),
]; ];
tx.send(out)? tx.send(out)?
}, },