2019-08-27 15:05:51 +02:00
|
|
|
use futures::prelude::*;
|
2018-01-02 03:20:36 +01:00
|
|
|
use irc::client::prelude::*;
|
|
|
|
|
2019-08-27 15:05:51 +02:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> irc::error::Result<()> {
|
2018-01-02 03:20:36 +01:00
|
|
|
let config = Config {
|
2020-03-07 06:17:35 +01:00
|
|
|
nickname: Some("pickles".to_owned()),
|
2020-07-23 19:40:10 +02:00
|
|
|
server: Some("chat.freenode.net".to_owned()),
|
2019-09-29 00:54:07 +02:00
|
|
|
channels: vec!["#rust-spam".to_owned()],
|
2018-01-02 03:20:36 +01:00
|
|
|
burst_window_length: Some(4),
|
|
|
|
max_messages_in_burst: Some(4),
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
2019-08-27 15:05:51 +02:00
|
|
|
let mut client = Client::from_config(config).await?;
|
|
|
|
client.identify()?;
|
|
|
|
|
|
|
|
let mut stream = client.stream()?;
|
2020-03-07 06:17:35 +01:00
|
|
|
let sender = client.sender();
|
2019-08-27 15:05:51 +02:00
|
|
|
|
|
|
|
loop {
|
|
|
|
let message = stream.select_next_some().await?;
|
2018-01-02 03:20:36 +01:00
|
|
|
|
2018-01-28 02:00:04 +01:00
|
|
|
if let Command::PRIVMSG(ref target, ref msg) = message.command {
|
2021-11-14 21:03:16 +01:00
|
|
|
if msg.starts_with(client.current_nickname()) {
|
2018-01-28 02:00:04 +01:00
|
|
|
let tokens: Vec<_> = msg.split(' ').collect();
|
|
|
|
if tokens.len() > 2 {
|
|
|
|
let n = tokens[0].len() + tokens[1].len() + 2;
|
|
|
|
if let Ok(count) = tokens[1].parse::<u8>() {
|
|
|
|
for _ in 0..count {
|
2020-03-07 06:17:35 +01:00
|
|
|
sender.send_privmsg(
|
2018-01-28 02:00:04 +01:00
|
|
|
message.response_target().unwrap_or(target),
|
2019-08-27 15:05:51 +02:00
|
|
|
&msg[n..],
|
|
|
|
)?;
|
2018-01-02 03:20:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-27 15:05:51 +02:00
|
|
|
}
|
2018-01-02 03:20:36 +01:00
|
|
|
}
|