Merge branch 'next' into released

This commit is contained in:
Graham Christensen 2018-01-14 15:02:27 -05:00
commit df5f44f61c
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
4 changed files with 117 additions and 9 deletions

91
ircbot/src/bin/ban.rs Normal file
View file

@ -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();
}

View file

@ -24,11 +24,18 @@ use ircbot::config;
use std::env; use std::env;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
struct Message { struct MessageToIRC {
target: String, target: String,
body: String body: String
} }
#[derive(Serialize, Deserialize, Debug)]
struct MessageFromIRC {
from: String,
sender: String,
body: String
}
fn main() { fn main() {
if let Err(_) = env::var("RUST_LOG") { if let Err(_) = env::var("RUST_LOG") {
env::set_var("RUST_LOG", "info"); env::set_var("RUST_LOG", "info");
@ -58,12 +65,12 @@ fn main() {
let consumer_name = channel.basic_consume( let consumer_name = channel.basic_consume(
move |chan: &mut Channel, _deliver: Deliver, _headers: BasicProperties, body: Vec<u8>| { move |chan: &mut Channel, _deliver: Deliver, _headers: BasicProperties, body: Vec<u8>| {
debug!("Got a message"); debug!("Got a message");
let msg: Result<Message, serde_json::Error> = serde_json::from_slice(&body); let msg: Result<MessageFromIRC, serde_json::Error> = serde_json::from_slice(&body);
if let Ok(msg) = msg { if let Ok(msg) = msg {
let trigger = msg.body.trim(); let trigger = msg.body.trim();
if let Some(response) = factoids.get(trigger) { if let Some(response) = factoids.get(trigger) {
let resp = Some(Message{ let resp = Some(MessageToIRC{
target: msg.target.clone(), target: msg.from.clone(),
body: response.clone(), body: response.clone(),
}); });

View file

@ -28,11 +28,18 @@ use std::thread;
use std::env; use std::env;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
struct Message { struct MessageToIRC {
target: String, target: String,
body: String body: String
} }
#[derive(Serialize, Deserialize, Debug)]
struct MessageFromIRC {
from: String,
sender: String,
body: String
}
fn main() { fn main() {
if let Err(_) = env::var("RUST_LOG") { if let Err(_) = env::var("RUST_LOG") {
env::set_var("RUST_LOG", "info"); env::set_var("RUST_LOG", "info");
@ -72,7 +79,7 @@ fn main() {
thread::spawn(move || { thread::spawn(move || {
let consumer_name = readchan.basic_consume( let consumer_name = readchan.basic_consume(
move |_channel: &mut Channel, _deliver: Deliver, _headers: BasicProperties, body: Vec<u8>| { move |_channel: &mut Channel, _deliver: Deliver, _headers: BasicProperties, body: Vec<u8>| {
let msg: Result<Message, serde_json::Error> = serde_json::from_slice(&body); let msg: Result<MessageToIRC, serde_json::Error> = serde_json::from_slice(&body);
if let Ok(msg) = msg { if let Ok(msg) = msg {
server.send_privmsg(&msg.target, &msg.body).unwrap(); server.send_privmsg(&msg.target, &msg.body).unwrap();
} }
@ -90,10 +97,13 @@ fn main() {
reader.for_each_incoming(|message| { reader.for_each_incoming(|message| {
match message.command { match message.command {
Command::PRIVMSG(ref _target, ref msg) => { Command::PRIVMSG(ref _target, ref msg) => {
let msg = serde_json::to_string(&Message{ let msg = serde_json::to_string(&MessageFromIRC{
target: message.response_target() from: message.response_target()
.expect("a response target for a privmsg") .expect("a response target for a privmsg")
.to_owned(), .to_owned(),
sender: message.source_nickname()
.expect("a source nickname for a privmsg")
.to_owned(),
body: msg.clone(), body: msg.clone(),
}).unwrap(); }).unwrap();

View file

@ -46,7 +46,7 @@ pub fn parse_line(text: &str) -> Option<Vec<Instruction>> {
Instruction::Build(Subset::NixOS, Instruction::Build(Subset::NixOS,
right right
.into_iter() .into_iter()
.map(|attr| format!("tests.{}", attr)) .map(|attr| format!("tests.{}.x86_64-linux", attr))
.collect() .collect()
) )
); );