Skip to content

Commit

Permalink
chore: fix all warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
matteopolak committed Mar 26, 2024
1 parent 0cade9d commit bfc7598
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 24 deletions.
4 changes: 0 additions & 4 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#![feature(exclusive_range_pattern)]
#![feature(assert_matches)]
#![feature(associated_type_defaults)]
// Temporarily suppress a few clippy warnings
// See: https://github.com/SoftbearStudios/bitcode/issues/7
// TODO: Remember to remove this once it has been fixed
#![allow(clippy::verbose_bit_mask)]

mod extras;

Expand Down
2 changes: 1 addition & 1 deletion crates/statpixel/src/commands/at/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub async fn guild_command(

let png: Option<Cow<_>> = if let snapshot::guild::Status::Found((ref guild, _)) = status {
let guilds =
get_snapshots_multiple_of_weekday(ctx, guild, Utc::now() - chrono::Duration::days(30))
get_snapshots_multiple_of_weekday(ctx, guild, Utc::now() - chrono::Duration::try_days(30).unwrap())
.await?;
let monthly_xp = get_monthly_xp(guild, &guilds);

Expand Down
4 changes: 2 additions & 2 deletions crates/statpixel/src/commands/guild/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ pub async fn general(
background: Option<Color>,
) -> Result<Cow<'static, [u8]>, Error> {
let guilds =
get_snapshots_multiple_of_weekday(ctx, guild, Utc::now() - chrono::Duration::days(30))
get_snapshots_multiple_of_weekday(ctx, guild, Utc::now() - chrono::Duration::try_days(30).unwrap())
.await?;
let monthly_xp = get_monthly_xp(guild, &guilds);

Expand Down Expand Up @@ -452,7 +452,7 @@ pub async fn member(
background: Option<Color>,
) -> Result<Cow<'static, [u8]>, Error> {
let guilds =
get_snapshots_multiple_of_weekday(ctx, guild, Utc::now() - chrono::Duration::days(30))
get_snapshots_multiple_of_weekday(ctx, guild, Utc::now() - chrono::Duration::try_days(30).unwrap())
.await?;

let member_xp = get_member_monthly_xp(guild, &guilds);
Expand Down
2 changes: 1 addition & 1 deletion crates/statpixel/src/commands/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async fn top(
name,
player,
uuid,
days.map_or(chrono::Duration::days(30), chrono::Duration::days),
days.map_or(chrono::Duration::try_days(30).unwrap(), |d| chrono::Duration::try_days(d).unwrap()),
limit,
None,
)
Expand Down
6 changes: 3 additions & 3 deletions crates/statpixel/src/commands/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,6 @@ macro_rules! commands {
};
}

commands!(daily, ::chrono::Duration::days(1), "daily");
commands!(weekly, ::chrono::Duration::weeks(1), "weekly");
commands!(monthly, ::chrono::Duration::days(30), "monthly");
commands!(daily, ::chrono::Duration::try_days(1).unwrap(), "daily");
commands!(weekly, ::chrono::Duration::try_weeks(1).unwrap(), "weekly");
commands!(monthly, ::chrono::Duration::try_days(30).unwrap(), "monthly");
2 changes: 1 addition & 1 deletion crates/statpixel/src/id/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ pub async fn map(
family,
&guild,
limit.unwrap_or(30),
Utc::now() - nanos.map_or(Duration::days(30), Duration::nanoseconds),
Utc::now() - nanos.map_or(Duration::try_days(30).unwrap(), Duration::nanoseconds),
background,
)
.await
Expand Down
2 changes: 1 addition & 1 deletion crates/statpixel/src/id/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub async fn map(ctx: &Context<'_>, id: Id) -> Result<(), Error> {
None,
None,
member_id,
nanos.map_or(chrono::Duration::days(30), chrono::Duration::nanoseconds),
nanos.map_or(chrono::Duration::try_days(30).unwrap(), chrono::Duration::nanoseconds),
limit.unwrap_or(30),
Some(uuid),
)
Expand Down
2 changes: 1 addition & 1 deletion crates/statpixel/src/server/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ pub fn create_token(id: u64, name: String) -> String {
#[allow(clippy::cast_possible_truncation)]
#[allow(clippy::cast_sign_loss)]
let claims = Claims {
exp: (now + Duration::days(30)).timestamp() as usize,
exp: (now + Duration::try_days(30).unwrap()).timestamp() as usize,
iat: now.timestamp() as usize,
iss: "https://statpixel.xyz".to_string(),
id,
Expand Down
2 changes: 1 addition & 1 deletion crates/statpixel/src/server/topgg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub async fn add_vote(
.values((
user::id.eq(id as i64),
user::votes.eq(1),
user::premium_until.eq(Utc::now() + Duration::days(3)),
user::premium_until.eq(Utc::now() + Duration::try_days(3).unwrap()),
))
.on_conflict(user::id)
.do_update()
Expand Down
2 changes: 1 addition & 1 deletion crates/statpixel/src/server/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub async fn post(
let prev_hash = diesel::update(
schedule::table
.filter(schedule::uuid.eq(data.uuid))
.filter(schedule::vendor_update_at.lt(Utc::now() - Duration::minutes(15))),
.filter(schedule::vendor_update_at.lt(Utc::now() - Duration::try_minutes(15).unwrap())),
)
.set((
schedule::vendor_update_at.eq(Utc::now()),
Expand Down
4 changes: 2 additions & 2 deletions crates/statpixel/src/snapshot/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn update(
let days = (now.timestamp() / 60 / 60 / 24) as i32;

let next = {
let increase = chrono::Duration::hours(12);
let increase = chrono::Duration::try_hours(12).unwrap();
let next = timestamp + increase;

if next > now {
Expand Down Expand Up @@ -229,7 +229,7 @@ pub async fn insert(ctx: &Context<'_>, guild: &Guild) -> Result<(), Error> {
// Schedule the first update for one hour from now.
// The first few updates should be more frequent to calculate the
// timezone of the player.
guild_schedule::update_at.eq(now + chrono::Duration::hours(12)),
guild_schedule::update_at.eq(now + chrono::Duration::try_hours(12).unwrap()),
// Set the number of snapshots to 1, since we just inserted one.
guild_schedule::snapshots.eq(1),
guild_schedule::hash.eq(hash),
Expand Down
12 changes: 6 additions & 6 deletions crates/statpixel/src/snapshot/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async fn update(
|| (snapshots - CALCULATION_PERIOD_SNAPSHOTS) % FULL_PERIOD_SNAPSHOTS
> REGULAR_PERIOD_SNAPSHOTS
{
let increase = chrono::Duration::hours(i64::from(CALCULATION_WEEK_TIME_STEP_HOURS));
let increase = chrono::Duration::try_hours(i64::from(CALCULATION_WEEK_TIME_STEP_HOURS)).unwrap();
let next = timestamp + increase;

if next > now {
Expand All @@ -108,7 +108,7 @@ async fn update(
}
}
} else {
let time = timestamp + chrono::Duration::days(1);
let time = timestamp + chrono::Duration::try_days(1).unwrap();
let weekday = time.weekday();
let weekday = weekday.num_days_from_monday();

Expand Down Expand Up @@ -261,8 +261,8 @@ pub async fn begin(
// However, we can only fetch ones that update within 3 hours, since other profiles
// could be added while this is active that might need to update in 3 hours.
let players = schedule::table
.filter(schedule::update_at.le(now + chrono::Duration::hours(3)))
.filter(schedule::active_at.gt(now - chrono::Duration::weeks(1)))
.filter(schedule::update_at.le(now + chrono::Duration::try_hours(3).unwrap()))
.filter(schedule::active_at.gt(now - chrono::Duration::try_weeks(1).unwrap()))
.select((
schedule::uuid,
schedule::update_at,
Expand Down Expand Up @@ -526,7 +526,7 @@ pub async fn insert(ctx: &Context<'_>, player: &Player, data: &Data) -> Result<(
// Schedule the first update for one hour from now.
// The first few updates should be more frequent to calculate the
// timezone of the player.
schedule::update_at.eq(Utc::now() + chrono::Duration::hours(3)),
schedule::update_at.eq(Utc::now() + chrono::Duration::try_hours(3).unwrap()),
// Set the number of snapshots to 1, since we just inserted one.
schedule::snapshots.eq(1),
schedule::hash.eq(hash),
Expand Down Expand Up @@ -586,7 +586,7 @@ pub async fn insert_with_session(
// Schedule the first update for one hour from now.
// The first few updates should be more frequent to calculate the
// timezone of the player.
schedule::update_at.eq(Utc::now() + chrono::Duration::hours(3)),
schedule::update_at.eq(Utc::now() + chrono::Duration::try_hours(3).unwrap()),
// Set the number of snapshots to 1, since we just inserted one.
schedule::snapshots.eq(1),
schedule::hash.eq(hash),
Expand Down

0 comments on commit bfc7598

Please sign in to comment.