Files
LazyBot/app/public/guild.html
T
2026-01-16 00:25:06 +01:00

344 lines
11 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Dashboard du serveur</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/guild.css">
</head>
<body>
<nav>
<a href="/">Accueil</a>
<a href="/dashboard">Tableau de bord</a>
</nav>
<h1 id="guild-name">Chargement...</h1>
<form id="welcome-form">
<label>
<input type="checkbox" id="welcome-enabled" />
Activer le message de bienvenue
</label>
<label>
Canal de bienvenue :
<br />
<select id="welcome-channel">
</select>
</label>
<label>
Message :
<br />
<textarea
id="welcome-message"
rows="4"
cols="50"
placeholder="Ex : Bienvenue {user} sur {server} 🎉"
></textarea>
</label>
<small>
Variables disponibles :
<ul>
<li><code>{user}</code> → nom de l'utilisateur</li>
<li><code>{mention}</code> → mention de l'utilisateur</li>
<li><code>{server}</code> → nom du serveur</li>
</ul>
</small>
<button type="submit">Sauvegarder</button>
<div id="status-welcome-form"></div>
</form>
<form id="goodbye-form">
<label>
<input type="checkbox" id="goodbye-enabled" />
Activer le message d'au revoir
</label>
<label>
Canal d'au revoir :
<br />
<select id="goodbye-channel">
</select>
</label>
<label>
Message :
<br />
<textarea
id="goodbye-message"
rows="4"
cols="50"
placeholder="Ex : Au revoir {user}, on espère te revoir sur {server} 👋"
></textarea>
</label>
<small>
Variables disponibles :
<ul>
<li><code>{user}</code> → nom de l'utilisateur</li>
<li><code>{server}</code> → nom du serveur</li>
</ul>
</small>
<button type="submit">Sauvegarder</button>
<div id="status-goodbye-form"></div>
</form>
<form id="autorole-newuser-form">
<label>
<input type="checkbox" id="autorole-enabled" />
Activer le rôle automatique pour les nouveaux membres
</label>
<label>
Rôle à attribuer :
<br />
<select id="autorole-role">
</select>
</label>
<button type="submit">Sauvegarder</button>
<div id="status-autorole-form"></div>
</form>
<form id="autorole-vocal-form">
<label>
<input type="checkbox" id="autorole-vocal-enabled" />
Activer le rôle automatique pour les membres en vocal
</label>
<label>
Rôle à attribuer :
<br />
<select id="autorole-vocal-role">
</select>
</label>
<label>
Salon à éviter :
<br />
<select id="autorole-vocal-exclude-channel" multiple size="5">
</select>
</label>
<button type="submit">Sauvegarder</button>
<div id="status-autorole-vocal-form"></div>
</form>
<script>
const guildId = window.location.pathname.split("/")[2]; // récupère l'ID du serveur
// Afficher le nom du serveur
fetch("/api/guilds")
.then((res) => res.json())
.then((guilds) => {
const guild = guilds.find((g) => g.id === guildId);
if (!guild) {
document.getElementById("guild-name").textContent =
"Serveur introuvable ou accès refusé";
return;
}
document.getElementById(
"guild-name"
).textContent = `Dashboard : ${guild.name}`;
});
fetch(`/api/bot/get-text-channels/${guildId}`)
.then(res => res.json())
.then(channels => {
const selectWelcome = document.getElementById("welcome-channel");
const selectGoodbye = document.getElementById("goodbye-channel");
channels.forEach(channel => {
const option = document.createElement("option");
option.value = channel.id;
option.textContent = `#${channel.name}`;
selectWelcome.appendChild(option);
selectGoodbye.appendChild(option.cloneNode(true));
});
});
const selectExclude = document.getElementById("autorole-vocal-exclude-channel");
selectExclude.innerHTML = ""; // reset
fetch(`/api/bot/get-voice-channels/${guildId}`)
.then(res => res.json())
.then(channels => {
channels.forEach(channel => {
const option = document.createElement("option");
option.value = channel.id;
option.textContent = `#${channel.name}`;
selectExclude.appendChild(option);
});
return fetch(`/api/bot/get-autorole-vocal-config/${guildId}`);
})
.then(res => res.json())
.then(cfg => {
document.getElementById("autorole-vocal-enabled").checked = !!cfg.enabled;
document.getElementById("autorole-vocal-role").value = cfg.roleId ?? "";
const excluded = Array.isArray(cfg.excludeChannelIds)
? cfg.excludeChannelIds.map(String) // sécurité
: [];
Array.from(selectExclude.options).forEach(option => {
option.selected = excluded.includes(option.value);
});
})
.catch(console.error);
fetch(`/api/bot/get-roles/${guildId}`)
.then(res => res.json())
.then(roles => {
const selectAutorole = document.getElementById("autorole-role");
const selectAutoroleVocal = document.getElementById("autorole-vocal-role");
roles.forEach(role => {
const option = document.createElement("option");
option.value = role.id;
option.textContent = role.name;
selectAutorole.appendChild(option);
selectAutoroleVocal.appendChild(option.cloneNode(true));
});
});
const welcomeForm = document.getElementById("welcome-form");
welcomeForm.addEventListener("submit", async (e) => {
e.preventDefault();
const enabled = document.getElementById("welcome-enabled").checked;
const channelId = document.getElementById("welcome-channel").value;
const message = document.getElementById("welcome-message").value;
const res = await fetch("/api/bot/save-welcome-config", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
guildId,
channelId,
welcomeMessage: message,
welcomeEnabled: enabled,
}),
});
const data = await res.json();
document.getElementById("status-welcome-form").textContent = data.success
? "Config de bienvenue sauvegardée ✅"
: "Erreur ❌";
});
const goodbyeForm = document.getElementById("goodbye-form");
goodbyeForm.addEventListener("submit", async (e) => {
e.preventDefault();
const enabled = document.getElementById("goodbye-enabled").checked;
const channelId = document.getElementById("goodbye-channel").value;
const message = document.getElementById("goodbye-message").value;
const res = await fetch("/api/bot/save-goodbye-config", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
guildId,
channelId,
goodbyeMessage: message,
goodbyeEnabled: enabled,
}),
});
const data = await res.json();
document.getElementById("status-goodbye-form").textContent = data.success
? "Config d'au revoir sauvegardée ✅"
: "Erreur ❌";
});
const autoroleNewUserForm = document.getElementById("autorole-newuser-form");
autoroleNewUserForm.addEventListener("submit", async (e) => {
e.preventDefault();
const enabled = document.getElementById("autorole-enabled").checked;
const roleId = document.getElementById("autorole-role").value;
const res = await fetch("/api/bot/save-autorole-newuser-config", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
guildId,
roleId,
enabled,
}),
});
const data = await res.json();
document.getElementById("status-autorole-form").textContent = data.success
? "Config d'auto-rôle pour nouveaux membres sauvegardée ✅"
: "Erreur ❌";
});
const autoroleVocalForm = document.getElementById("autorole-vocal-form");
autoroleVocalForm.addEventListener("submit", async (e) => {
e.preventDefault();
const enabled = document.getElementById("autorole-vocal-enabled").checked;
const roleId = document.getElementById("autorole-vocal-role").value;
const excludeChannelSelect = document.getElementById("autorole-vocal-exclude-channel");
const excludeChannelId = Array.from(excludeChannelSelect.selectedOptions).map(option => option.value);
const res = await fetch("/api/bot/save-autorole-vocal-config", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
guildId,
roleId,
excludeChannelId,
enabled,
}),
});
const data = await res.json();
document.getElementById("status-autorole-vocal-form").textContent = data.success
? "Config d'auto-rôle pour membres en vocal sauvegardée ✅"
: "Erreur ❌";
});
fetch(`/api/bot/get-welcome-config/${guildId}`)
.then(res => res.json())
.then(cfg => {
document.getElementById("welcome-enabled").checked = cfg.enabled;
document.getElementById("welcome-channel").value = cfg.channelId;
document.getElementById("welcome-message").value = cfg.message;
});
fetch(`/api/bot/get-goodbye-config/${guildId}`)
.then(res => res.json())
.then(cfg => {
document.getElementById("goodbye-enabled").checked = cfg.enabled;
document.getElementById("goodbye-channel").value = cfg.channelId;
document.getElementById("goodbye-message").value = cfg.message;
});
fetch(`/api/bot/get-autorole-newuser-config/${guildId}`)
.then(res => res.json())
.then(cfg => {
document.getElementById("autorole-enabled").checked = cfg.enabled;
document.getElementById("autorole-role").value = cfg.roleId;
});
</script>
</body>
</html>