forked from jmug/stoatchat
Add fetch owned, public and specific bots for #8.
This commit is contained in:
22
src/routes/bots/fetch.rs
Normal file
22
src/routes/bots/fetch.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
#[get("/<target>")]
|
||||
pub async fn fetch_bot(user: User, target: Ref) -> Result<Value> {
|
||||
let bot = target.fetch_bot().await?;
|
||||
|
||||
if !bot.public {
|
||||
if bot.owner != user.id {
|
||||
return Err(Error::BotIsPrivate);
|
||||
}
|
||||
}
|
||||
|
||||
let user = Ref::from_unchecked(bot.id.clone()).fetch_user().await?;
|
||||
|
||||
Ok(json!({
|
||||
"bot": bot,
|
||||
"user": user
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user