hinzugefügt: Grund für Tausch + Discord benachrichtigung + PWA

This commit is contained in:
Honey committed 2026-02-08 19:52:32 +01:00
1 parent dae99a0b76
commit 497faa72db
8 files changed
+175 -48

No files matched your search

+37 -20
View File
@@ -45,7 +45,7 @@ function getState() {
if (!fs.existsSync(stateFile)) {
fs.writeFileSync(
stateFile,
JSON.stringify({ current: "A" }, null, 2)
JSON.stringify({ current: "A", lastReason: null }, null, 2)
);
}
return JSON.parse(fs.readFileSync(stateFile, "utf-8"));
@@ -58,12 +58,34 @@ function setState(newState) {
// --------------------
// Discord Webhook
// --------------------
async function sendDiscordEmbed(previousKey, currentKey) {
async function sendDiscordEmbed(previousKey, currentKey, reason) {
const previous = CONFIG[previousKey];
const current = CONFIG[currentKey];
if (!DISCORD_WEBHOOK_URL) return;
const fields = [
{
name: "Von",
value: previous.name,
inline: true
},
{
name: "Zu",
value: current.name,
inline: true
}
];
// Add reason field if provided
if (reason) {
fields.push({
name: "📝 Grund",
value: reason,
inline: false
});
}
const embed = {
title: "💸 Zahl-Wechsel",
description: `**${current.name}** ist jetzt dran zu zahlen`,
@@ -71,18 +93,7 @@ async function sendDiscordEmbed(previousKey, currentKey) {
thumbnail: {
url: `${PUBLIC_BASE_URL}/img/${current.icon}`
},
fields: [
{
name: "Von",
value: previous.name,
inline: true
},
{
name: "Zu",
value: current.name,
inline: true
}
],
fields: fields,
footer: {
text: new Date().toLocaleString("de-DE")
}
@@ -96,8 +107,9 @@ async function sendDiscordEmbed(previousKey, currentKey) {
embeds: [embed]
})
});
console.log("✅ Discord Benachrichtigung gesendet");
} catch (err) {
console.error("Discord Webhook Fehler:", err.message);
console.error("❌ Discord Webhook Fehler:", err.message);
}
}
@@ -115,19 +127,24 @@ app.get("/status", (req, res) => {
app.post("/toggle", async (req, res) => {
const state = getState();
const previousKey = state.current;
const reason = req.body?.reason;
state.current = state.current === "A" ? "B" : "A";
state.lastReason = reason || null;
setState(state);
console.log(
`Zahl-Wechsel: ${CONFIG[previousKey].name} → ${CONFIG[state.current].name}`
);
const logMessage = reason
? `Zahl-Wechsel: ${CONFIG[previousKey].name} → ${CONFIG[state.current].name} (Grund: ${reason})`
: `Zahl-Wechsel: ${CONFIG[previousKey].name} → ${CONFIG[state.current].name}`;
console.log(logMessage);
await sendDiscordEmbed(previousKey, state.current);
await sendDiscordEmbed(previousKey, state.current, reason);
res.json({
current: state.current,
name: CONFIG[state.current].name
name: CONFIG[state.current].name,
lastReason: state.lastReason
});
});