chore: implement invite join and rauth conf

This commit is contained in:
Paul Makles
2022-02-11 11:28:06 +00:00
parent 1988a9501b
commit 249b1161f9
2 changed files with 37 additions and 10 deletions

View File

@@ -1,8 +1,35 @@
use revolt_quark::{Error, Result};
use revolt_quark::{Error, Result, Ref, models::{User, Invite}, Db};
use rocket::serde::json::Value;
use crate::util::variables::MAX_SERVER_COUNT;
#[post("/<target>")]
pub async fn req(/*user: UserRef, target: Ref*/ target: String) -> Result<Value> {
todo!()
pub async fn req(db: &Db, user: User, target: Ref) -> Result<Value> {
if user.bot.is_some() {
return Err(Error::IsBot)
}
if !user.can_acquire_server(db).await? {
return Err(Error::TooManyServers {
max: *MAX_SERVER_COUNT
})
}
let invite = target.as_invite(db).await?;
match &invite {
Invite::Server { channel, server, .. } => {
let channel = db.fetch_channel(channel).await?;
let server = db.fetch_server(server).await?;
db.insert_member(&server.id, &user.id).await?;
Ok(json!({
"type": "Server",
"channel": channel,
"server": server
}))
}
_ => unreachable!()
}
}