mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 15:35:35 +01:00
53 lines
1.1 KiB
Rust
53 lines
1.1 KiB
Rust
use once_cell::sync::Lazy;
|
|
use serde::Deserialize;
|
|
|
|
use crate::config;
|
|
|
|
|
|
pub static CLIENT: Lazy<reqwest::Client> = Lazy::new(reqwest::Client::new);
|
|
|
|
|
|
#[derive(Deserialize, Debug, PartialEq, Clone, Copy)]
|
|
pub enum BotCache {
|
|
#[serde(rename = "original")]
|
|
Original,
|
|
#[serde(rename = "cache")]
|
|
Cache,
|
|
#[serde(rename = "no_cache")]
|
|
NoCache,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug, Clone)]
|
|
pub struct BotData {
|
|
pub id: u32,
|
|
pub token: String,
|
|
pub cache: BotCache,
|
|
}
|
|
|
|
pub async fn get_bots() -> Result<Vec<BotData>, reqwest::Error> {
|
|
let response = CLIENT
|
|
.get(&config::CONFIG.manager_url)
|
|
.header("Authorization", &config::CONFIG.manager_api_key)
|
|
.send()
|
|
.await;
|
|
|
|
match response {
|
|
Ok(v) => v.json::<Vec<BotData>>().await,
|
|
Err(err) => Err(err),
|
|
}
|
|
}
|
|
|
|
|
|
pub async fn delete_bot(id: u32) -> Result<(), reqwest::Error> {
|
|
let response = CLIENT
|
|
.delete(&format!("{}/{}/", config::CONFIG.manager_url, id))
|
|
.header("Authorization", &config::CONFIG.manager_api_key)
|
|
.send()
|
|
.await;
|
|
|
|
match response {
|
|
Ok(_) => Ok(()),
|
|
Err(err) => Err(err),
|
|
}
|
|
}
|