Skip to content

Commit

Permalink
categorise entitlements by entitlement id
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacherr committed Oct 21, 2024
1 parent aec47c9 commit 6075f17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions assyst-core/src/task/tasks/refresh_entitlements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ pub async fn refresh_entitlements(assyst: ThreadSafeAssyst) {
},
};

println!("{:?}", additional.iter().map(|x| x.id).collect::<Vec<_>>());

for a in additional {
if !assyst
.entitlements
.lock()
.unwrap()
.contains_key(&(a.guild_id.map(|x| x.get()).unwrap_or(0) as i64))
{
if !assyst.entitlements.lock().unwrap().contains_key(&(a.id.get() as i64)) {
let active = match ActiveGuildPremiumEntitlement::try_from(a) {
Ok(a) => a,
Err(e) => {
Expand All @@ -40,13 +37,15 @@ pub async fn refresh_entitlements(assyst: ThreadSafeAssyst) {
};

if let Err(e) = active.set(&assyst.database_handler).await {
err!(
"Error adding new entitlement from later fetch for ID {}: {e:?}",
active.entitlement_id
);
err!("Error adding new entitlement for ID {}: {e:?}", active.entitlement_id);
};
handle_log(format!("New entitlement! Guild: {}", active.guild_id));
assyst.entitlements.lock().unwrap().insert(active.guild_id, active);

assyst
.entitlements
.lock()
.unwrap()
.insert(active.entitlement_id, active);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl ActiveGuildPremiumEntitlement {
let rows = sqlx::query_as::<_, Self>(query).fetch_all(&handler.pool).await?;
let mut out = HashMap::new();
for r in rows {
out.insert(r.guild_id, r);
out.insert(r.entitlement_id, r);
}

Ok(out)
Expand Down

0 comments on commit 6075f17

Please sign in to comment.