Add colors update
This commit is contained in:
+54
-5
@@ -16,6 +16,7 @@ use scylla::{
|
||||
};
|
||||
use thiserror::Error;
|
||||
use time::{Duration, OffsetDateTime, UtcDateTime, UtcOffset};
|
||||
use tokio::sync::mpsc::Sender;
|
||||
use twilight_http::Client;
|
||||
use twilight_model::{
|
||||
channel::{Message as TwilightMessage, Webhook},
|
||||
@@ -25,9 +26,10 @@ use twilight_model::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
colors::AvatarColorFetchingRequest,
|
||||
constants::DEFAULT_PREFIX,
|
||||
groups::calls::masks::{get_mask_avatar_url, get_mask_display_name, get_random_mask},
|
||||
utils::{get_random_u64, i64_to_u64, u64_to_i64},
|
||||
utils::{Bye, get_random_u64, i64_to_u64, u64_to_i64},
|
||||
};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
@@ -105,6 +107,8 @@ pub struct User {
|
||||
pub supporter_until: Option<UtcDateTime>,
|
||||
pub is_banned_from_leaderboard: Option<bool>,
|
||||
pub findings: HashSet<String>,
|
||||
pub avatar_hash: Option<String>,
|
||||
pub color: Option<i32>,
|
||||
}
|
||||
|
||||
impl<'a> Object<'a> for User {
|
||||
@@ -120,6 +124,9 @@ impl<'a> Object<'a> for User {
|
||||
Option<OffsetDateTime>,
|
||||
Option<bool>,
|
||||
HashSet<String>,
|
||||
Option<String>,
|
||||
Option<i32>,
|
||||
Option<bool>,
|
||||
);
|
||||
|
||||
fn from_row(row: Self::Row) -> Self {
|
||||
@@ -135,6 +142,8 @@ impl<'a> Object<'a> for User {
|
||||
supporter_until: row.8.map(|i| i.into()),
|
||||
is_banned_from_leaderboard: row.9,
|
||||
findings: row.10,
|
||||
avatar_hash: row.11,
|
||||
color: row.12,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,6 +160,9 @@ impl<'a> Object<'a> for User {
|
||||
value.supporter_until.map(|i| i.into()),
|
||||
Some(value.is_banned_from_leaderboard.unwrap_or(false)),
|
||||
value.findings,
|
||||
value.avatar_hash,
|
||||
value.color,
|
||||
Some(value.color.is_some()),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -178,7 +190,10 @@ impl User {
|
||||
supporter_since,
|
||||
supporter_until,
|
||||
is_banned_from_leaderboard,
|
||||
findings
|
||||
findings,
|
||||
avatar_hash,
|
||||
color,
|
||||
is_color_set
|
||||
FROM
|
||||
payphone.users
|
||||
WHERE
|
||||
@@ -218,6 +233,7 @@ impl User {
|
||||
pub async fn create_or_update(
|
||||
user: TwilightUser,
|
||||
session: &Session,
|
||||
sender: &Sender<AvatarColorFetchingRequest>,
|
||||
) -> Result<Self, DatabaseError> {
|
||||
let db_user = User::get_by_id(user.id.get(), session).await?;
|
||||
|
||||
@@ -225,10 +241,38 @@ impl User {
|
||||
db_user.last_seen_at = UtcDateTime::now();
|
||||
db_user.name = user.name;
|
||||
|
||||
if user.avatar.map(|hash| hash.to_string()) != db_user.avatar_hash {
|
||||
db_user.avatar_hash = user.avatar.map(|hash| hash.to_string());
|
||||
db_user.color = None;
|
||||
|
||||
if let Some(avatar_hash) = &db_user.avatar_hash {
|
||||
sender
|
||||
.send(AvatarColorFetchingRequest::new(avatar_hash, user.id.get()))
|
||||
.await
|
||||
.inspect_err(|e| {
|
||||
log::error!(
|
||||
"Failed to send avatar color fetching request to queue! {e}"
|
||||
)
|
||||
})
|
||||
.bye();
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(db_user);
|
||||
}
|
||||
|
||||
let new_user = User::from(user);
|
||||
|
||||
if let Some(avatar_hash) = &new_user.avatar_hash {
|
||||
sender
|
||||
.send(AvatarColorFetchingRequest::new(avatar_hash, new_user.id))
|
||||
.await
|
||||
.inspect_err(|e| {
|
||||
log::error!("Failed to send avatar color fetching request to queue! {e}")
|
||||
})
|
||||
.bye();
|
||||
}
|
||||
|
||||
new_user.insert(session).await?;
|
||||
|
||||
Ok(new_user)
|
||||
@@ -249,8 +293,11 @@ impl User {
|
||||
supporter_since,
|
||||
supporter_until,
|
||||
is_banned_from_leaderboard,
|
||||
findings
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
|
||||
findings,
|
||||
avatar_hash,
|
||||
color,
|
||||
is_color_set
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
|
||||
"#,
|
||||
Self::to_row(self.clone()),
|
||||
)
|
||||
@@ -338,6 +385,8 @@ impl From<TwilightUser> for User {
|
||||
supporter_until: None,
|
||||
is_banned_from_leaderboard: None,
|
||||
findings: HashSet::new(),
|
||||
avatar_hash: value.avatar.map(|a| a.to_string()),
|
||||
color: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1865,7 +1914,7 @@ impl<'a> Object<'a> for Participant {
|
||||
|
||||
fn make_name_valid(name: String) -> String {
|
||||
if name.len() == 1 {
|
||||
format!("{name}\u{2800}")
|
||||
format!("{name}⠀⠀") // Add two invisible characters
|
||||
} else if name.len() > 80 {
|
||||
format!("{name:.80}")
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user