From bc5c1ba69b5adaadbddcf87085cf5e7f37140220 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 10 Jan 2018 19:55:05 -0500 Subject: [PATCH 1/3] Split to / from message formats for the bot --- ircbot/src/bin/factoids.rs | 15 +++++++++++---- ircbot/src/bin/gateway.rs | 18 ++++++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/ircbot/src/bin/factoids.rs b/ircbot/src/bin/factoids.rs index 6f7a321..3082fb1 100644 --- a/ircbot/src/bin/factoids.rs +++ b/ircbot/src/bin/factoids.rs @@ -24,11 +24,18 @@ use ircbot::config; use std::env; #[derive(Serialize, Deserialize, Debug)] -struct Message { +struct MessageToIRC { target: String, body: String } +#[derive(Serialize, Deserialize, Debug)] +struct MessageFromIRC { + from: String, + sender: String, + body: String +} + fn main() { if let Err(_) = env::var("RUST_LOG") { env::set_var("RUST_LOG", "info"); @@ -58,12 +65,12 @@ fn main() { let consumer_name = channel.basic_consume( move |chan: &mut Channel, _deliver: Deliver, _headers: BasicProperties, body: Vec| { debug!("Got a message"); - let msg: Result = serde_json::from_slice(&body); + let msg: Result = serde_json::from_slice(&body); if let Ok(msg) = msg { let trigger = msg.body.trim(); if let Some(response) = factoids.get(trigger) { - let resp = Some(Message{ - target: msg.target.clone(), + let resp = Some(MessageToIRC{ + target: msg.from.clone(), body: response.clone(), }); diff --git a/ircbot/src/bin/gateway.rs b/ircbot/src/bin/gateway.rs index 67aaaff..b1341aa 100644 --- a/ircbot/src/bin/gateway.rs +++ b/ircbot/src/bin/gateway.rs @@ -28,11 +28,18 @@ use std::thread; use std::env; #[derive(Serialize, Deserialize, Debug)] -struct Message { +struct MessageToIRC { target: String, body: String } +#[derive(Serialize, Deserialize, Debug)] +struct MessageFromIRC { + from: String, + sender: String, + body: String +} + fn main() { if let Err(_) = env::var("RUST_LOG") { env::set_var("RUST_LOG", "info"); @@ -72,7 +79,7 @@ fn main() { thread::spawn(move || { let consumer_name = readchan.basic_consume( move |_channel: &mut Channel, _deliver: Deliver, _headers: BasicProperties, body: Vec| { - let msg: Result = serde_json::from_slice(&body); + let msg: Result = serde_json::from_slice(&body); if let Ok(msg) = msg { server.send_privmsg(&msg.target, &msg.body).unwrap(); } @@ -90,10 +97,13 @@ fn main() { reader.for_each_incoming(|message| { match message.command { Command::PRIVMSG(ref _target, ref msg) => { - let msg = serde_json::to_string(&Message{ - target: message.response_target() + let msg = serde_json::to_string(&MessageFromIRC{ + from: message.response_target() .expect("a response target for a privmsg") .to_owned(), + sender: message.source_nickname() + .expect("a source nickname for a privmsg") + .to_owned(), body: msg.clone(), }).unwrap(); From 4a84900deea6d08856fe3038971fd49a3797d328 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 10 Jan 2018 19:55:57 -0500 Subject: [PATCH 2/3] check in the ban bot --- ircbot/src/bin/ban.rs | 91 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 ircbot/src/bin/ban.rs diff --git a/ircbot/src/bin/ban.rs b/ircbot/src/bin/ban.rs new file mode 100644 index 0000000..2fc2705 --- /dev/null +++ b/ircbot/src/bin/ban.rs @@ -0,0 +1,91 @@ +#[macro_use] +extern crate serde_derive; +extern crate serde; +extern crate serde_json; +extern crate ircbot; +extern crate irc; +extern crate amqp; +extern crate env_logger; + +#[macro_use] +extern crate log; +use irc::client::server::Server; +use irc::client::prelude::Command; +use irc::client::prelude::ServerExt; +use irc::client::prelude::IrcServer; +use irc::proto::mode::Mode; +use irc::proto::mode::ChannelMode; + +use ircbot::config; + +use std::thread; +use std::env; + +#[derive(Serialize, Deserialize, Debug)] +struct Message { + target: String, + body: String +} + +fn main() { + if let Err(_) = env::var("RUST_LOG") { + env::set_var("RUST_LOG", "info"); + env_logger::init().unwrap(); + info!("Defaulting RUST_LOG environment variable to info"); + } else { + env_logger::init().unwrap(); + } + + let cfg = config::load(env::args().nth(1).unwrap().as_ref()); + + + let server = IrcServer::from_config(cfg.irc_config()).unwrap(); + server.identify().unwrap(); + let reader = server.clone(); + + reader.for_each_incoming(|message| { + match message.command { + Command::PRIVMSG(ref _target, ref msg) => { + let badwords: Vec<&str> = vec![ + "▄", + "companieshouse.gov.uk", + "christel sold", + "freenode to private", + "snoonet", + "nigger", + "chan freenode", + "supernets.org", + "flooding challenge", + "details!!", + ]; + + if let Some(from) = message.source_nickname() { + if let Some(inchan) = message.response_target() { + for word in badwords { + if msg.to_lowercase().contains(word) { + server.send_mode( + inchan, + &[ + Mode::Plus( + ChannelMode::Ban, + Some(from.to_owned()) + ) + ] + ); + server.send_kick( + inchan, + from, + "PM gchristensen to dispute this" + ); + println!("Banning: {:?}, {:?}", from, msg); + } + } + } + } + } + _ => { + print!("{:?}\n", message.command); + }, + } + }).unwrap(); +} From b17005eabbdfbb85fe8f1576fb1b8c02013579ef Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 10 Jan 2018 19:56:18 -0500 Subject: [PATCH 3/3] fix tests being run for aarch64 and linuxon linux --- ofborg/src/commentparser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ofborg/src/commentparser.rs b/ofborg/src/commentparser.rs index 526392c..383e6c6 100644 --- a/ofborg/src/commentparser.rs +++ b/ofborg/src/commentparser.rs @@ -46,7 +46,7 @@ pub fn parse_line(text: &str) -> Option> { Instruction::Build(Subset::NixOS, right .into_iter() - .map(|attr| format!("tests.{}", attr)) + .map(|attr| format!("tests.{}.x86_64-linux", attr)) .collect() ) );