Replace db query with simple in-memory check of if account already exists.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
5b3d174edc
commit
8f5b6f0636
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue