From 4727434362a84fa10d70f84f2e90c8607ea1a580 Mon Sep 17 00:00:00 2001 From: admin_rb Date: Sat, 4 Jul 2026 04:00:12 +0200 Subject: [PATCH] changed from ISO to LocaleDateString, Made Regex work with Any Prefix --- commands/slash/applications/ezd.js | 39 +++++++++++++----------------- events/MessageCreate.js | 38 +++++++++++++++-------------- 2 files changed, 37 insertions(+), 40 deletions(-) diff --git a/commands/slash/applications/ezd.js b/commands/slash/applications/ezd.js index 316b173..fa61dd9 100644 --- a/commands/slash/applications/ezd.js +++ b/commands/slash/applications/ezd.js @@ -9,16 +9,6 @@ const { const { mClient } = require('../../..'); require('dotenv').config() -function formatGermanDate(dateStr) { - const date = new Date(dateStr); - - return new Intl.DateTimeFormat("de-DE", { - year: "numeric", - month: "2-digit", - day: "2-digit" - }).format(date); -} - module.exports = { data: new SlashCommandBuilder() .setName('ezd') @@ -28,7 +18,9 @@ module.exports = { const db = mClient.db(process.env.M_DB); // adjust if needed const coll = db.collection('items_daily_numbers'); - const today = new Date().toISOString().slice(0, 10); + const today = new Date().toLocaleDateString("en-CA", { + timeZone: "Europe/Berlin" + }); let currentDate = today; @@ -42,17 +34,21 @@ module.exports = { return `${emoji} **${label}:** ${v ? `<@${v.userId}>` : "—"}`; }; + const germanDate = new Date(`${date}T00:00:00`).toLocaleDateString("de-DE", { + timeZone: "Europe/Berlin", + day: "2-digit", + month: "2-digit", + year: "numeric" + }); + return new EmbedBuilder() - .setTitle(`📊 EZD Übersicht – ${formatGermanDate(date)}`) + .setTitle(`📊 EZD Übersicht – ${germanDate}`) .setColor(0x2b2d31) - .setDescription( - [ - line("🥇", "Erster", "Erster"), - line("🥈", "Zweiter", "Zweiter"), - line("🥉", "Dritter", "Dritter") - ].join("\n") - ) - .setFooter({ text: `Datum: ${date}` }); + .setDescription([ + line("🥇", "Ersti", "Ersti"), + line("🥈", "Zweiti", "Zweiti"), + line("🥉", "Dritti", "Dritti") + ].join("\n")); }; const buildButtons = (date) => { @@ -72,8 +68,7 @@ module.exports = { const msg = await interaction.reply({ embeds: [buildEmbed(doc, currentDate)], - components: [buildButtons(currentDate)], - flags: MessageFlags.Ephemeral + components: [buildButtons(currentDate)] }); const collector = msg.createMessageComponentCollector({ diff --git a/events/MessageCreate.js b/events/MessageCreate.js index 97a07ed..d46f328 100644 --- a/events/MessageCreate.js +++ b/events/MessageCreate.js @@ -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 = { } } -} \ No newline at end of file +}