From 8f5b6f063662db8c4c552561104e91ab51c12a74 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Wed, 26 May 2021 21:04:53 +0000 Subject: [PATCH] Replace db query with simple in-memory check of if account already exists. --- src/commands/management.rs | 3 ++- src/models.rs | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/commands/management.rs b/src/commands/management.rs index 975949a..d161105 100644 --- a/src/commands/management.rs +++ b/src/commands/management.rs @@ -34,7 +34,7 @@ impl Command for RegisterCommand { } 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)); } @@ -46,6 +46,7 @@ impl Command for RegisterCommand { }; ctx.db.upsert_user(&user).await?; + Execution::success(format!( "User account {} registered for bot commands.", ctx.username diff --git a/src/models.rs b/src/models.rs index 2da71dc..c185424 100644 --- a/src/models.rs +++ b/src/models.rs @@ -42,6 +42,11 @@ pub enum 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 /// actual account status (fully registered or awaiting /// activation). For transient users, this is