feat(cooldown): implement cooldown management functions for user actions

This commit is contained in:
2025-10-05 00:51:13 -05:00
parent 767b1ee63a
commit fcc400f671

View File

@@ -0,0 +1,20 @@
import { prisma } from '../../core/database/prisma';
export async function getCooldown(userId: string, guildId: string, key: string) {
return prisma.actionCooldown.findUnique({ where: { userId_guildId_key: { userId, guildId, key } } });
}
export async function setCooldown(userId: string, guildId: string, key: string, seconds: number) {
const until = new Date(Date.now() + Math.max(0, seconds) * 1000);
return prisma.actionCooldown.upsert({
where: { userId_guildId_key: { userId, guildId, key } },
update: { until },
create: { userId, guildId, key, until },
});
}
export async function assertNotOnCooldown(userId: string, guildId: string, key: string) {
const cd = await getCooldown(userId, guildId, key);
if (cd && cd.until > new Date()) throw new Error('Cooldown activo');
}