feat(bots): implement bot routes

This commit is contained in:
Paul Makles
2022-02-10 15:54:41 +00:00
parent d4aff072a8
commit a8d5fcec9e
12 changed files with 206 additions and 58 deletions

View File

@@ -1,8 +1,20 @@
use revolt_quark::Result;
use revolt_quark::{Db, Error, Ref, Result};
use serde_json::Value;
#[get("/<target>/invite")]
pub async fn fetch_public_bot(/*user: UserRef, target: Ref*/ target: String) -> Result<Value> {
todo!()
pub async fn fetch_public_bot(db: &Db, target: Ref) -> Result<Value> {
let bot = target.as_bot(db).await?;
if !bot.public {
return Err(Error::NotFound);
}
let user = db.fetch_user(&bot.id).await?;
Ok(json!({
"_id": bot.id,
"username": user.username,
"avatar": user.avatar,
"description": user.profile.map(|p| p.content)
}))
}