|
|
|
@ -333,27 +333,9 @@ fn main() {
|
|
|
|
|
.command(
|
|
|
|
|
Command::new("bot")
|
|
|
|
|
.usage("atr bot {}")
|
|
|
|
|
.description("bot\n\t\t\t$ atr bot --chat")
|
|
|
|
|
.description("bot\n\t\t\t$ atr bot")
|
|
|
|
|
.alias("b")
|
|
|
|
|
.action(bot)
|
|
|
|
|
.flag(
|
|
|
|
|
Flag::new("chat", FlagType::Bool)
|
|
|
|
|
.description("bot-chat flag")
|
|
|
|
|
.alias("c"),
|
|
|
|
|
)
|
|
|
|
|
.flag(
|
|
|
|
|
Flag::new("deepl", FlagType::Bool)
|
|
|
|
|
.description("bot-deepl flag")
|
|
|
|
|
.alias("d"),
|
|
|
|
|
)
|
|
|
|
|
.flag(
|
|
|
|
|
Flag::new("ja", FlagType::Bool)
|
|
|
|
|
.description("deepl japanese flag")
|
|
|
|
|
)
|
|
|
|
|
.flag(
|
|
|
|
|
Flag::new("en", FlagType::Bool)
|
|
|
|
|
.description("deepl english flag")
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.command(
|
|
|
|
|
Command::new("test")
|
|
|
|
@ -947,16 +929,30 @@ fn bot_run(_c: &Context) {
|
|
|
|
|
let reason = &n[i].reason;
|
|
|
|
|
let handle = &n[i].author.handle;
|
|
|
|
|
let read = n[i].isRead;
|
|
|
|
|
if reason == "mention" && handle == "syui.cf" && read == false {
|
|
|
|
|
if read == false && { reason == "mention" || reason == "reply" } {
|
|
|
|
|
let time = &n[i].indexedAt;
|
|
|
|
|
let cid = &n[i].cid;
|
|
|
|
|
let uri = &n[i].uri;
|
|
|
|
|
if ! n[i].record.text.is_none() {
|
|
|
|
|
let text = &n[i].record.text.as_ref().unwrap();
|
|
|
|
|
let vec: Vec<&str> = text.split_whitespace().collect();
|
|
|
|
|
if vec.len() > 2 {
|
|
|
|
|
if reason == "reply" && handle == "syui.cf" || handle == "jik.wtf" || handle == "kappa.seijin.jp" {
|
|
|
|
|
let prompt = &vec[0..].join(" ");
|
|
|
|
|
println!("prompt:{}", prompt);
|
|
|
|
|
println!("cid:{}, uri:{}", cid, uri);
|
|
|
|
|
println!("{}", text);
|
|
|
|
|
let model = "text-davinci-003";
|
|
|
|
|
let str_openai = openai::post_request(prompt.to_string(),model.to_string()).await;
|
|
|
|
|
println!("{}", str_openai);
|
|
|
|
|
let text_limit = char_c(str_openai);
|
|
|
|
|
let str_rep = at_reply::post_request(text_limit.to_string(), cid.to_string(), uri.to_string()).await;
|
|
|
|
|
println!("{}", str_rep);
|
|
|
|
|
let str_notify = at_notify_read::post_request(time.to_string()).await;
|
|
|
|
|
println!("{}", str_notify);
|
|
|
|
|
}
|
|
|
|
|
if vec.len() > 1 {
|
|
|
|
|
let com = vec[1].trim().to_string();
|
|
|
|
|
if com == "/chat" {
|
|
|
|
|
if com == "/chat" && { handle == "syui.cf" || handle == "jik.wtf" || handle == "kappa.seijin.jp" } {
|
|
|
|
|
let prompt = &vec[2..].join(" ");
|
|
|
|
|
println!("cmd:{}, prompt:{}", com, prompt);
|
|
|
|
|
println!("cid:{}, uri:{}", cid, uri);
|
|
|
|
@ -969,81 +965,95 @@ fn bot_run(_c: &Context) {
|
|
|
|
|
println!("{}", str_rep);
|
|
|
|
|
let str_notify = at_notify_read::post_request(time.to_string()).await;
|
|
|
|
|
println!("{}", str_notify);
|
|
|
|
|
}
|
|
|
|
|
if com == "/deepl" {
|
|
|
|
|
let lang = &vec[2].to_string();
|
|
|
|
|
let prompt = &vec[3..].join(" ");
|
|
|
|
|
println!("cmd:{}, lang:{}, prompt:{}", com, lang, prompt);
|
|
|
|
|
println!("cid:{}, uri:{}", cid, uri);
|
|
|
|
|
println!("{}", text);
|
|
|
|
|
let str_deepl = deepl::post_request(prompt.to_string(),lang.to_string()).await;
|
|
|
|
|
println!("{}", str_deepl);
|
|
|
|
|
let text_limit = char_c(str_deepl);
|
|
|
|
|
let str_rep = at_reply::post_request(text_limit.to_string(), cid.to_string(), uri.to_string()).await;
|
|
|
|
|
println!("{}", str_rep);
|
|
|
|
|
let str_notify = at_notify_read::post_request(time.to_string()).await;
|
|
|
|
|
println!("{}", str_notify);
|
|
|
|
|
}
|
|
|
|
|
if com == "/sh" {
|
|
|
|
|
let str_notify = at_notify_read::post_request(time.to_string()).await;
|
|
|
|
|
println!("{}", str_notify);
|
|
|
|
|
|
|
|
|
|
let prompt = &vec[2..].join(" ");
|
|
|
|
|
println!("cmd:{}, prompt:{}", com, prompt);
|
|
|
|
|
println!("cid:{}, uri:{}", cid, uri);
|
|
|
|
|
println!("{}", text);
|
|
|
|
|
let file = "/.config/atr/scpt/arch.zsh";
|
|
|
|
|
let mut f = shellexpand::tilde("~").to_string();
|
|
|
|
|
f.push_str(&file);
|
|
|
|
|
use std::process::Command;
|
|
|
|
|
let output = Command::new(&f).arg(&prompt).output().expect("zsh");
|
|
|
|
|
let d = String::from_utf8_lossy(&output.stdout);
|
|
|
|
|
let d = d.to_string();
|
|
|
|
|
println!("{}", d);
|
|
|
|
|
let text_limit = char_c(d);
|
|
|
|
|
let str_rep = at_reply::post_request(text_limit.to_string(), cid.to_string(), uri.to_string()).await;
|
|
|
|
|
println!("{}", str_rep);
|
|
|
|
|
}
|
|
|
|
|
if com == "/diffusion" {
|
|
|
|
|
let str_notify = at_notify_read::post_request(time.to_string()).await;
|
|
|
|
|
println!("{}", str_notify);
|
|
|
|
|
|
|
|
|
|
let prompt = &vec[2..].join(" ");
|
|
|
|
|
println!("cmd:{}, prompt:{}", com, prompt);
|
|
|
|
|
println!("cid:{}, uri:{}", cid, uri);
|
|
|
|
|
println!("{}", text);
|
|
|
|
|
let file = "/.config/atr/scpt/diffusion.zsh";
|
|
|
|
|
let mut f = shellexpand::tilde("~").to_string();
|
|
|
|
|
f.push_str(&file);
|
|
|
|
|
use std::process::Command;
|
|
|
|
|
let output = Command::new(&f).arg(&prompt).output().expect("zsh");
|
|
|
|
|
let d = String::from_utf8_lossy(&output.stdout);
|
|
|
|
|
let d = d.to_string();
|
|
|
|
|
println!("{}", d);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//media upload { #efactoring }
|
|
|
|
|
let file = "/.config/atr/scpt/png/t.jpg";
|
|
|
|
|
let mut f = shellexpand::tilde("~").to_string();
|
|
|
|
|
f.push_str(&file);
|
|
|
|
|
let token = token_toml(&"access");
|
|
|
|
|
let atoken = "Authorization: Bearer ".to_owned() + &token;
|
|
|
|
|
let con = "Content-Type: image/png";
|
|
|
|
|
let url = url(&"upload_blob");
|
|
|
|
|
let f = "@".to_owned() + &f;
|
|
|
|
|
let output = Command::new("curl").arg("-X").arg("POST").arg("-sL").arg("-H").arg(&con).arg("-H").arg(&atoken).arg("--data-binary").arg(&f).arg(&url).output().expect("curl");
|
|
|
|
|
let d = String::from_utf8_lossy(&output.stdout);
|
|
|
|
|
let d = d.to_string();
|
|
|
|
|
let mid: Cid = serde_json::from_str(&d).unwrap();
|
|
|
|
|
let mid = mid.cid;
|
|
|
|
|
println!("{}", mid);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let text_limit = "#stablediffusion";
|
|
|
|
|
let itype = "image/jpeg";
|
|
|
|
|
let str_rep = at_reply_media::post_request(text_limit.to_string(), cid.to_string(), uri.to_string(), mid.to_string(), itype.to_string()).await;
|
|
|
|
|
println!("{}", str_rep);
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
if com == "/deepl" && { handle == "syui.cf" || handle == "jik.wtf" || handle == "kappa.seijin.jp" } {
|
|
|
|
|
let lang = &vec[2].to_string();
|
|
|
|
|
let prompt = &vec[3..].join(" ");
|
|
|
|
|
println!("cmd:{}, lang:{}, prompt:{}", com, lang, prompt);
|
|
|
|
|
println!("cid:{}, uri:{}", cid, uri);
|
|
|
|
|
println!("{}", text);
|
|
|
|
|
let str_deepl = deepl::post_request(prompt.to_string(),lang.to_string()).await;
|
|
|
|
|
println!("{}", str_deepl);
|
|
|
|
|
let text_limit = char_c(str_deepl);
|
|
|
|
|
let str_rep = at_reply::post_request(text_limit.to_string(), cid.to_string(), uri.to_string()).await;
|
|
|
|
|
println!("{}", str_rep);
|
|
|
|
|
let str_notify = at_notify_read::post_request(time.to_string()).await;
|
|
|
|
|
println!("{}", str_notify);
|
|
|
|
|
} else
|
|
|
|
|
if com == "/sh" && handle == "syui.cf" {
|
|
|
|
|
let str_notify = at_notify_read::post_request(time.to_string()).await;
|
|
|
|
|
println!("{}", str_notify);
|
|
|
|
|
|
|
|
|
|
let prompt = &vec[2..].join(" ");
|
|
|
|
|
println!("cmd:{}, prompt:{}", com, prompt);
|
|
|
|
|
println!("cid:{}, uri:{}", cid, uri);
|
|
|
|
|
println!("{}", text);
|
|
|
|
|
let file = "/.config/atr/scpt/arch.zsh";
|
|
|
|
|
let mut f = shellexpand::tilde("~").to_string();
|
|
|
|
|
f.push_str(&file);
|
|
|
|
|
use std::process::Command;
|
|
|
|
|
let output = Command::new(&f).arg(&prompt).output().expect("zsh");
|
|
|
|
|
let d = String::from_utf8_lossy(&output.stdout);
|
|
|
|
|
let d = d.to_string();
|
|
|
|
|
println!("{}", d);
|
|
|
|
|
let text_limit = char_c(d);
|
|
|
|
|
let str_rep = at_reply::post_request(text_limit.to_string(), cid.to_string(), uri.to_string()).await;
|
|
|
|
|
println!("{}", str_rep);
|
|
|
|
|
} else
|
|
|
|
|
if com == "/diffusion" && { handle == "syui.cf" || handle == "jik.wtf" || handle == "kappa.seijin.jp" } {
|
|
|
|
|
let str_notify = at_notify_read::post_request(time.to_string()).await;
|
|
|
|
|
println!("{}", str_notify);
|
|
|
|
|
|
|
|
|
|
let prompt = &vec[2..].join(" ");
|
|
|
|
|
println!("cmd:{}, prompt:{}", com, prompt);
|
|
|
|
|
println!("cid:{}, uri:{}", cid, uri);
|
|
|
|
|
println!("{}", text);
|
|
|
|
|
let file = "/.config/atr/scpt/diffusion.zsh";
|
|
|
|
|
let mut f = shellexpand::tilde("~").to_string();
|
|
|
|
|
f.push_str(&file);
|
|
|
|
|
use std::process::Command;
|
|
|
|
|
let output = Command::new(&f).arg(&prompt).output().expect("zsh");
|
|
|
|
|
let d = String::from_utf8_lossy(&output.stdout);
|
|
|
|
|
let d = d.to_string();
|
|
|
|
|
println!("{}", d);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//media upload { #efactoring }
|
|
|
|
|
let file = "/.config/atr/scpt/png/t.jpg";
|
|
|
|
|
let mut f = shellexpand::tilde("~").to_string();
|
|
|
|
|
f.push_str(&file);
|
|
|
|
|
let token = token_toml(&"access");
|
|
|
|
|
let atoken = "Authorization: Bearer ".to_owned() + &token;
|
|
|
|
|
let con = "Content-Type: image/png";
|
|
|
|
|
let url = url(&"upload_blob");
|
|
|
|
|
let f = "@".to_owned() + &f;
|
|
|
|
|
let output = Command::new("curl").arg("-X").arg("POST").arg("-sL").arg("-H").arg(&con).arg("-H").arg(&atoken).arg("--data-binary").arg(&f).arg(&url).output().expect("curl");
|
|
|
|
|
let d = String::from_utf8_lossy(&output.stdout);
|
|
|
|
|
let d = d.to_string();
|
|
|
|
|
let mid: Cid = serde_json::from_str(&d).unwrap();
|
|
|
|
|
let mid = mid.cid;
|
|
|
|
|
println!("{}", mid);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let text_limit = "#stablediffusion";
|
|
|
|
|
let itype = "image/jpeg";
|
|
|
|
|
let str_rep = at_reply_media::post_request(text_limit.to_string(), cid.to_string(), uri.to_string(), mid.to_string(), itype.to_string()).await;
|
|
|
|
|
println!("{}", str_rep);
|
|
|
|
|
} else
|
|
|
|
|
if reason == "mention" && handle == "syui.cf" || handle == "jik.wtf" || handle == "kappa.seijin.jp" {
|
|
|
|
|
let prompt = &vec[1..].join(" ");
|
|
|
|
|
println!("prompt:{}", prompt);
|
|
|
|
|
println!("cid:{}, uri:{}", cid, uri);
|
|
|
|
|
println!("{}", text);
|
|
|
|
|
let model = "text-davinci-003";
|
|
|
|
|
let str_openai = openai::post_request(prompt.to_string(),model.to_string()).await;
|
|
|
|
|
println!("{}", str_openai);
|
|
|
|
|
let text_limit = char_c(str_openai);
|
|
|
|
|
let str_rep = at_reply::post_request(text_limit.to_string(), cid.to_string(), uri.to_string()).await;
|
|
|
|
|
println!("{}", str_rep);
|
|
|
|
|
let str_notify = at_notify_read::post_request(time.to_string()).await;
|
|
|
|
|
println!("{}", str_notify);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1054,10 +1064,8 @@ fn bot_run(_c: &Context) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn bot(c: &Context) {
|
|
|
|
|
if c.bool_flag("chat") || c.bool_flag("deepl") {
|
|
|
|
|
aa().unwrap();
|
|
|
|
|
bot_run(c);
|
|
|
|
|
}
|
|
|
|
|
aa().unwrap();
|
|
|
|
|
bot_run(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// atr test
|
|
|
|
@ -1176,3 +1184,4 @@ fn test(_c: &Context) {
|
|
|
|
|
};
|
|
|
|
|
tokio::runtime::Runtime::new().unwrap().block_on(h);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|