Replace db query with simple in-memory check of if account already exists.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
projectmoon 2021-05-26 21:04:53 +00:00
parent 5b3d174edc
commit 8f5b6f0636
2 changed files with 7 additions and 1 deletions

View File

@ -34,7 +34,7 @@ impl Command for RegisterCommand {
} }
async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult { async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult {
if let Some(_) = ctx.db.get_user(ctx.username).await? { if ctx.account.is_registered() {
return Err(ExecutionError(BotError::AccountAlreadyExists)); return Err(ExecutionError(BotError::AccountAlreadyExists));
} }
@ -46,6 +46,7 @@ impl Command for RegisterCommand {
}; };
ctx.db.upsert_user(&user).await?; ctx.db.upsert_user(&user).await?;
Execution::success(format!( Execution::success(format!(
"User account {} registered for bot commands.", "User account {} registered for bot commands.",
ctx.username ctx.username

View File

@ -42,6 +42,11 @@ pub enum Account {
} }
impl Account { impl Account {
/// Whether or not this account is a registered user account.
pub fn is_registered(&self) -> bool {
matches!(self, Self::Registered(_))
}
/// Gets the account status. For registered users, this is their /// Gets the account status. For registered users, this is their
/// actual account status (fully registered or awaiting /// actual account status (fully registered or awaiting
/// activation). For transient users, this is /// activation). For transient users, this is