fix refresh
This commit is contained in:
		
							
								
								
									
										20
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								README.md
									
									
									
									
									
								
							@@ -84,23 +84,3 @@ $ cargo install --force cargo-make
 | 
			
		||||
$ cargo make build
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### docker
 | 
			
		||||
 | 
			
		||||
```sh
 | 
			
		||||
$ docker run -it syui/aios ai
 | 
			
		||||
$ docker run -it -d syui/aios zsh -c "ai login <handle> -p <password> && ai bot"
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
```sh
 | 
			
		||||
$ cp -rf ~/.config/ai ./.config/
 | 
			
		||||
 | 
			
		||||
$ docker compose up
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### cron
 | 
			
		||||
 | 
			
		||||
```sh
 | 
			
		||||
$ sudo pacman -S fcron
 | 
			
		||||
$ fcrontab -e
 | 
			
		||||
* * * * * $HOME/bot/test/ai.zsh c
 | 
			
		||||
```
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										53
									
								
								docs/wiki.md
									
									
									
									
									
								
							
							
						
						
									
										53
									
								
								docs/wiki.md
									
									
									
									
									
								
							@@ -1 +1,52 @@
 | 
			
		||||
##
 | 
			
		||||
### docker
 | 
			
		||||
 | 
			
		||||
```sh
 | 
			
		||||
$ docker run -it syui/aios ai
 | 
			
		||||
$ docker run -it -d syui/aios zsh -c "ai login <handle> -p <password> && ai bot"
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
```sh
 | 
			
		||||
$ cp -rf ~/.config/ai ./.config/
 | 
			
		||||
 | 
			
		||||
$ docker compose up
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### cron
 | 
			
		||||
 | 
			
		||||
```sh
 | 
			
		||||
$ sudo pacman -S fcron
 | 
			
		||||
$ fcrontab -e
 | 
			
		||||
* * * * * $HOME/bot/test/ai.zsh c
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### ssh
 | 
			
		||||
 | 
			
		||||
```sh
 | 
			
		||||
$ ssh-keygen -f /.ssh/diffusers.key -t ed25519
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
```sh
 | 
			
		||||
FROM syui/aios
 | 
			
		||||
ADD .ssh /root/.ssh
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
```sh
 | 
			
		||||
Host diffusers
 | 
			
		||||
	HostName localhost
 | 
			
		||||
	User root
 | 
			
		||||
	IdentityFile ~/.ssh/diffusers.key
 | 
			
		||||
	StrictHostKeyChecking no
 | 
			
		||||
	UserKnownHostsFile /dev/null
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
```sh
 | 
			
		||||
services:
 | 
			
		||||
  aios:
 | 
			
		||||
    #image: syui/aios
 | 
			
		||||
    build:
 | 
			
		||||
      context: .
 | 
			
		||||
    restart: always
 | 
			
		||||
    volumes:
 | 
			
		||||
      - ./.config:/root/.config
 | 
			
		||||
    command: ai bot -a syui.syu.is
 | 
			
		||||
```
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								src/data.rs
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								src/data.rs
									
									
									
									
									
								
							@@ -84,6 +84,7 @@ pub struct Token {
 | 
			
		||||
#[allow(non_snake_case)]
 | 
			
		||||
pub struct Data {
 | 
			
		||||
    pub host: String,
 | 
			
		||||
    pub password: String,
 | 
			
		||||
    pub did: String,
 | 
			
		||||
    pub handle: String,
 | 
			
		||||
    pub access: String,
 | 
			
		||||
@@ -129,6 +130,7 @@ pub fn url(s: &str) -> String {
 | 
			
		||||
    let data = Data::new().unwrap();
 | 
			
		||||
    let data = Data {
 | 
			
		||||
        host: data.host,
 | 
			
		||||
        password: data.password,
 | 
			
		||||
        handle: data.handle,
 | 
			
		||||
        did: data.did,
 | 
			
		||||
        access: data.access,
 | 
			
		||||
@@ -194,6 +196,7 @@ pub fn data_toml(s: &str) -> String {
 | 
			
		||||
    let data = Data::new().unwrap();
 | 
			
		||||
    let data = Data {
 | 
			
		||||
        host: data.host,
 | 
			
		||||
        password: data.password,
 | 
			
		||||
        handle: data.handle,
 | 
			
		||||
        did: data.did,
 | 
			
		||||
        access: data.access,
 | 
			
		||||
@@ -201,6 +204,7 @@ pub fn data_toml(s: &str) -> String {
 | 
			
		||||
    };
 | 
			
		||||
    match &*s {
 | 
			
		||||
        "host" => data.handle,
 | 
			
		||||
        "password" => data.password,
 | 
			
		||||
        "handle" => data.handle,
 | 
			
		||||
        "did" => data.did,
 | 
			
		||||
        "access" => data.access,
 | 
			
		||||
@@ -209,8 +213,35 @@ pub fn data_toml(s: &str) -> String {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn c_refresh(access: &str, refresh: &str) {
 | 
			
		||||
    let ff = data_file(&"refresh");
 | 
			
		||||
    let mut ff = fs::File::create(ff.clone()).unwrap();
 | 
			
		||||
    let refreshs = Refresh {
 | 
			
		||||
        access: access.to_string(),
 | 
			
		||||
        refresh: refresh.to_string(),
 | 
			
		||||
    };
 | 
			
		||||
    let toml = toml::to_string(&refreshs).unwrap();
 | 
			
		||||
    ff.write_all(&toml.as_bytes()).unwrap();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn data_refresh(s: &str) -> String {
 | 
			
		||||
    let s = String::from(s);
 | 
			
		||||
 | 
			
		||||
    let data = Data::new().unwrap();
 | 
			
		||||
    let data = Data {
 | 
			
		||||
        host: data.host,
 | 
			
		||||
        password: data.password,
 | 
			
		||||
        handle: data.handle,
 | 
			
		||||
        did: data.did,
 | 
			
		||||
        access: data.access,
 | 
			
		||||
        refresh: data.refresh,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let mut _file = match  Refresh::new()
 | 
			
		||||
    {
 | 
			
		||||
        Err(_why) => c_refresh(&data.access, &data.refresh),
 | 
			
		||||
        Ok(_) => println!("ok"),
 | 
			
		||||
    };
 | 
			
		||||
    let refresh = Refresh::new().unwrap();
 | 
			
		||||
    let refresh = Refresh {
 | 
			
		||||
        access: refresh.access,
 | 
			
		||||
@@ -490,7 +521,7 @@ pub fn c_char(i: String) -> String {
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn w_cfg(h: &str, res: &str) {
 | 
			
		||||
pub fn w_cfg(h: &str, res: &str, password: &str) {
 | 
			
		||||
    let f = data_file(&"json");
 | 
			
		||||
    let ff = data_file(&"toml");
 | 
			
		||||
    let mut f = fs::File::create(f.clone()).unwrap();
 | 
			
		||||
@@ -499,6 +530,7 @@ pub fn w_cfg(h: &str, res: &str) {
 | 
			
		||||
    let json: Token = serde_json::from_str(&res).unwrap();
 | 
			
		||||
    let datas = Data {
 | 
			
		||||
        host: h.to_string(),
 | 
			
		||||
        password: password.to_string(),
 | 
			
		||||
        did: json.did.to_string(),
 | 
			
		||||
        handle: json.handle.to_string(),
 | 
			
		||||
        access: json.accessJwt.to_string(),
 | 
			
		||||
 
 | 
			
		||||
@@ -282,13 +282,13 @@ fn token(c: &Context) {
 | 
			
		||||
        if let Ok(p) = c.string_flag("password") {
 | 
			
		||||
            if let Ok(s) = c.string_flag("server") {
 | 
			
		||||
                let res = token::post_request(m.to_string(), p.to_string(), s.to_string()).await;
 | 
			
		||||
                w_cfg(&s, &res);
 | 
			
		||||
                w_cfg(&s, &res, &p);
 | 
			
		||||
                w_refresh(&res);
 | 
			
		||||
            } else {
 | 
			
		||||
                let res =
 | 
			
		||||
                    token::post_request(m.to_string(), p.to_string(), "bsky.social".to_string())
 | 
			
		||||
                        .await;
 | 
			
		||||
                w_cfg(&"bsky.social", &res);
 | 
			
		||||
                w_cfg(&"bsky.social", &res, &p);
 | 
			
		||||
                w_refresh(&res);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user