Update user's name when running commands or on call
This commit is contained in:
@@ -274,6 +274,8 @@ impl From<TwilightUser> for User {
|
|||||||
|
|
||||||
/// Gets a user from the DB and sets their last seen timestamp or inserts a new user from Discord.
|
/// Gets a user from the DB and sets their last seen timestamp or inserts a new user from Discord.
|
||||||
///
|
///
|
||||||
|
/// It also updates the user's username.
|
||||||
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// * `user` - The Twilight user to get or create.
|
/// * `user` - The Twilight user to get or create.
|
||||||
/// * `session` - The Scylla session to use for database operations.
|
/// * `session` - The Scylla session to use for database operations.
|
||||||
@@ -287,10 +289,11 @@ pub async fn get_or_create_user_and_set_last_seen(
|
|||||||
) -> Result<User, DatabaseError> {
|
) -> Result<User, DatabaseError> {
|
||||||
let db_user = User::get_by_id(user.id.get(), session).await?;
|
let db_user = User::get_by_id(user.id.get(), session).await?;
|
||||||
|
|
||||||
if let Some(mut user) = db_user {
|
if let Some(mut db_user) = db_user {
|
||||||
user.last_seen_at = UtcDateTime::now();
|
db_user.last_seen_at = UtcDateTime::now();
|
||||||
|
db_user.name = user.name;
|
||||||
|
|
||||||
return Ok(user);
|
return Ok(db_user);
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_user = User::from(user);
|
let new_user = User::from(user);
|
||||||
|
|||||||
Reference in New Issue
Block a user