fix bot
This commit is contained in:
parent
8d3a7e6af6
commit
087310e94f
46
src/bot.rs
46
src/bot.rs
@ -1,9 +1,11 @@
|
|||||||
use seahorse::Context;
|
use seahorse::Context;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
use crate::refresh;
|
use crate::refresh;
|
||||||
use crate::reply;
|
use crate::reply;
|
||||||
use crate::reply_link;
|
use crate::reply_link;
|
||||||
use crate::notify;
|
use crate::notify;
|
||||||
|
use crate::openai;
|
||||||
use crate::notify_read;
|
use crate::notify_read;
|
||||||
|
|
||||||
use crate::data::log_file;
|
use crate::data::log_file;
|
||||||
@ -49,7 +51,7 @@ pub fn c_bot(c: &Context) {
|
|||||||
text = &n[i].record.text.as_ref().unwrap();
|
text = &n[i].record.text.as_ref().unwrap();
|
||||||
}
|
}
|
||||||
let vec: Vec<&str> = text.split_whitespace().collect();
|
let vec: Vec<&str> = text.split_whitespace().collect();
|
||||||
let rep_com = &vec[0..].join(" ");
|
let com = vec[1].trim().to_string();
|
||||||
let handlev: Vec<&str> = handle.split('.').collect();
|
let handlev: Vec<&str> = handle.split('.').collect();
|
||||||
let mut handlev = handlev[0].trim().to_string();
|
let mut handlev = handlev[0].trim().to_string();
|
||||||
|
|
||||||
@ -57,10 +59,20 @@ pub fn c_bot(c: &Context) {
|
|||||||
let s = 0;
|
let s = 0;
|
||||||
let mut e = link.chars().count();
|
let mut e = link.chars().count();
|
||||||
|
|
||||||
use std::process::Command;
|
let mut prompt = "none".to_string();
|
||||||
|
if reason == "mention" {
|
||||||
|
prompt = vec[2..].join(" ");
|
||||||
|
} else if reason == "reply" {
|
||||||
|
prompt = vec[1..].join(" ");
|
||||||
|
}
|
||||||
|
if prompt.is_empty() == false {
|
||||||
|
println!("{}", prompt);
|
||||||
|
}
|
||||||
|
|
||||||
if check_cid == false && { reason == "mention" || reason == "reply" } || check_cid_run == false && { reason == "mention" || reason == "reply" } {
|
if check_cid == false && { reason == "mention" || reason == "reply" } || check_cid_run == false && { reason == "mention" || reason == "reply" } {
|
||||||
|
|
||||||
w_cid(cid.to_string(), log_file(&"n2"), true);
|
w_cid(cid.to_string(), log_file(&"n2"), true);
|
||||||
if rep_com == "/did" || rep_com == "did" {
|
if com == "/did" || com == "did" {
|
||||||
let link = "https://plc.directory/".to_owned() + &did + &"/log";
|
let link = "https://plc.directory/".to_owned() + &did + &"/log";
|
||||||
let s = 0;
|
let s = 0;
|
||||||
let e = link.chars().count();
|
let e = link.chars().count();
|
||||||
@ -71,12 +83,11 @@ pub fn c_bot(c: &Context) {
|
|||||||
w_cid(cid.to_string(), log_file(&"n1"), true);
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
println!("{}", str_rep);
|
println!("{}", str_rep);
|
||||||
}
|
}
|
||||||
} else if rep_com == "/diffusers" || rep_com == "diffusers" {
|
} else if com == "/diffusers" || com == "diffusers" {
|
||||||
let prompt = &vec[2..].join(" ");
|
|
||||||
let _output = Command::new(data_scpt(&"diffusers")).arg(&did).arg(&prompt).output().expect("zsh");
|
let _output = Command::new(data_scpt(&"diffusers")).arg(&did).arg(&prompt).output().expect("zsh");
|
||||||
let _output = Command::new(data_scpt(&"at_img")).arg(&cid).arg(&uri).output().expect("zsh");
|
let _output = Command::new(data_scpt(&"at_img")).arg(&cid).arg(&uri).output().expect("zsh");
|
||||||
w_cid(cid.to_string(), log_file(&"n1"), true);
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
} else if rep_com.contains("占") == true || rep_com.contains("うらない") == true || rep_com.contains("うらなって") == true {
|
} else if prompt.contains("占") == true || prompt.contains("うらない") == true || prompt.contains("うらなって") == true {
|
||||||
let output = Command::new(data_scpt(&"card_fortune")).arg(&handle).arg(&did).arg(&cid).arg(&uri).output().expect("zsh");
|
let output = Command::new(data_scpt(&"card_fortune")).arg(&handle).arg(&did).arg(&cid).arg(&uri).output().expect("zsh");
|
||||||
let d = String::from_utf8_lossy(&output.stdout);
|
let d = String::from_utf8_lossy(&output.stdout);
|
||||||
let d = d.to_string();
|
let d = d.to_string();
|
||||||
@ -85,8 +96,7 @@ pub fn c_bot(c: &Context) {
|
|||||||
println!("{}", text_limit);
|
println!("{}", text_limit);
|
||||||
w_cid(cid.to_string(), log_file(&"n1"), true);
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
}
|
}
|
||||||
} else if rep_com == "/card" || rep_com == "card" {
|
} else if com == "/card" || com == "card" {
|
||||||
let prompt = &vec[2..].join(" ");
|
|
||||||
let output = Command::new(data_scpt(&"api_card.zsh")).arg(&handle).arg(&did).arg(&prompt).output().expect("zsh");
|
let output = Command::new(data_scpt(&"api_card.zsh")).arg(&handle).arg(&did).arg(&prompt).output().expect("zsh");
|
||||||
let d = String::from_utf8_lossy(&output.stdout);
|
let d = String::from_utf8_lossy(&output.stdout);
|
||||||
let dd = "\n".to_owned() + &d.to_string();
|
let dd = "\n".to_owned() + &d.to_string();
|
||||||
@ -104,8 +114,7 @@ pub fn c_bot(c: &Context) {
|
|||||||
}
|
}
|
||||||
w_cid(cid.to_string(), log_file(&"n1"), true);
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
}
|
}
|
||||||
} else if rep_com == "/fav" || rep_com == "fav" {
|
} else if com == "/fav" || com == "fav" {
|
||||||
let prompt = &vec[2..].join(" ");
|
|
||||||
let output = Command::new(data_scpt(&"api_fav")).arg(&handle).arg(&did).arg(&prompt).output().expect("zsh");
|
let output = Command::new(data_scpt(&"api_fav")).arg(&handle).arg(&did).arg(&prompt).output().expect("zsh");
|
||||||
let d = String::from_utf8_lossy(&output.stdout);
|
let d = String::from_utf8_lossy(&output.stdout);
|
||||||
let dd = "\n".to_owned() + &d.to_string();
|
let dd = "\n".to_owned() + &d.to_string();
|
||||||
@ -115,8 +124,7 @@ pub fn c_bot(c: &Context) {
|
|||||||
println!("{}", str_rep);
|
println!("{}", str_rep);
|
||||||
w_cid(cid.to_string(), log_file(&"n1"), true);
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
}
|
}
|
||||||
} else if rep_com == "/egg" || rep_com == "egg" {
|
} else if com == "/egg" || com == "egg" {
|
||||||
let prompt = &vec[2..].join(" ");
|
|
||||||
let output = Command::new(data_scpt(&"api_egg")).arg(&handle).arg(&did).arg(&prompt).output().expect("zsh");
|
let output = Command::new(data_scpt(&"api_egg")).arg(&handle).arg(&did).arg(&prompt).output().expect("zsh");
|
||||||
let d = String::from_utf8_lossy(&output.stdout);
|
let d = String::from_utf8_lossy(&output.stdout);
|
||||||
let dd = "\n".to_owned() + &d.to_string();
|
let dd = "\n".to_owned() + &d.to_string();
|
||||||
@ -126,8 +134,7 @@ pub fn c_bot(c: &Context) {
|
|||||||
println!("{}", str_rep);
|
println!("{}", str_rep);
|
||||||
w_cid(cid.to_string(), log_file(&"n1"), true);
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
}
|
}
|
||||||
} else if rep_com == "/nyan" || rep_com == "nyan" {
|
} else if com == "/nyan" || com == "nyan" {
|
||||||
let prompt = &vec[2..].join(" ");
|
|
||||||
let output = Command::new(data_scpt(&"nyancat")).arg(&handle).arg(&did).arg(&cid).arg(&uri).arg(&prompt).output().expect("zsh");
|
let output = Command::new(data_scpt(&"nyancat")).arg(&handle).arg(&did).arg(&cid).arg(&uri).arg(&prompt).output().expect("zsh");
|
||||||
let d = String::from_utf8_lossy(&output.stdout);
|
let d = String::from_utf8_lossy(&output.stdout);
|
||||||
let dd = "\n".to_owned() + &d.to_string();
|
let dd = "\n".to_owned() + &d.to_string();
|
||||||
@ -138,7 +145,7 @@ pub fn c_bot(c: &Context) {
|
|||||||
println!("{}", str_rep);
|
println!("{}", str_rep);
|
||||||
w_cid(cid.to_string(), log_file(&"n1"), true);
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
}
|
}
|
||||||
} else if rep_com == "/ten" || rep_com == "ten" {
|
} else if com == "/ten" || com == "ten" {
|
||||||
let option = &vec[2..].join(" ");
|
let option = &vec[2..].join(" ");
|
||||||
let sub_option = &vec[3..].join(" ");
|
let sub_option = &vec[3..].join(" ");
|
||||||
let output = Command::new(data_scpt(&"api_ten")).arg(&handle).arg(&did).arg(&cid).arg(&uri).arg(&option).arg(&sub_option).output().expect("zsh");
|
let output = Command::new(data_scpt(&"api_ten")).arg(&handle).arg(&did).arg(&cid).arg(&uri).arg(&option).arg(&sub_option).output().expect("zsh");
|
||||||
@ -150,7 +157,14 @@ pub fn c_bot(c: &Context) {
|
|||||||
println!("{}", str_rep);
|
println!("{}", str_rep);
|
||||||
w_cid(cid.to_string(), log_file(&"n1"), true);
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
// openai
|
||||||
|
let str_openai = openai::post_request(prompt.to_string()).await;
|
||||||
|
let text_limit = c_char(str_openai);
|
||||||
|
let str_rep = reply::post_request(text_limit.to_string(), cid.to_string(), uri.to_string(), cid_root.to_string(), uri_root.to_string()).await;
|
||||||
|
println!("{}", str_rep);
|
||||||
|
w_cid(cid.to_string(), log_file(&"n1"), true);
|
||||||
|
}
|
||||||
let str_notify = notify_read::post_request(time.to_string()).await;
|
let str_notify = notify_read::post_request(time.to_string()).await;
|
||||||
println!("{}", str_notify);
|
println!("{}", str_notify);
|
||||||
println!("---");
|
println!("---");
|
||||||
|
Loading…
Reference in New Issue
Block a user