parent
50dce8da96
commit
6b6c047b68
@ -0,0 +1,35 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use poise::serenity_prelude::Http;
|
||||
use rocket::{http::{CookieJar, Status}, State};
|
||||
use rocket::serde::json::Json;
|
||||
|
||||
use crate::{cookies::user::USER_ID_COOKIE, models::Settings};
|
||||
|
||||
// TODO: Incrementally send guilds
|
||||
#[get("/get_guilds")]
|
||||
pub async fn get_guilds(
|
||||
cookies: &CookieJar<'_>,
|
||||
settings: &State<Settings>,
|
||||
http: &State<Http>,
|
||||
) -> Result<Json<HashMap<u64, bool>>, Status> {
|
||||
let user_id: u64 = match cookies.get_private(USER_ID_COOKIE) {
|
||||
Some(id) => match id.value().parse() {
|
||||
Ok(id) => id,
|
||||
Err(_) => return Err(Status::BadRequest),
|
||||
},
|
||||
None => return Err(Status::Unauthorized),
|
||||
};
|
||||
Ok(Json({
|
||||
let mut guild_statuses = HashMap::with_capacity(settings.guilds.len());
|
||||
for guild in &settings.guilds {
|
||||
guild_statuses.insert(guild.id, {
|
||||
if guild.hidden {
|
||||
continue;
|
||||
}
|
||||
http.get_member(guild.id, user_id).await.is_ok()
|
||||
});
|
||||
}
|
||||
guild_statuses
|
||||
}))
|
||||
}
|
Loading…
Reference in new issue