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,7 +1,16 @@
use rauth::util::EmptyResponse;
use revolt_quark::Result;
use revolt_quark::{models::User, Db, Error, Ref, Result};
#[delete("/<target>")]
pub async fn delete_bot(/*user: UserRef, target: Ref*/ target: String,) -> Result<EmptyResponse> {
todo!()
pub async fn delete_bot(db: &Db, user: User, target: Ref) -> Result<EmptyResponse> {
if user.bot.is_some() {
return Err(Error::IsBot);
}
let bot = target.as_bot(db).await?;
if bot.owner != user.id {
return Err(Error::NotFound);
}
db.delete_bot(&bot.id).await.map(|_| EmptyResponse)
}