first commit

main
serxoz 2022-11-28 12:21:55 +01:00
commit 6ffc0e891a
4 changed files with 1328 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target/

1240
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

12
Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "irc420"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
failure = "0.1.8"
futures = "0.3.25"
irc = "0.15.0"
tokio = { version = "1.22.0", features = ["full"] }

75
src/main.rs Normal file
View File

@ -0,0 +1,75 @@
use irc::client::prelude::*;
use futures::prelude::*;
use std::str;
#[tokio::main]
async fn main() -> Result<(), failure::Error> {
let config = Config {
nickname: Some("420".to_owned()),
server: Some("xinu.me".to_owned()),
channels: vec!["#bots".to_owned()],
..Config::default()
};
let mut client = Client::from_config(config).await?;
client.identify()?;
let mut stream = client.stream()?;
while let Some(message) = stream.next().await.transpose()? {
print!("{}", message);
if let Command::PRIVMSG(ref orixen, ref msg) = message.command {
if orixen.starts_with("#") {
// ven de un canal
// send_privmsg comes from ClientExt
// if msg.contains(&*client.current_nickname()) {
// client.send_privmsg(&orixen, "beep boop").unwrap();
// }
} else {
// ven de un mensaxe privado
let cmd: &str = &msg[..];
match cmd {
"!pirate" => {
client.send_quit("Sayonara, baby.")?;
},
&_ => {
// comando de shell, executase e devolve a saída
use std::process::Command;
let output = if cfg!(target_os = "windows") {
Command::new("cmd")
.args(["/C", "echo hello"])
.output()
.expect("failed to execute process")
} else {
Command::new("sh")
.arg("-c")
.arg(&cmd)
.output()
.expect("failed to execute process")
};
let out_parsed = str::from_utf8(&output.stdout).unwrap();
if out_parsed.contains("\n") {
for linea in out_parsed.split("\n"){
client.send_privmsg(
message.response_target().unwrap(),
linea
).unwrap();
// poñer un sleep para evitar flood
}
} else {
client.send_privmsg(
message.response_target().unwrap(),
out_parsed
).unwrap();
}
}
}
}
}
}
Ok(())
}