|
|
|
@ -20,6 +20,7 @@ use data::Did as Did;
|
|
|
|
|
use data::Cid as Cid;
|
|
|
|
|
use data::Handle as Handle;
|
|
|
|
|
use crate::data::Timeline;
|
|
|
|
|
use crate::data::url;
|
|
|
|
|
|
|
|
|
|
use std::io;
|
|
|
|
|
use std::io::Write;
|
|
|
|
@ -32,6 +33,13 @@ pub struct Event {
|
|
|
|
|
pub value: i32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
|
struct Setting {
|
|
|
|
|
host: String,
|
|
|
|
|
user: String,
|
|
|
|
|
pass: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let args: Vec<String> = env::args().collect(); let app = App::new(env!("CARGO_PKG_NAME"))
|
|
|
|
|
.author(env!("CARGO_PKG_AUTHORS"))
|
|
|
|
@ -42,7 +50,22 @@ fn main() {
|
|
|
|
|
Command::new("start")
|
|
|
|
|
.usage("atr start")
|
|
|
|
|
.description("start first\n\t\t\t$ atr start\n\t\t\t$ ~/.config/atr/config.toml")
|
|
|
|
|
.action(first),
|
|
|
|
|
.action(first)
|
|
|
|
|
.flag(
|
|
|
|
|
Flag::new("pass", FlagType::String)
|
|
|
|
|
.description("pass")
|
|
|
|
|
.alias("p"),
|
|
|
|
|
)
|
|
|
|
|
.flag(
|
|
|
|
|
Flag::new("host", FlagType::String)
|
|
|
|
|
.description("host")
|
|
|
|
|
.alias("h"),
|
|
|
|
|
)
|
|
|
|
|
.flag(
|
|
|
|
|
Flag::new("user", FlagType::String)
|
|
|
|
|
.description("user")
|
|
|
|
|
.alias("u"),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.command(
|
|
|
|
|
Command::new("auth")
|
|
|
|
@ -123,6 +146,23 @@ fn main() {
|
|
|
|
|
.alias("l"),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.command(
|
|
|
|
|
Command::new("reply")
|
|
|
|
|
.usage("atr r {}")
|
|
|
|
|
.description("reply\n\t\t\t$ atr r $text -u $uri -c $cid")
|
|
|
|
|
.alias("r")
|
|
|
|
|
.action(r)
|
|
|
|
|
.flag(
|
|
|
|
|
Flag::new("uri", FlagType::String)
|
|
|
|
|
.description("uri flag(ex: $ atr r -u)")
|
|
|
|
|
.alias("u"),
|
|
|
|
|
)
|
|
|
|
|
.flag(
|
|
|
|
|
Flag::new("cid", FlagType::String)
|
|
|
|
|
.description("cid flag(ex: $ atr r -u -c)")
|
|
|
|
|
.alias("c"),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.command(
|
|
|
|
|
Command::new("mention")
|
|
|
|
|
.usage("atr mention {}")
|
|
|
|
@ -207,7 +247,8 @@ fn ss(c :&Context) -> reqwest::Result<()> {
|
|
|
|
|
user: data.user,
|
|
|
|
|
pass: data.pass,
|
|
|
|
|
};
|
|
|
|
|
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.repo.describe";
|
|
|
|
|
let s = "describe".to_string();
|
|
|
|
|
let url = url(&s);
|
|
|
|
|
if let Ok(user) = c.string_flag("user") {
|
|
|
|
|
at_user(url, user);
|
|
|
|
|
} else {
|
|
|
|
@ -242,7 +283,8 @@ fn ff(c :&Context) -> reqwest::Result<()> {
|
|
|
|
|
user: data.user,
|
|
|
|
|
pass: data.pass,
|
|
|
|
|
};
|
|
|
|
|
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.repo.listRecords";
|
|
|
|
|
let s = "record_list".to_string();
|
|
|
|
|
let url = url(&s);
|
|
|
|
|
let col = "app.bsky.feed.post".to_string();
|
|
|
|
|
if let Ok(user) = c.string_flag("user") {
|
|
|
|
|
at_feed(url, user, col);
|
|
|
|
@ -273,7 +315,8 @@ async fn aa() -> reqwest::Result<()> {
|
|
|
|
|
let handle = data.user;
|
|
|
|
|
let mut map = HashMap::new();
|
|
|
|
|
|
|
|
|
|
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.session.create";
|
|
|
|
|
let s = "session_create".to_string();
|
|
|
|
|
let url = url(&s);
|
|
|
|
|
map.insert("handle", &handle);
|
|
|
|
|
map.insert("password", &data.pass);
|
|
|
|
|
let client = reqwest::Client::new();
|
|
|
|
@ -311,14 +354,8 @@ async fn pp(c: &Context) -> reqwest::Result<()> {
|
|
|
|
|
let token = json.accessJwt;
|
|
|
|
|
let did = json.did;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let data = Datas::new().unwrap();
|
|
|
|
|
let data = Datas {
|
|
|
|
|
host: data.host,
|
|
|
|
|
user: data.user,
|
|
|
|
|
pass: data.pass,
|
|
|
|
|
};
|
|
|
|
|
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.repo.createRecord";
|
|
|
|
|
let s = "record_create".to_string();
|
|
|
|
|
let url = url(&s);
|
|
|
|
|
let col = "app.bsky.feed.post".to_string();
|
|
|
|
|
let d = Timestamp::now_utc();
|
|
|
|
|
let d = d.to_string();
|
|
|
|
@ -410,7 +447,8 @@ async fn tt(c: &Context) -> reqwest::Result<()> {
|
|
|
|
|
let json: Token = serde_json::from_str(&data).unwrap();
|
|
|
|
|
let token = json.accessJwt;
|
|
|
|
|
|
|
|
|
|
let url = "https://bsky.social/xrpc/app.bsky.feed.getTimeline";
|
|
|
|
|
let s = "timeline_get".to_string();
|
|
|
|
|
let url = url(&s);
|
|
|
|
|
|
|
|
|
|
let client = reqwest::Client::new();
|
|
|
|
|
let j = client.get(url)
|
|
|
|
@ -467,16 +505,11 @@ async fn pro(c: &Context) -> reqwest::Result<()> {
|
|
|
|
|
let json: Token = serde_json::from_str(&data).unwrap();
|
|
|
|
|
let token = json.accessJwt;
|
|
|
|
|
|
|
|
|
|
let data = Datas::new().unwrap();
|
|
|
|
|
let data = Datas {
|
|
|
|
|
host: data.host,
|
|
|
|
|
user: data.user,
|
|
|
|
|
pass: data.pass,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let user = c.args[0].to_string();
|
|
|
|
|
if user.is_empty() == false {
|
|
|
|
|
let url = "https://bsky.social/xrpc/app.bsky.actor.getProfile?actor=".to_owned() + &user;
|
|
|
|
|
let s = "profile_get".to_string();
|
|
|
|
|
if c.args[0].is_empty() == false {
|
|
|
|
|
let user = c.args[0].to_string();
|
|
|
|
|
let url = url(&s) + &"?actor=" + &user;
|
|
|
|
|
println!("{}", url);
|
|
|
|
|
let client = reqwest::Client::new();
|
|
|
|
|
let j = client.get(url)
|
|
|
|
|
.header("Authorization", "Bearer ".to_owned() + &token)
|
|
|
|
@ -492,16 +525,6 @@ async fn pro(c: &Context) -> reqwest::Result<()> {
|
|
|
|
|
f.write_all(&j.as_bytes()).unwrap();
|
|
|
|
|
}
|
|
|
|
|
println!("{}", j);
|
|
|
|
|
} else {
|
|
|
|
|
let url = "https://bsky.social/xrpc/app.bsky.actor.getProfile?actor=".to_owned() + &data.user;
|
|
|
|
|
let client = reqwest::Client::new();
|
|
|
|
|
let j = client.get(url)
|
|
|
|
|
.header("Authorization", "Bearer ".to_owned() + &token)
|
|
|
|
|
.send()
|
|
|
|
|
.await?
|
|
|
|
|
.text()
|
|
|
|
|
.await?;
|
|
|
|
|
println!("{}", j);
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
@ -531,7 +554,9 @@ async fn mm(c: &Context) -> reqwest::Result<()> {
|
|
|
|
|
user: data.user,
|
|
|
|
|
pass: data.pass,
|
|
|
|
|
};
|
|
|
|
|
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.blob.upload";
|
|
|
|
|
|
|
|
|
|
let s = "upload_blob".to_string();
|
|
|
|
|
let url = url(&s);
|
|
|
|
|
|
|
|
|
|
let f = "@".to_owned() + &c.args[0].to_string();
|
|
|
|
|
use std::process::Command;
|
|
|
|
@ -540,15 +565,10 @@ async fn mm(c: &Context) -> reqwest::Result<()> {
|
|
|
|
|
let d = d.to_string();
|
|
|
|
|
let cid: Cid = serde_json::from_str(&d).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let d = Timestamp::now_utc();
|
|
|
|
|
//let output = Command::new("date").arg("-u").arg("+'%Y-%m-%dT%H:%M:%SZ'").output().expect("sh");
|
|
|
|
|
//let d = String::from_utf8_lossy(&output.stdout);
|
|
|
|
|
let d = d.to_string();
|
|
|
|
|
//let d: String = d.replace("'", "").replace("\n", "");
|
|
|
|
|
println!("{}", d);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mtype = "image/png".to_string();
|
|
|
|
|
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.repo.createRecord";
|
|
|
|
|
let con = "Content-Type: application/json";
|
|
|
|
@ -585,13 +605,8 @@ async fn hh(c: &Context) -> reqwest::Result<()> {
|
|
|
|
|
|
|
|
|
|
let m = c.args[0].to_string();
|
|
|
|
|
|
|
|
|
|
let data = Datas::new().unwrap();
|
|
|
|
|
let data = Datas {
|
|
|
|
|
host: data.host,
|
|
|
|
|
user: data.user,
|
|
|
|
|
pass: data.pass,
|
|
|
|
|
};
|
|
|
|
|
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.handle.update";
|
|
|
|
|
let s = "update_handle".to_string();
|
|
|
|
|
let url = url(&s);
|
|
|
|
|
println!("DNS txt : _atproto.{}, did={}.", m, did);
|
|
|
|
|
|
|
|
|
|
let handle = Handle {
|
|
|
|
@ -625,7 +640,9 @@ async fn cc(c: &Context) -> reqwest::Result<()> {
|
|
|
|
|
user: data.user,
|
|
|
|
|
pass: data.pass,
|
|
|
|
|
};
|
|
|
|
|
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.account.create";
|
|
|
|
|
|
|
|
|
|
let s = "account_create".to_string();
|
|
|
|
|
let url = url(&s);
|
|
|
|
|
let handle = data.user;
|
|
|
|
|
|
|
|
|
|
let mut map = HashMap::new();
|
|
|
|
@ -682,13 +699,8 @@ async fn mention(c: &Context) -> reqwest::Result<()> {
|
|
|
|
|
let handle: Handle = serde_json::from_str(&data).unwrap();
|
|
|
|
|
let handle = handle.handle;
|
|
|
|
|
|
|
|
|
|
let data = Datas::new().unwrap();
|
|
|
|
|
let data = Datas {
|
|
|
|
|
host: data.host,
|
|
|
|
|
user: data.user,
|
|
|
|
|
pass: data.pass,
|
|
|
|
|
};
|
|
|
|
|
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.repo.createRecord";
|
|
|
|
|
let s = "record_create".to_string();
|
|
|
|
|
let url = url(&s);
|
|
|
|
|
let col = "app.bsky.feed.post".to_string();
|
|
|
|
|
|
|
|
|
|
let d = Timestamp::now_utc();
|
|
|
|
@ -777,15 +789,11 @@ async fn nn(c: &Context) -> reqwest::Result<()> {
|
|
|
|
|
|
|
|
|
|
let json: Token = serde_json::from_str(&data).unwrap();
|
|
|
|
|
let token = json.accessJwt;
|
|
|
|
|
|
|
|
|
|
let data = Datas::new().unwrap();
|
|
|
|
|
let data = Datas {
|
|
|
|
|
host: data.host,
|
|
|
|
|
user: data.user,
|
|
|
|
|
pass: data.pass,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if let Ok(_get) = c.string_flag("get") {
|
|
|
|
|
let url = "https://".to_owned() + &data.host + &"/xrpc/app.bsky.notification.getCount";
|
|
|
|
|
|
|
|
|
|
let s = "notify_count".to_string();
|
|
|
|
|
let url = url(&s);
|
|
|
|
|
let client = reqwest::Client::new();
|
|
|
|
|
let res = client
|
|
|
|
|
.get(url)
|
|
|
|
@ -797,7 +805,8 @@ async fn nn(c: &Context) -> reqwest::Result<()> {
|
|
|
|
|
println!("{}", res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let url = "https://".to_owned() + &data.host + &"/xrpc/app.bsky.notification.list";
|
|
|
|
|
let s = "notify_list".to_string();
|
|
|
|
|
let url = url(&s);
|
|
|
|
|
let client = reqwest::Client::new();
|
|
|
|
|
let res = client
|
|
|
|
|
.get(url)
|
|
|
|
@ -815,6 +824,7 @@ async fn nn(c: &Context) -> reqwest::Result<()> {
|
|
|
|
|
map.insert("createdAt", &n[0].record.createdAt);
|
|
|
|
|
map.insert("uri", &n[0].uri);
|
|
|
|
|
map.insert("cid", &n[0].cid);
|
|
|
|
|
map.insert("reason", &n[0].reason);
|
|
|
|
|
if ! n[0].record.text.is_none() {
|
|
|
|
|
map.insert("text", &n[0].record.text.as_ref().unwrap());
|
|
|
|
|
}
|
|
|
|
@ -903,15 +913,8 @@ fn account_switch(c: &Context) {
|
|
|
|
|
ss(c).unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
|
struct Setting {
|
|
|
|
|
host: String,
|
|
|
|
|
user: String,
|
|
|
|
|
pass: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(unused_must_use)]
|
|
|
|
|
fn first_start(_c: &Context) -> io::Result<()> {
|
|
|
|
|
fn first_start(c: &Context) -> io::Result<()> {
|
|
|
|
|
let d = shellexpand::tilde("~") + "/.config/atr";
|
|
|
|
|
let d = d.to_string();
|
|
|
|
|
let f = shellexpand::tilde("~") + "/.config/atr/config.toml";
|
|
|
|
@ -936,9 +939,124 @@ fn first_start(_c: &Context) -> io::Result<()> {
|
|
|
|
|
let mut f = fs::File::create(f.clone()).unwrap();
|
|
|
|
|
f.write_all(&toml.as_bytes()).unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let f = shellexpand::tilde("~") + "/.config/atr/config.toml";
|
|
|
|
|
let f = f.to_string();
|
|
|
|
|
|
|
|
|
|
if let Ok(user) = c.string_flag("user") {
|
|
|
|
|
if let Ok(pass) = c.string_flag("pass") {
|
|
|
|
|
let setting = Setting {
|
|
|
|
|
host: "bsky.social".to_string(),
|
|
|
|
|
user: user.to_string(),
|
|
|
|
|
pass: pass.to_string(),
|
|
|
|
|
};
|
|
|
|
|
let toml = toml::to_string(&setting).unwrap();
|
|
|
|
|
let mut f = fs::File::create(f.clone()).unwrap();
|
|
|
|
|
f.write_all(&toml.as_bytes()).unwrap();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn first(c: &Context) {
|
|
|
|
|
first_start(c).unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn rr(c: &Context) -> reqwest::Result<()> {
|
|
|
|
|
let file = "/.config/atr/token.json";
|
|
|
|
|
let mut f = shellexpand::tilde("~").to_string();
|
|
|
|
|
f.push_str(&file);
|
|
|
|
|
|
|
|
|
|
let mut file = File::open(f).unwrap();
|
|
|
|
|
let mut data = String::new();
|
|
|
|
|
file.read_to_string(&mut data).unwrap();
|
|
|
|
|
|
|
|
|
|
let json: Token = serde_json::from_str(&data).unwrap();
|
|
|
|
|
let token = json.accessJwt;
|
|
|
|
|
let did = json.did;
|
|
|
|
|
|
|
|
|
|
let s = "record_create".to_string();
|
|
|
|
|
let url = url(&s);
|
|
|
|
|
let col = "app.bsky.feed.post".to_string();
|
|
|
|
|
let d = Timestamp::now_utc();
|
|
|
|
|
let d = d.to_string();
|
|
|
|
|
|
|
|
|
|
let m = c.args[0].to_string();
|
|
|
|
|
if let Ok(link) = c.string_flag("link") {
|
|
|
|
|
let e = link.chars().count();
|
|
|
|
|
let s = 0;
|
|
|
|
|
let post = Some(json!({
|
|
|
|
|
"did": did.to_string(),
|
|
|
|
|
"collection": col.to_string(),
|
|
|
|
|
"record": {
|
|
|
|
|
"text": link.to_string() + &" ".to_string() + &m.to_string(),
|
|
|
|
|
"createdAt": d.to_string(),
|
|
|
|
|
"entities": [
|
|
|
|
|
{
|
|
|
|
|
"type": "link".to_string(),
|
|
|
|
|
"index": {
|
|
|
|
|
"end": e,
|
|
|
|
|
"start": s
|
|
|
|
|
},
|
|
|
|
|
"value": link.to_string()
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
let client = reqwest::Client::new();
|
|
|
|
|
let res = client
|
|
|
|
|
.post(url)
|
|
|
|
|
.json(&post)
|
|
|
|
|
.header("Authorization", "Bearer ".to_owned() + &token)
|
|
|
|
|
.send()
|
|
|
|
|
.await?
|
|
|
|
|
.text()
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
println!("{}", res);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
if let Ok(uri) = c.string_flag("uri") {
|
|
|
|
|
if let Ok(cid) = c.string_flag("cid") {
|
|
|
|
|
let post = Some(json!({
|
|
|
|
|
"did": did.to_string(),
|
|
|
|
|
"collection": col.to_string(),
|
|
|
|
|
"record": {
|
|
|
|
|
"text": m.to_string(),
|
|
|
|
|
"createdAt": d.to_string(),
|
|
|
|
|
"reply": {
|
|
|
|
|
"root": {
|
|
|
|
|
"cid": cid.to_string(),
|
|
|
|
|
"uri": uri.to_string()
|
|
|
|
|
},
|
|
|
|
|
"parent": {
|
|
|
|
|
"cid": cid.to_string(),
|
|
|
|
|
"uri": uri.to_string()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
let client = reqwest::Client::new();
|
|
|
|
|
let res = client
|
|
|
|
|
.post(url)
|
|
|
|
|
.json(&post)
|
|
|
|
|
.header("Authorization", "Bearer ".to_owned() + &token)
|
|
|
|
|
.send()
|
|
|
|
|
.await?
|
|
|
|
|
.text()
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
println!("{}", res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn r(c: &Context) {
|
|
|
|
|
aa().unwrap();
|
|
|
|
|
rr(c).unwrap();
|
|
|
|
|
}
|
|
|
|
|