Skip to content

Commit 5fa9631

Browse files
committed
Fix bug
1 parent 759f1d1 commit 5fa9631

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/commands/penis.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,14 @@ export default class PenisCommand implements MessageCommand {
138138
}
139139

140140
async #getOrCreateMeasurement(userToMeasure: User): Promise<Penis> {
141-
const recentMeasurement = await penis.fetchRecentMeasurement(userToMeasure);
142-
if (recentMeasurement !== undefined) {
143-
return recentMeasurement;
141+
const lastMeasurement = await penis.fetchLastMeasurement(userToMeasure);
142+
if (lastMeasurement !== undefined) {
143+
const now = new Date();
144+
const measurement = new Date(`${lastMeasurement.measuredAt}Z`);
145+
// TODO: Make use of temporal lol
146+
if (measurement.toISOString().split("T")[0] === now.toISOString().split("T")[0]) {
147+
return lastMeasurement;
148+
}
144149
}
145150

146151
log.debug(`No recent measuring of ${userToMeasure.id} found. Creating Measurement.`);

src/storage/penis.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@ export function insertMeasurement(
2626
.executeTakeFirstOrThrow();
2727
}
2828

29-
export function fetchRecentMeasurement(user: User, ctx = db()): Promise<Penis | undefined> {
30-
const now = Temporal.Now.instant();
31-
const { startOfToday, startOfTomorrow } = getStartAndEndDay(now);
32-
29+
export function fetchLastMeasurement(user: User, ctx = db()): Promise<Penis | undefined> {
3330
return ctx
3431
.selectFrom("penis")
3532
.where("userId", "=", user.id)
36-
.where("measuredAt", ">=", startOfToday.toString())
37-
.where("measuredAt", "<", startOfTomorrow.toString())
33+
.orderBy("id", "desc")
34+
.limit(1)
3835
.selectAll()
3936
.executeTakeFirst();
4037
}

0 commit comments

Comments
 (0)