Add warning system, role management, and guessing game

This commit is contained in:
2026-01-27 09:53:03 +01:00
parent 2edcf2ccf6
commit 31e9169231
5 changed files with 256 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
const { connectToDatabase } = require('../db');
const WARNING_COLLECTION = 'warnings';
const getWarningsCollection = async () => {
const client = await connectToDatabase();
return client.db('discord').collection(WARNING_COLLECTION);
};
const addWarning = async ({ guildId, userId, moderatorId, reason }) => {
const collection = await getWarningsCollection();
const warningEntry = {
reason,
moderatorId,
createdAt: new Date(),
};
const result = await collection.findOneAndUpdate(
{ guildId, userId },
{
$push: { warnings: warningEntry },
$setOnInsert: { guildId, userId },
},
{ upsert: true, returnDocument: 'after' },
);
const warnings = result.value?.warnings ?? [];
return { warnings, warningEntry };
};
const getWarnings = async ({ guildId, userId }) => {
const collection = await getWarningsCollection();
const record = await collection.findOne({ guildId, userId });
return record?.warnings ?? [];
};
module.exports = {
addWarning,
getWarnings,
};