Skip to content

Commit

Permalink
fix: handle unavailable guilds
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Aug 21, 2022
1 parent 204e7e6 commit 5519bb2
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions src/events/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub async fn load_muted_members(ctx: &serenity::Context, _: &serenity::Ready) {
let data = get_data_lock(ctx).await;
let data = data.read().await;
let database = &data.database;
let mute_role_id = data.configuration.read().await.general.mute.role;
let mut pending_unmutes = data.pending_unmutes.write().await;
let mute_role_id = data.configuration.general.mute.role;
let mut pending_unmutes = data.pending_unmutes.lock().await;

let mut cursor = database
.find::<Muted>(
Expand All @@ -32,28 +32,26 @@ pub async fn load_muted_members(ctx: &serenity::Context, _: &serenity::Ready) {
let guild_id = current.guild_id.unwrap().parse::<u64>().unwrap();
let member_id = current.user_id.unwrap().parse::<u64>().unwrap();

if let Ok(member) = http_ref
.get_guild(guild_id)
.await
.unwrap()
.member(http_ref, member_id)
.await
{
let amount_left =
std::cmp::max(current.expires.unwrap() as i64 - Utc::now().timestamp(), 0);
if let Ok(guild) = http_ref.get_guild(guild_id).await {
if let Ok(member) = guild.member(http_ref, member_id).await {
let amount_left =
std::cmp::max(current.expires.unwrap() as i64 - Utc::now().timestamp(), 0);

pending_unmutes.insert(
member.user.id.0,
queue_unmute_member(
ctx,
database,
&member,
mute_role_id,
amount_left as u64, // i64 as u64 is handled properly here
),
);
pending_unmutes.insert(
member.user.id.0,
queue_unmute_member(
ctx,
database,
&member,
mute_role_id,
amount_left as u64, // i64 as u64 is handled properly here
),
);
} else {
trace!("Failed to find member {} in guild {}", member_id, guild_id);
}
} else {
trace!("Failed to find member {} in guild {}", member_id, guild_id);
trace!("Guild {} unavailable", guild_id);
}
}
}

0 comments on commit 5519bb2

Please sign in to comment.