feat(arabot): add temp ban database utilities

This commit is contained in:
smyalygames 2023-02-17 01:03:42 +00:00
parent e8fac57b72
commit 48125ba896

View File

@ -0,0 +1,98 @@
import { container } from '@sapphire/framework';
import type { Snowflake } from 'discord.js';
export async function addTempBan(
userId: Snowflake,
modId: Snowflake,
endTime: Date,
reason: string,
) {
// Add the user to the database
await container.database.tempBan.create({
data: {
user: {
connect: {
id: userId,
},
},
mod: {
connect: {
id: modId,
},
},
endTime,
reason,
},
});
}
export async function removeTempBan(userId: Snowflake, modId?: Snowflake) {
const ban = await container.database.tempBan.findFirst({
where: {
userId,
},
orderBy: {
id: 'desc',
},
});
if (ban === null) {
return;
}
if (modId !== undefined) {
await container.database.tempBan.update({
where: {
id: ban.id,
},
data: {
endModId: modId,
active: false,
},
});
return;
}
await container.database.tempBan.update({
where: {
id: ban.id,
},
data: {
active: false,
},
});
}
export async function checkTempBan(userId: Snowflake) {
const ban = await container.database.tempBan.findFirst({
where: {
userId,
},
orderBy: {
id: 'desc',
},
});
if (ban === null) {
return false;
}
return ban.active;
}
export async function getTempBanReason(userId: Snowflake) {
const ban = await container.database.tempBan.findFirst({
where: {
userId,
},
orderBy: {
id: 'desc',
},
});
if (ban === null) {
return '';
}
return ban.reason;
}