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
+17 -22
View File
@@ -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({
+19 -17
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
});
}