1
0

add feed watch
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s

This commit is contained in:
syui 2024-08-18 01:28:04 +09:00
parent 3904c576f0
commit 84efc31248
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
5 changed files with 110 additions and 1 deletions

@ -1 +1 @@
Subproject commit 7c80e30b3ed3bb2badc220e8fda3a28c55323ea9 Subproject commit 9cbca76fc7846495894b254881cde1f7dc0ae363

75
src/feed_watch.rs Normal file
View File

@ -0,0 +1,75 @@
use seahorse::Context;
//use crate::openai;
use crate::feed_get;
use crate::data::data_toml;
use crate::data::Timeline;
pub fn c_feed_watch(c: &Context) {
let mut feed = "at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.generator/cmd".to_string();
if c.string_flag("url").is_ok() {
feed = c.string_flag("url").unwrap();
}
let mut tag = "syai".to_string();
if c.string_flag("tag").is_ok() {
tag = c.string_flag("tag").unwrap();
}
let h = async {
let notify = feed_get::get_request(feed).await;
if notify == "err" {
return;
//refresh(c);
//notify = feed_get::get_request("at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.generator/cmd".to_string()).await;
}
let timeline: Timeline = serde_json::from_str(&notify).unwrap();
let n = timeline.feed;
let host = data_toml(&"host");
let length = &n.len();
let su = 0..*length;
for i in su {
let handle = &n[i].post.author.handle;
let did = &n[i].post.author.did;
let cid = &n[i].post.cid;
let uri = &n[i].post.uri;
let _time = &n[i].post.indexedAt;
let cid_root = cid;
let uri_root = uri;
let mut text = "";
if !n[i].post.record.text.is_none() {
text = &n[i].post.record.text.as_ref().unwrap();
}
let vec: Vec<&str> = text.split_whitespace().collect();
let com = vec[0].trim().to_string();
let mut prompt = "".to_string();
let mut prompt_sub = "".to_string();
if com == "@ai" || com == "/ai" || com == tag {
prompt_sub = 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 {
println!("{}", handle);
if c.bool_flag("debug") == true {
println!(
"cid:{}\nuri:{}\ncid_root:{}\nuri_root:{}\nhost:{}\ndid:{}",
cid, uri, cid_root, uri_root, host, did
);
}
println!("{}", prompt_sub);
println!("---");
}
}
};
let res = tokio::runtime::Runtime::new().unwrap().block_on(h);
return res;
}

View File

@ -11,6 +11,7 @@ use crate::data::data_refresh;
use crate::data::url; use crate::data::url;
use crate::data::w_cfg; use crate::data::w_cfg;
use crate::data::w_refresh; use crate::data::w_refresh;
use crate::feed_watch::c_feed_watch;
use data::ProfileIdentityResolve; use data::ProfileIdentityResolve;
@ -39,6 +40,7 @@ pub mod session;
pub mod timeline_author; pub mod timeline_author;
pub mod token; pub mod token;
pub mod feed_get; pub mod feed_get;
pub mod feed_watch;
pub mod delete_record; pub mod delete_record;
fn main() { fn main() {
@ -70,6 +72,22 @@ fn main() {
.alias("f"), .alias("f"),
) )
) )
.command(
Command::new("feed_watch")
.action(feed_watch)
.flag(
Flag::new("url", FlagType::String)
.alias("u"),
)
.flag(
Flag::new("tag", FlagType::String)
.alias("t"),
)
.flag(
Flag::new("debug", FlagType::Bool)
.alias("d"),
)
)
.command( .command(
Command::new("follow_all") Command::new("follow_all")
.action(follow_all), .action(follow_all),
@ -301,6 +319,13 @@ fn bot(c: &Context) {
} }
} }
fn feed_watch(c: &Context) {
refresh(c);
loop {
c_feed_watch(c);
}
}
fn follow_all(_c: &Context) { fn follow_all(_c: &Context) {
c_follow_all(); c_follow_all();
} }

View File

@ -16,6 +16,7 @@ source $d/reply.zsh
source $d/notify.zsh source $d/notify.zsh
source $d/notify_cid.zsh source $d/notify_cid.zsh
source $d/cron.zsh source $d/cron.zsh
source $d/feed.zsh
case $1 in case $1 in
refresh|r) refresh|r)
@ -36,4 +37,7 @@ case $1 in
cid) cid)
cid cid
;; ;;
feed)
feed
;;
esac esac

5
test/feed.zsh Normal file
View File

@ -0,0 +1,5 @@
function feed(){
token=`cat ~/.config/ai/token.json|jq -r .accessJwt`
url=at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.generator/cmd
curl -sL "https://public.api.bsky.app/xrpc/app.bsky.feed.getFeed?feed=$url" -H "Authorization: Bearer $token"
}