mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-19 12:44:17 +02:00
feat(arabot): add vcmute database utils
This commit is contained in:
parent
b14de47934
commit
0e31061d99
66
src/utils/database/vcMute.ts
Normal file
66
src/utils/database/vcMute.ts
Normal file
@ -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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user