diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0be2a391..55ff2dff 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -159,7 +159,7 @@ model userData { // username is only guarenteed to be set and/or used for blacklisted users username String? locale String? - lastVoted Int? + lastVoted DateTime? voteCount Int @default(0) blacklistedFrom hubBlacklist[] // if user has seen the welcome message when they first use the network diff --git a/src/managers/VoteManager.ts b/src/managers/VoteManager.ts index 3aec9542..0d75081d 100644 --- a/src/managers/VoteManager.ts +++ b/src/managers/VoteManager.ts @@ -22,9 +22,7 @@ export class VoteManager extends EventEmitter { this.cluster = cluster; this.scheduler = scheduler; this.scheduler.addRecurringTask('removeVoterRole', 60 * 60 * 1_000, async () => { - const expiredVotes = await db.userData.findMany({ - where: { lastVoted: { lt: new Date().getTime() } }, - }); + const expiredVotes = await db.userData.findMany({ where: { lastVoted: { lt: new Date() } } }); for (const vote of expiredVotes) { this.emit('voteExpired', vote.userId); await this.removeVoterRole(vote.userId); @@ -50,7 +48,7 @@ export class VoteManager extends EventEmitter { } async incrementUserVote(userId: string, username?: string) { - const lastVoted = new Date().getTime(); + const lastVoted = new Date(); return await db.userData.upsert({ where: { userId }, create: { @@ -88,7 +86,7 @@ export class VoteManager extends EventEmitter { `, ) .setFooter({ text: `This is your ${voteCount}${ordinalSuffix} time voting!` }) - .setColor('Orange'), + .setColor('Green'), ], }); } diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 1a5bc19c..aa7b3f97 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -87,10 +87,14 @@ export const hasVoted = async (userId: Snowflake): Promise => { }; export const userVotedToday = async (userId: Snowflake): Promise => { - const res = await db.userData.findFirst({ where: { userId } }); + const res = await db.userData.findFirst({ + where: { + userId, + lastVoted: { gte: new Date(Date.now() - 60 * 60 * 24 * 1000) }, + }, + }); - const oneDay = Date.now() - 60 * 60 * 24 * 1000; - return (res?.lastVoted && res.lastVoted > oneDay) === true; + return Boolean(res?.lastVoted); }; export const yesOrNoEmoji = (option: unknown, yesEmoji: string, noEmoji: string) => {