add card verify
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s
This commit is contained in:
parent
f4948f319e
commit
37a74b6c7d
88
src/main.rs
88
src/main.rs
@ -31,6 +31,7 @@ pub mod openai;
|
|||||||
pub mod post;
|
pub mod post;
|
||||||
pub mod post_link;
|
pub mod post_link;
|
||||||
pub mod post_card;
|
pub mod post_card;
|
||||||
|
pub mod post_card_verify;
|
||||||
pub mod profile;
|
pub mod profile;
|
||||||
pub mod refresh;
|
pub mod refresh;
|
||||||
pub mod reply;
|
pub mod reply;
|
||||||
@ -157,7 +158,7 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.command(
|
.command(
|
||||||
Command::new("card")
|
Command::new("card")
|
||||||
.description("-v <at://verify> -i <int:id> -p <int:cp> -r <int:rank> -c <collection> -a <author>")
|
.description("-v <at://verify> -i <int:id> -p <int:cp> -r <int:rank> -c <collection> -a <author> -img <link> -rare <normal>")
|
||||||
.action(card)
|
.action(card)
|
||||||
.flag(
|
.flag(
|
||||||
Flag::new("id", FlagType::Int)
|
Flag::new("id", FlagType::Int)
|
||||||
@ -171,6 +172,9 @@ fn main() {
|
|||||||
Flag::new("rank", FlagType::Int)
|
Flag::new("rank", FlagType::Int)
|
||||||
.alias("r"),
|
.alias("r"),
|
||||||
)
|
)
|
||||||
|
.flag(
|
||||||
|
Flag::new("rare", FlagType::Int)
|
||||||
|
)
|
||||||
.flag(
|
.flag(
|
||||||
Flag::new("col", FlagType::String)
|
Flag::new("col", FlagType::String)
|
||||||
.alias("c"),
|
.alias("c"),
|
||||||
@ -183,6 +187,41 @@ fn main() {
|
|||||||
Flag::new("verify", FlagType::String)
|
Flag::new("verify", FlagType::String)
|
||||||
.alias("v"),
|
.alias("v"),
|
||||||
)
|
)
|
||||||
|
.flag(
|
||||||
|
Flag::new("img", FlagType::String)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.command(
|
||||||
|
Command::new("card-verify")
|
||||||
|
.description("<at://verify> -c <collection> -i <id> -p <cp> -r <rank> -rare <normal> -h <syui.ai> -d <did>")
|
||||||
|
.action(card_verify)
|
||||||
|
.flag(
|
||||||
|
Flag::new("col", FlagType::String)
|
||||||
|
.alias("c"),
|
||||||
|
)
|
||||||
|
.flag(
|
||||||
|
Flag::new("id", FlagType::Int)
|
||||||
|
.alias("i"),
|
||||||
|
)
|
||||||
|
.flag(
|
||||||
|
Flag::new("cp", FlagType::Int)
|
||||||
|
.alias("p"),
|
||||||
|
)
|
||||||
|
.flag(
|
||||||
|
Flag::new("rank", FlagType::Int)
|
||||||
|
.alias("r"),
|
||||||
|
)
|
||||||
|
.flag(
|
||||||
|
Flag::new("rare", FlagType::String)
|
||||||
|
)
|
||||||
|
.flag(
|
||||||
|
Flag::new("handle", FlagType::String)
|
||||||
|
.alias("handle"),
|
||||||
|
)
|
||||||
|
.flag(
|
||||||
|
Flag::new("did", FlagType::String)
|
||||||
|
.alias("did"),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
.command(
|
.command(
|
||||||
Command::new("like")
|
Command::new("like")
|
||||||
@ -504,32 +543,16 @@ fn like(c: &Context) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
//fn card(c: &Context) {
|
|
||||||
// refresh(c);
|
|
||||||
// let m = c.args[0].to_string();
|
|
||||||
// let h = async {
|
|
||||||
// let author = c.string_flag("author").unwrap_or_else(|_| "syui".to_string());
|
|
||||||
// let verify = c.string_flag("verify").unwrap_or_else(|_| "at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.post/3lafcod6drd2c".to_string());
|
|
||||||
// let col = c.string_flag("col").unwrap_or_else(|_| "ai.syui.card".to_string());
|
|
||||||
// let id = c.int_flag("id")?.try_into()?;
|
|
||||||
// let cp = c.int_flag("cp")?.try_into()?;
|
|
||||||
// let rank = c.int_flag("rank")?.try_into()?;
|
|
||||||
// let str = post_card::post_request(m, id, cp, rank, col, author);
|
|
||||||
// println!("{}", str.await);
|
|
||||||
// };
|
|
||||||
// let res = tokio::runtime::Runtime::new().unwrap().block_on(h);
|
|
||||||
// return res;
|
|
||||||
//}
|
|
||||||
|
|
||||||
async fn c_card(c: &Context) -> Result<(), Box<dyn std::error::Error>> {
|
async fn c_card(c: &Context) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
//let m = c.args[0].to_string();
|
//let m = c.args[0].to_string();
|
||||||
let author = c.string_flag("author").unwrap_or_else(|_| "syui".to_string());
|
let author = c.string_flag("author").unwrap_or_else(|_| "syui".to_string());
|
||||||
let verify = c.string_flag("verify").unwrap_or_else(|_| "at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.post/3lafcod6drd2c".to_string());
|
let verify = c.string_flag("verify").unwrap_or_else(|_| "at://did:plc:4hqjfn7m6n5hno3doamuhgef/ai.syui.card.verify/3lagpert5ca2w".to_string());
|
||||||
let col = c.string_flag("col").unwrap_or_else(|_| "ai.syui.card".to_string());
|
let col = c.string_flag("col").unwrap_or_else(|_| "ai.syui.card".to_string());
|
||||||
let rare = c.string_flag("rare").unwrap_or_else(|_| "normal".to_string());
|
//let img = c.string_flag("img").unwrap_or_else(|_| "bafkreigvcjc46qtelpc4wsg7fwf6qktbi6a23ouqiupth2r37zhrn7wbza".to_string());
|
||||||
let id = c.int_flag("id")?.try_into()?;
|
let id = c.int_flag("id")?.try_into()?;
|
||||||
let cp = c.int_flag("cp")?.try_into()?;
|
let cp = c.int_flag("cp")?.try_into()?;
|
||||||
let rank = c.int_flag("rank")?.try_into()?;
|
let rank = c.int_flag("rank")?.try_into()?;
|
||||||
|
let rare = c.string_flag("rare").unwrap_or_else(|_| "normal".to_string());
|
||||||
let str = post_card::post_request(verify, id, cp, rank, rare, col, author);
|
let str = post_card::post_request(verify, id, cp, rank, rare, col, author);
|
||||||
println!("{}", str.await);
|
println!("{}", str.await);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -546,6 +569,31 @@ fn card(c: &Context) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn c_card_verify(c: &Context) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let col = c.string_flag("col").unwrap_or_else(|_| "ai.syui.card.verify".to_string());
|
||||||
|
let img = c.string_flag("img").unwrap_or_else(|_| "bafkreigvcjc46qtelpc4wsg7fwf6qktbi6a23ouqiupth2r37zhrn7wbza".to_string());
|
||||||
|
let id = c.int_flag("id")?.try_into()?;
|
||||||
|
let cp = c.int_flag("cp")?.try_into()?;
|
||||||
|
let rank = c.int_flag("rank")?.try_into()?;
|
||||||
|
let rare = c.string_flag("rare").unwrap_or_else(|_| "normal".to_string());
|
||||||
|
let user_handle = c.string_flag("handle").unwrap_or_else(|_| "syui.ai".to_string());
|
||||||
|
let user_did = c.string_flag("did").unwrap_or_else(|_| "did:plc:uqzpqmrjnptsxezjx4xuh2mn".to_string());
|
||||||
|
let str = post_card_verify::post_request(col, img, id, cp, rank, rare, user_handle, user_did);
|
||||||
|
println!("{}", str.await);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn card_verify(c: &Context) {
|
||||||
|
refresh(c);
|
||||||
|
tokio::runtime::Runtime::new()
|
||||||
|
.unwrap()
|
||||||
|
.block_on(async {
|
||||||
|
if let Err(e) = c_card_verify(c).await {
|
||||||
|
eprintln!("Error: {}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn repost(c: &Context) {
|
fn repost(c: &Context) {
|
||||||
refresh(c);
|
refresh(c);
|
||||||
let m = c.args[0].to_string();
|
let m = c.args[0].to_string();
|
||||||
|
58
src/post_card_verify.rs
Normal file
58
src/post_card_verify.rs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
extern crate reqwest;
|
||||||
|
use crate::data_toml;
|
||||||
|
use crate::data_refresh;
|
||||||
|
use crate::url;
|
||||||
|
use iso8601_timestamp::Timestamp;
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
|
pub async fn post_request(col: String, img: String, id: i32, cp: i32, rank: i32, rare: String, user_handle: String, user_did: String) -> String {
|
||||||
|
let token = data_refresh(&"access");
|
||||||
|
let did = data_toml(&"did");
|
||||||
|
let handle = data_toml(&"handle");
|
||||||
|
let url = url(&"record_create");
|
||||||
|
let d = Timestamp::now_utc();
|
||||||
|
let d = d.to_string();
|
||||||
|
let link = "https://bsky.app/profile/yui.syui.ai".to_string();
|
||||||
|
let post = Some(json!({
|
||||||
|
"repo": handle.to_string(),
|
||||||
|
"did": did.to_string(),
|
||||||
|
"collection": col.to_string(),
|
||||||
|
"record": {
|
||||||
|
"id": id,
|
||||||
|
"cp": cp,
|
||||||
|
"rank": rank,
|
||||||
|
"rare": rare.to_string(),
|
||||||
|
"handle": user_handle.to_string(),
|
||||||
|
"did": user_did.to_string(),
|
||||||
|
"embed": {
|
||||||
|
"$type": "app.bsky.embed.external",
|
||||||
|
"external": {
|
||||||
|
"uri": link,
|
||||||
|
"thumb": {
|
||||||
|
"$type": "blob",
|
||||||
|
"ref": {
|
||||||
|
"$link": img.to_string()
|
||||||
|
},
|
||||||
|
"mimeType": "image/jpeg",
|
||||||
|
"size": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"createdAt": d.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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user