Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit 343b568

Browse files
committed
fix: fix vote timestamp not getting set properly
1 parent 24f46cc commit 343b568

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ model userData {
159159
// username is only guarenteed to be set and/or used for blacklisted users
160160
username String?
161161
locale String?
162-
lastVoted Int?
162+
lastVoted DateTime?
163163
voteCount Int @default(0)
164164
blacklistedFrom hubBlacklist[]
165165
// if user has seen the welcome message when they first use the network

src/managers/VoteManager.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ export class VoteManager extends EventEmitter {
2222
this.cluster = cluster;
2323
this.scheduler = scheduler;
2424
this.scheduler.addRecurringTask('removeVoterRole', 60 * 60 * 1_000, async () => {
25-
const expiredVotes = await db.userData.findMany({
26-
where: { lastVoted: { lt: new Date().getTime() } },
27-
});
25+
const expiredVotes = await db.userData.findMany({ where: { lastVoted: { lt: new Date() } } });
2826
for (const vote of expiredVotes) {
2927
this.emit('voteExpired', vote.userId);
3028
await this.removeVoterRole(vote.userId);
@@ -50,7 +48,7 @@ export class VoteManager extends EventEmitter {
5048
}
5149

5250
async incrementUserVote(userId: string, username?: string) {
53-
const lastVoted = new Date().getTime();
51+
const lastVoted = new Date();
5452
return await db.userData.upsert({
5553
where: { userId },
5654
create: {
@@ -88,7 +86,7 @@ export class VoteManager extends EventEmitter {
8886
`,
8987
)
9088
.setFooter({ text: `This is your ${voteCount}${ordinalSuffix} time voting!` })
91-
.setColor('Orange'),
89+
.setColor('Green'),
9290
],
9391
});
9492
}

src/utils/Utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ export const hasVoted = async (userId: Snowflake): Promise<boolean> => {
8787
};
8888

8989
export const userVotedToday = async (userId: Snowflake): Promise<boolean> => {
90-
const res = await db.userData.findFirst({ where: { userId } });
90+
const res = await db.userData.findFirst({
91+
where: {
92+
userId,
93+
lastVoted: { gte: new Date(Date.now() - 60 * 60 * 24 * 1000) },
94+
},
95+
});
9196

92-
const oneDay = Date.now() - 60 * 60 * 24 * 1000;
93-
return (res?.lastVoted && res.lastVoted > oneDay) === true;
97+
return Boolean(res?.lastVoted);
9498
};
9599

96100
export const yesOrNoEmoji = (option: unknown, yesEmoji: string, noEmoji: string) => {

0 commit comments

Comments
 (0)