mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2026-03-03 23:20:53 +01:00
Optimize user activity update
This commit is contained in:
44
src/bots_manager/bot_manager_client.rs
Normal file
44
src/bots_manager/bot_manager_client.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::config;
|
||||
|
||||
|
||||
#[derive(Deserialize, Debug, PartialEq, Clone, Copy)]
|
||||
pub enum BotStatus {
|
||||
#[serde(rename = "pending")]
|
||||
Pending,
|
||||
#[serde(rename = "approved")]
|
||||
Approved,
|
||||
#[serde(rename = "blocked")]
|
||||
Blocked,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, PartialEq, Clone, Copy)]
|
||||
pub enum BotCache {
|
||||
#[serde(rename = "original")]
|
||||
Original,
|
||||
#[serde(rename = "no_cache")]
|
||||
NoCache,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct BotData {
|
||||
pub id: u32,
|
||||
pub token: String,
|
||||
pub status: BotStatus,
|
||||
pub cache: BotCache,
|
||||
}
|
||||
|
||||
pub async fn get_bots() -> Result<Vec<BotData>, reqwest::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
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),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user