chore: commit the things that are to be commited

This commit is contained in:
Paul Makles
2022-02-11 23:33:38 +00:00
parent 28db08ba88
commit 50d9f50c8f
9 changed files with 46 additions and 24 deletions

View File

@@ -2,7 +2,7 @@ use crate::util::{regex::RE_USERNAME, variables::MAX_BOT_COUNT};
use nanoid::nanoid;
use revolt_quark::{
models::{Bot, User},
models::{Bot, User, user::BotInformation},
Db, Error, Result,
};
@@ -31,13 +31,28 @@ pub async fn create_bot(db: &Db, user: User, info: Json<Data>) -> Result<Json<Bo
return Err(Error::ReachedMaximumBots);
}
if db.is_username_taken(&info.name).await? {
return Err(Error::UsernameTaken);
}
let id = Ulid::new().to_string();
let bot_user = User {
id: id.clone(),
username: info.name,
bot: Some(BotInformation {
owner: user.id.clone()
}),
..Default::default()
};
let bot = Bot {
id: Ulid::new().to_string(),
id,
owner: user.id,
token: nanoid!(64),
..Default::default()
};
db.insert_user(&bot_user).await?;
db.insert_bot(&bot).await?;
Ok(Json(bot))
}