Serialize fediverse configuration
This commit is contained in:
parent
c51beb2bda
commit
c9bf51baee
|
@ -14,7 +14,7 @@ pub struct Config {
|
||||||
pub interval_seconds: MinMax,
|
pub interval_seconds: MinMax,
|
||||||
pub bot_token: String,
|
pub bot_token: String,
|
||||||
pub chat_ref: ChatId,
|
pub chat_ref: ChatId,
|
||||||
pub fediverse_oauth_token: String,
|
pub fediverse_token: Option<mammut::Data>,
|
||||||
pub post_buffer: u32,
|
pub post_buffer: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ impl Default for Config {
|
||||||
max: 60 * 90,
|
max: 60 * 90,
|
||||||
},
|
},
|
||||||
post_buffer: 5,
|
post_buffer: 5,
|
||||||
fediverse_oauth_token: "".to_owned(),
|
fediverse_token: None,
|
||||||
bot_token: "".to_owned(),
|
bot_token: "".to_owned(),
|
||||||
chat_ref: ChatId::new(0),
|
chat_ref: ChatId::new(0),
|
||||||
}
|
}
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -4,7 +4,7 @@ use async_std::io::stdin;
|
||||||
use futures_timer::Delay;
|
use futures_timer::Delay;
|
||||||
use mammut::{
|
use mammut::{
|
||||||
apps::{AppBuilder, Scopes},
|
apps::{AppBuilder, Scopes},
|
||||||
Registration,
|
Mastodon, Registration,
|
||||||
};
|
};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use telegram_bot::{Api, ChatRef};
|
use telegram_bot::{Api, ChatRef};
|
||||||
|
@ -48,22 +48,23 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let mut registration = Registration::new(cfg.fediverse_base_url.clone());
|
let mut registration = Registration::new(cfg.fediverse_base_url.clone());
|
||||||
registration.register(app)?;
|
registration.register(app)?;
|
||||||
|
|
||||||
let token = if cfg.fediverse_oauth_token.is_empty() {
|
let mastodon = if let Some(data) = &cfg.fediverse_token {
|
||||||
|
Mastodon::from_data(data.clone())
|
||||||
|
} else {
|
||||||
let url = registration.authorise()?;
|
let url = registration.authorise()?;
|
||||||
println!("{}", url);
|
println!("{}", url);
|
||||||
|
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
stdin().read_line(&mut buffer).await?;
|
stdin().read_line(&mut buffer).await?;
|
||||||
|
|
||||||
cfg.fediverse_oauth_token = buffer.clone();
|
let mastodon = registration.create_access_token(buffer)?;
|
||||||
|
|
||||||
|
cfg.fediverse_token = Some(mastodon.data.clone());
|
||||||
cfg.save(CONFIG_PATH)?;
|
cfg.save(CONFIG_PATH)?;
|
||||||
|
|
||||||
buffer
|
mastodon
|
||||||
} else {
|
|
||||||
cfg.fediverse_oauth_token.clone()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mastodon = registration.create_access_token(token)?;
|
|
||||||
let publisher = MastodonPublisher::new(mastodon);
|
let publisher = MastodonPublisher::new(mastodon);
|
||||||
|
|
||||||
let api = Arc::new(Api::new(cfg.bot_token.clone()));
|
let api = Arc::new(Api::new(cfg.bot_token.clone()));
|
||||||
|
|
Loading…
Reference in New Issue