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('../../..'); const { mClient } = require('../../..');
require('dotenv').config() 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 = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('ezd') .setName('ezd')
@@ -28,7 +18,9 @@ module.exports = {
const db = mClient.db(process.env.M_DB); // adjust if needed const db = mClient.db(process.env.M_DB); // adjust if needed
const coll = db.collection('items_daily_numbers'); 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; let currentDate = today;
@@ -42,17 +34,21 @@ module.exports = {
return `${emoji} **${label}:** ${v ? `<@${v.userId}>` : "—"}`; 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() return new EmbedBuilder()
.setTitle(`📊 EZD Übersicht ${formatGermanDate(date)}`) .setTitle(`📊 EZD Übersicht ${germanDate}`)
.setColor(0x2b2d31) .setColor(0x2b2d31)
.setDescription( .setDescription([
[ line("🥇", "Ersti", "Ersti"),
line("🥇", "Erster", "Erster"), line("🥈", "Zweiti", "Zweiti"),
line("🥈", "Zweiter", "Zweiter"), line("🥉", "Dritti", "Dritti")
line("🥉", "Dritter", "Dritter") ].join("\n"));
].join("\n")
)
.setFooter({ text: `Datum: ${date}` });
}; };
const buildButtons = (date) => { const buildButtons = (date) => {
@@ -72,8 +68,7 @@ module.exports = {
const msg = await interaction.reply({ const msg = await interaction.reply({
embeds: [buildEmbed(doc, currentDate)], embeds: [buildEmbed(doc, currentDate)],
components: [buildButtons(currentDate)], components: [buildButtons(currentDate)]
flags: MessageFlags.Ephemeral
}); });
const collector = msg.createMessageComponentCollector({ const collector = msg.createMessageComponentCollector({
+20 -18
View File
@@ -11,18 +11,23 @@ module.exports = {
if (message.author.bot) { return } if (message.author.bot) { return }
// Erster/Zweiter/Dritter Handler // Erster/Zweiter/Dritter Handler
if (message.channelId === '471058991481487361') { if (message.channelId === '353902391021535244' || message.channelId === '471058991481487361') {
const numbered = ["Erster", "Zweiter", "Dritter"]; const numbered = {
Erst: "Ersti",
Zweit: "Zweiti",
Dritt: "Dritti"
};
// Regex-Erkennung (ganze Wörter, unabhängig von Groß-/Kleinschreibung) const found = Object.entries(numbered).find(([stem]) =>
const found = numbered.find(word => new RegExp(`\\b${stem}\\w*\\b`, "i").test(message.content)
new RegExp(`\\b${word}\\b`, "i").test(message.content) )?.[1];
);
if (!found) return; if (!found) return;
const numberedColl = db.collection('items_daily_numbers'); 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 // Tages-Dokument sicherstellen
await numberedColl.findOneAndUpdate( await numberedColl.findOneAndUpdate(
@@ -31,9 +36,9 @@ module.exports = {
$setOnInsert: { $setOnInsert: {
date: today, date: today,
positions: { positions: {
Erster: null, Ersti: null,
Zweiter: null, Zweiti: null,
Dritter: null Dritti: null
} }
} }
}, },
@@ -46,14 +51,11 @@ module.exports = {
const result = await numberedColl.findOneAndUpdate( const result = await numberedColl.findOneAndUpdate(
{ {
date: today, date: today,
// Position frei
[`positions.${found}`]: null, [`positions.${found}`]: null,
// User hat noch keine Position "positions.Ersti.userId": { $ne: message.author.id },
"positions.Erster.userId": { $ne: message.author.id }, "positions.Zweiti.userId": { $ne: message.author.id },
"positions.Zweiter.userId": { $ne: message.author.id }, "positions.Dritti.userId": { $ne: message.author.id }
"positions.Dritter.userId": { $ne: message.author.id }
}, },
{ {
$set: { $set: {
@@ -76,7 +78,7 @@ module.exports = {
// ✅ Erfolg // ✅ Erfolg
return message.reply({ return message.reply({
content: `✅ Du bist ${found}! <@${message.author.id}>`, content: `✅ Du bist ${found}! :point_right: :point_left: <@${message.author.id}>`,
flags: MessageFlags.Ephemeral flags: MessageFlags.Ephemeral
}); });
} }
@@ -98,4 +100,4 @@ module.exports = {
} }
} }
} }