From 0e31061d9984cff7104f866aa171f8fc485c680d Mon Sep 17 00:00:00 2001 From: smyalygames Date: Sat, 11 Feb 2023 00:35:51 +0000 Subject: [PATCH] feat(arabot): add vcmute database utils --- src/utils/database/vcMute.ts | 66 ++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/utils/database/vcMute.ts diff --git a/src/utils/database/vcMute.ts b/src/utils/database/vcMute.ts new file mode 100644 index 0000000..3cb4bf7 --- /dev/null +++ b/src/utils/database/vcMute.ts @@ -0,0 +1,66 @@ +import { container } from '@sapphire/framework'; +import type { Snowflake } from 'discord.js'; + +export async function addMute(userId: Snowflake, modId: Snowflake, reason: string | null) { + // Add the user to the database + await container.database.vCMute.create({ + data: { + user: { + connect: { + id: userId, + }, + }, + mod: { + connect: { + id: modId, + }, + }, + reason, + }, + }); +} + +export async function removeMute(userId: Snowflake) { + const ban = await container.database.vCMute.findFirst({ + where: { + userId, + }, + select: { + id: true, + }, + orderBy: { + id: 'desc', + }, + }); + + if (ban === null) { + return; + } + + // Query to deactivate the specific sus note + await container.database.vCMute.update({ + where: { + id: ban.id, + }, + data: { + endTime: new Date(), + }, + }); +} + +export async function checkActive(userId: Snowflake) { + const ban = await container.database.vCMute.findFirst({ + where: { + userId, + }, + select: { + endTime: true, + }, + orderBy: { + id: 'desc', + }, + }); + + return !(ban === null + || ban.endTime === null); +}