changed from ISO to LocaleDateString, Made Regex work with Any Prefix

This commit is contained in:
2026-07-04 04:00:12 +02:00
parent 6b2fab8b95
commit 4727434362
2 changed files with 37 additions and 40 deletions
+20 -18
View File
@@ -11,18 +11,23 @@ module.exports = {
if (message.author.bot) { return }
// Erster/Zweiter/Dritter Handler
if (message.channelId === '471058991481487361') {
const numbered = ["Erster", "Zweiter", "Dritter"];
if (message.channelId === '353902391021535244' || message.channelId === '471058991481487361') {
const numbered = {
Erst: "Ersti",
Zweit: "Zweiti",
Dritt: "Dritti"
};
// Regex-Erkennung (ganze Wörter, unabhängig von Groß-/Kleinschreibung)
const found = numbered.find(word =>
new RegExp(`\\b${word}\\b`, "i").test(message.content)
);
const found = Object.entries(numbered).find(([stem]) =>
new RegExp(`\\b${stem}\\w*\\b`, "i").test(message.content)
)?.[1];
if (!found) return;
const numberedColl = db.collection('items_daily_numbers');
const today = new Date().toISOString().slice(0, 10);
const today = new Date().toLocaleDateString("en-CA", {
timeZone: "Europe/Berlin"
});
// Tages-Dokument sicherstellen
await numberedColl.findOneAndUpdate(
@@ -31,9 +36,9 @@ module.exports = {
$setOnInsert: {
date: today,
positions: {
Erster: null,
Zweiter: null,
Dritter: null
Ersti: null,
Zweiti: null,
Dritti: null
}
}
},
@@ -46,14 +51,11 @@ module.exports = {
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 }
"positions.Ersti.userId": { $ne: message.author.id },
"positions.Zweiti.userId": { $ne: message.author.id },
"positions.Dritti.userId": { $ne: message.author.id }
},
{
$set: {
@@ -76,7 +78,7 @@ module.exports = {
// ✅ Erfolg
return message.reply({
content: `✅ Du bist ${found}! <@${message.author.id}>`,
content: `✅ Du bist ${found}! :point_right: :point_left: <@${message.author.id}>`,
flags: MessageFlags.Ephemeral
});
}
@@ -98,4 +100,4 @@ module.exports = {
}
}
}
}