1
0

fix
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 5s

This commit is contained in:
syui 2024-04-13 06:23:58 +09:00
parent 3e7703c573
commit 9bbe699ed1
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
3 changed files with 82 additions and 5 deletions

View File

@ -550,12 +550,19 @@ pub fn c_bot_feed(c: &Context) {
let mut link = "https://card.syui.ai/".to_owned() + &handlev;
let s = 0;
let mut e = link.chars().count();
let mut prompt_sub = "".to_string();
let com = vec[0].trim().to_string();
let prompt = vec[1..].join(" ");
if vec.len() > 1 {
prompt_sub = vec[2..].join(" ");
let mut prompt = "".to_string();
let mut prompt_sub = "".to_string();
let mut prompt_chat = "".to_string();
if com == "@ai" {
prompt_chat = vec[1..].join(" ");
} else {
prompt = vec[1..].join(" ");
if vec.len() > 1 {
prompt_sub = vec[2..].join(" ");
}
}
if prompt.is_empty() == false || com.is_empty() == false {
@ -924,6 +931,19 @@ pub fn c_bot_feed(c: &Context) {
println!("{}", str_rep);
w_cid(cid.to_string(), log_file(&"n1"), true);
}
} else if com == "@ai" {
let str_openai = openai::post_request(prompt_chat.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);
}
println!("---");
}

33
src/delete_record.rs Normal file
View File

@ -0,0 +1,33 @@
extern crate reqwest;
use crate::data_toml;
use crate::data_refresh;
use crate::url;
use serde_json::json;
pub async fn post_request(rkey: String, col: String) -> String {
let token = data_refresh(&"access");
//let did = data_toml(&"did");
let handle = data_toml(&"handle");
let url = url(&"record_delete");
let post = Some(json!({
"repo": handle.to_string(),
"rkey": rkey.to_string(),
"collection": col.to_string()
}));
let client = reqwest::Client::new();
let res = client
.post(url)
.json(&post)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
return res;
}

View File

@ -39,6 +39,7 @@ pub mod session;
pub mod timeline_author;
pub mod token;
pub mod feed_get;
pub mod delete_record;
fn main() {
let args: Vec<String> = env::args().collect();
@ -125,6 +126,16 @@ fn main() {
.alias("l"),
)
)
.command(
Command::new("delete")
.description("d <rkey>")
.alias("d")
.action(delete)
.flag(
Flag::new("col", FlagType::String)
.alias("c"),
)
)
.command(
Command::new("like")
.description("like <cid> -u <uri>")
@ -415,6 +426,19 @@ fn post(c: &Context) {
return res;
}
fn delete(c: &Context) {
refresh(c);
let m = c.args[0].to_string();
let h = async {
if let Ok(col) = c.string_flag("col") {
let str = delete_record::post_request(m.to_string(), col);
println!("{}", str.await);
}
};
let res = tokio::runtime::Runtime::new().unwrap().block_on(h);
return res;
}
fn like(c: &Context) {
refresh(c);
let m = c.args[0].to_string();