EZD Logik
This commit is contained in:
+13
-8
@@ -50,8 +50,19 @@ module.exports = {
|
||||
|
||||
if (!dbEntry) continue;
|
||||
|
||||
// skip if already notified
|
||||
if (dbEntry.notified) {
|
||||
// Reset notification once the birthday has passed
|
||||
if (!isToday(dbEntry.day, dbEntry.month) && dbEntry.notified) {
|
||||
await bdayColl.updateOne(
|
||||
{ userID: member.id },
|
||||
{ $set: { notified: false } }
|
||||
);
|
||||
|
||||
dbEntry.notified = false; // keep local copy in sync
|
||||
console.log(`Removed notified flag for ${member.user.tag}`);
|
||||
}
|
||||
|
||||
// Skip if already handled today
|
||||
if (dbEntry.notified && isToday(dbEntry.day, dbEntry.month)) {
|
||||
console.log(`${member.user.username} was already notified today, skipping...`);
|
||||
continue;
|
||||
}
|
||||
@@ -78,12 +89,6 @@ module.exports = {
|
||||
|
||||
console.log(`Removed birthday role from ${member.user.tag}`);
|
||||
}
|
||||
|
||||
// reset notification flag if not birthday anymore
|
||||
await bdayColl.updateOne(
|
||||
{ userID: member.id },
|
||||
{ $set: { notified: false } }
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@ async function commandHandler(interaction) {
|
||||
}
|
||||
async function buttonHandler(interaction) {
|
||||
const button = interaction.client.buttons.get(interaction.customId)
|
||||
if (!button) { return console.error(`No button registered matching ${interaction.customId}.`) }
|
||||
if (!button) { return }// console.error(`No button registered matching ${interaction.customId}.`) }
|
||||
try {
|
||||
await button.execute(interaction);
|
||||
} catch (error) {
|
||||
|
||||
+83
-6
@@ -1,20 +1,97 @@
|
||||
const { Events } = require('discord.js')
|
||||
const { Events, MessageFlags } = require('discord.js')
|
||||
require('dotenv').config()
|
||||
const { client } = require('../index')
|
||||
const { client, mClient } = require('../index')
|
||||
const prefix = process.env.D_Prefix
|
||||
const db = mClient.db(process.env.M_DB)
|
||||
|
||||
module.exports = {
|
||||
name: Events.MessageCreate,
|
||||
once: false,
|
||||
async execute(message) {
|
||||
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
||||
if (message.author.bot) { return }
|
||||
|
||||
// Erster/Zweiter/Dritter Handler
|
||||
if (message.channelId === '471058991481487361') {
|
||||
const numbered = ["Erster", "Zweiter", "Dritter"];
|
||||
|
||||
// Regex-Erkennung (ganze Wörter, unabhängig von Groß-/Kleinschreibung)
|
||||
const found = numbered.find(word =>
|
||||
new RegExp(`\\b${word}\\b`, "i").test(message.content)
|
||||
);
|
||||
|
||||
if (!found) return;
|
||||
|
||||
const numberedColl = db.collection('items_daily_numbers');
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
|
||||
// Tages-Dokument sicherstellen
|
||||
await numberedColl.findOneAndUpdate(
|
||||
{ date: today },
|
||||
{
|
||||
$setOnInsert: {
|
||||
date: today,
|
||||
positions: {
|
||||
Erster: null,
|
||||
Zweiter: null,
|
||||
Dritter: null
|
||||
}
|
||||
}
|
||||
},
|
||||
{ upsert: true }
|
||||
);
|
||||
|
||||
// 🔒 Atomarer Claim:
|
||||
// - Position muss frei sein
|
||||
// - User darf noch keine Position heute haben
|
||||
const result = await numberedColl.findOneAndUpdate(
|
||||
{
|
||||
date: today,
|
||||
|
||||
// Position frei
|
||||
[`positions.${found}`]: null,
|
||||
|
||||
// User hat noch keine Position
|
||||
"positions.Erster.userId": { $ne: message.author.id },
|
||||
"positions.Zweiter.userId": { $ne: message.author.id },
|
||||
"positions.Dritter.userId": { $ne: message.author.id }
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
[`positions.${found}`]: {
|
||||
userId: message.author.id,
|
||||
timestamp: new Date()
|
||||
}
|
||||
}
|
||||
},
|
||||
{ returnDocument: "after" }
|
||||
);
|
||||
|
||||
// ❌ bereits vergeben oder schon eine Position
|
||||
if (!result) {
|
||||
return message.reply({
|
||||
content: `❌ Du kannst pro Tag nur eine Position beanspruchen, und sie muss noch frei sein.`,
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
}
|
||||
|
||||
// ✅ Erfolg
|
||||
return message.reply({
|
||||
content: `✅ Du bist ${found}! <@${message.author.id}>`,
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
}
|
||||
|
||||
// Command Handler
|
||||
const args = message.content.slice(prefix.length).trim().split(/ +/);
|
||||
if (!message.content.startsWith(prefix)) return;
|
||||
|
||||
const cmd = args.shift().toLowerCase();
|
||||
let command = client.legacyCommands.get(cmd)
|
||||
if(!command) command = client.legacyCommands.get(client.aliases.get(cmd))
|
||||
if(!command) return
|
||||
try {
|
||||
|
||||
|
||||
if (!command) command = client.legacyCommands.get(client.aliases.get(cmd))
|
||||
if (!command) return
|
||||
try {
|
||||
client.legacyCommands.get(command.name).execute(message, args)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
|
||||
Reference in New Issue
Block a user