Bewerbungen zusätzlich automatisch in Discord (Ticketanizer) posten
Jede eingehende Bewerbung landet weiterhin wie bisher in der D1-Datenbank, wird zusätzlich aber (falls eine Webhook-URL hinterlegt ist) als formatierte Discord-Nachricht in den passenden Kanal gepostet - pro Bewerbungsbereich (Modi/Scout/Creator/Kooperation) eine eigene Webhook-URL, exakt wie auf der Website getrennt. Läuft über normale Discord-Webhooks, kompatibel mit Ticketanizer, falls dessen Kanäle eigene Ziel-URLs im selben Format anbieten. - Neu: cloudflare-worker/src/lib/discord.js (Embed-Aufbau, Feld-Labels pro Formular, Farbe je Bewerbungsart) - applications.js: submitApplication ruft den Versand nach dem Speichern auf, über ctx.waitUntil() damit die Antwort an den Nutzer nicht wartet - worker.js: ctx wird jetzt an fetch() durchgereicht - Discord ist rein informativ - fehlt die Webhook-URL oder ist Discord kurz nicht erreichbar, wird die Bewerbung trotzdem ganz normal gespeichert - README.md: Einrichtungsanleitung (wrangler secret put DISCORD_WEBHOOK_*)
This commit is contained in:
@@ -7,6 +7,7 @@ import { generateId, nowIso } from "../lib/crypto.js";
|
||||
import { hasPermission } from "../lib/permissions.js";
|
||||
import { logAction } from "../lib/audit.js";
|
||||
import { json } from "../lib/http.js";
|
||||
import { bewerbungAnDiscordSenden } from "../lib/discord.js";
|
||||
|
||||
const ALLOWED_TYPES = ["creator", "scout", "kooperation", "modi"];
|
||||
|
||||
@@ -24,7 +25,7 @@ function viewPermissionForType(type) {
|
||||
return type === "creator" ? "APPLICATIONS_VIEW_CREATOR" : "APPLICATIONS_VIEW_MANAGER_SCOUT";
|
||||
}
|
||||
|
||||
export async function submitApplication(request, env) {
|
||||
export async function submitApplication(request, env, ctx) {
|
||||
let body;
|
||||
try {
|
||||
body = await request.json();
|
||||
@@ -45,6 +46,15 @@ export async function submitApplication(request, env) {
|
||||
.bind(id, type, JSON.stringify(data), nowIso())
|
||||
.run();
|
||||
|
||||
// Zusätzlich (rein informativ, blockiert die Bewerbung selbst nie) als
|
||||
// Nachricht in den passenden Discord-Kanal (Ticketanizer) weiterleiten.
|
||||
const discordVersand = bewerbungAnDiscordSenden(env, type, data);
|
||||
if (ctx && typeof ctx.waitUntil === "function") {
|
||||
ctx.waitUntil(discordVersand);
|
||||
} else {
|
||||
await discordVersand.catch(() => {});
|
||||
}
|
||||
|
||||
return json({ ok: true });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user