add a major part of user level

This commit is contained in:
Arthur Puechberty
2026-01-16 23:41:39 +01:00
parent 20f7e080a8
commit 08b444efdd
10 changed files with 810 additions and 207 deletions
+29
View File
@@ -0,0 +1,29 @@
const autoroleNewUserForm = document.getElementById("autorole-newuser-form");
const autoroleEnabled = document.getElementById("autorole-enabled");
const autoroleRole = document.getElementById("autorole-role");
const statusAutoroleForm = document.getElementById("status-autorole-form");
fetch(`/api/bot/get-autorole-newuser-config/${guildId}`)
.then(res => res.json())
.then(cfg => {
autoroleEnabled.checked = cfg.enabled;
autoroleRole.value = cfg.roleId;
});
autoroleNewUserForm.addEventListener("submit", async e => {
e.preventDefault();
const res = await fetch("/api/bot/save-autorole-newuser-config", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
guildId,
enabled: autoroleEnabled.checked,
roleId: autoroleRole.value
})
});
statusAutoroleForm.textContent = (await res.json()).success
? "Auto-rôle sauvegardé ✅"
: "Erreur ❌";
});
+43
View File
@@ -0,0 +1,43 @@
const autoroleVocalForm = document.getElementById("autorole-vocal-form");
const autoroleVocalEnabled = document.getElementById("autorole-vocal-enabled");
const autoroleVocalRole = document.getElementById("autorole-vocal-role");
const excludeSelect = document.getElementById("autorole-vocal-exclude-channel");
const statusAutoroleVocalForm = document.getElementById("status-autorole-vocal-form");
fetch(`/api/bot/get-voice-channels/${guildId}`)
.then(res => res.json())
.then(channels => {
channels.forEach(c => {
excludeSelect.appendChild(new Option(`#${c.name}`, c.id));
});
return fetch(`/api/bot/get-autorole-vocal-config/${guildId}`);
})
.then(res => res.json())
.then(cfg => {
autoroleVocalEnabled.checked = cfg.enabled;
autoroleVocalRole.value = cfg.roleId;
Array.from(excludeSelect.options).forEach(opt => {
opt.selected = cfg.excludeChannelIds?.includes(opt.value);
});
});
autoroleVocalForm.addEventListener("submit", async e => {
e.preventDefault();
const exclude = Array.from(excludeSelect.selectedOptions).map(o => o.value);
const res = await fetch("/api/bot/save-autorole-vocal-config", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
guildId,
enabled: autoroleVocalEnabled.checked,
roleId: autoroleVocalRole.value,
excludeChannelId: exclude
})
});
statusAutoroleVocalForm.textContent = (await res.json()).success
? "Auto-rôle vocal sauvegardé ✅"
: "Erreur ❌";
});
+32
View File
@@ -0,0 +1,32 @@
const goodbyeForm = document.getElementById("goodbye-form");
const goodbyeEnabled = document.getElementById("goodbye-enabled");
const goodbyeChannel = document.getElementById("goodbye-channel");
const goodbyeMessage = document.getElementById("goodbye-message");
const statusGoodbyeForm = document.getElementById("status-goodbye-form");
fetch(`/api/bot/get-goodbye-config/${guildId}`)
.then(res => res.json())
.then(cfg => {
goodbyeEnabled.checked = cfg.enabled;
goodbyeChannel.value = cfg.channelId;
goodbyeMessage.value = cfg.message;
});
goodbyeForm.addEventListener("submit", async e => {
e.preventDefault();
const res = await fetch("/api/bot/save-goodbye-config", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
guildId,
goodbyeEnabled: goodbyeEnabled.checked,
channelId: goodbyeChannel.value,
goodbyeMessage: goodbyeMessage.value
})
});
statusGoodbyeForm.textContent = (await res.json()).success
? "Config au revoir sauvegardée ✅"
: "Erreur ❌";
});
+40
View File
@@ -0,0 +1,40 @@
window.guildId = window.location.pathname.split("/")[2];
// Nom du serveur
fetch("/api/guilds")
.then(res => res.json())
.then(guilds => {
const guild = guilds.find(g => g.id === guildId);
document.getElementById("guild-name").textContent =
guild ? `Dashboard : ${guild.name}` : "Serveur introuvable";
});
// Channels texte
fetch(`/api/bot/get-text-channels/${guildId}`)
.then(res => res.json())
.then(channels => {
const welcome = document.getElementById("welcome-channel");
const goodbye = document.getElementById("goodbye-channel");
const levelAnnouncements = document.getElementById("level-announcements-channel");
channels.forEach(c => {
const opt = new Option(`#${c.name}`, c.id);
welcome?.appendChild(opt);
goodbye?.appendChild(opt.cloneNode(true));
levelAnnouncements?.appendChild(opt.cloneNode(true));
});
});
// Rôles
fetch(`/api/bot/get-roles/${guildId}`)
.then(res => res.json())
.then(roles => {
const newUser = document.getElementById("autorole-role");
const vocal = document.getElementById("autorole-vocal-role");
roles.forEach(r => {
const opt = new Option(r.name, r.id);
newUser?.appendChild(opt);
vocal?.appendChild(opt.cloneNode(true));
});
});
+119
View File
@@ -0,0 +1,119 @@
const levelForm = document.getElementById("level-form");
const levelEnabled = document.getElementById("level-enabled");
const levelAnnouncementsEnabled = document.getElementById("level-announcement-enabled");
const levelAnnouncementsChannel = document.getElementById("level-announcements-channel");
const levelAnnouncementsMessage = document.getElementById("level-announcements-message");
const xpCourbeType = document.getElementById("level-xp-curve-type");
const multiplierCourbeForLevel = document.getElementById("level-xp-multiplier");
const levelAnnouncementEveryLevel = document.getElementById("level-announcement-every");
const levelMax = document.getElementById("level-max-level");
const roleWithWithoutType = document.getElementById("level-role-with-or-without-xp-type");
const roleWithWithoutXp = document.getElementById("level-role-with-or-without-xp");
const salonWithWithoutType = document.getElementById("level-channel-with-or-without-xp-type");
const salonWithWithoutXp = document.getElementById("level-channel-with-or-without-xp");
const gainXpOnMessage = document.getElementById("message-xp-enabled");
const gainXpMessageLowerBound = document.getElementById("level-xp-per-message-min");
const gainXpMessageUpperBound = document.getElementById("level-xp-per-message-max");
const cooldownXpMessageSeconds = document.getElementById("level-xp-cooldown");
const gainXpOnVoice = document.getElementById("voice-xp-enabled");
const gainVoiceXpLowerBound = document.getElementById("level-xp-per-voice-min");
const gainVoiceXpUpperBound = document.getElementById("level-xp-per-voice-max");
const statusLevelForm = document.getElementById("status-level-form");
// 1️⃣ RÔLES
fetch(`/api/bot/get-roles/${guildId}`)
.then(res => res.json())
.then(roles => {
roles.forEach(r => {
roleWithWithoutXp?.appendChild(new Option(r.name, r.id));
});
// 2️⃣ SALONS TEXTE
return fetch(`/api/bot/get-text-channels/${guildId}`);
})
.then(res => res.json())
.then(textSalons => {
textSalons.forEach(c => {
salonWithWithoutXp?.appendChild(new Option(`#${c.name}`, c.id));
});
// 3️⃣ SALONS VOCAUX
return fetch(`/api/bot/get-voice-channels/${guildId}`);
})
.then(res => res.json())
.then(voiceSalons => {
voiceSalons.forEach(c => {
salonWithWithoutXp?.appendChild(new Option(`🔊 ${c.name}`, c.id));
});
// 4️⃣ CONFIG (APRÈS QUE TOUT EST CHARGÉ)
return fetch(`/api/bot/get-level-config/${guildId}`);
})
.then(res => res.json())
.then(cfg => {
levelEnabled.checked = cfg.enabled;
levelAnnouncementsEnabled.checked = cfg.levelAnnouncementsEnabled;
levelAnnouncementsChannel.value = cfg.levelAnnouncementsChannelId;
levelAnnouncementsMessage.value = cfg.levelAnnouncementsMessage;
xpCourbeType.value = cfg.xpCourbeType;
multiplierCourbeForLevel.value = cfg.multiplierCourbeForLevel;
levelAnnouncementEveryLevel.value = cfg.levelAnnouncementEveryLevel;
levelMax.value = cfg.levelMax;
roleWithWithoutType.value = cfg.roleWithWithoutType;
Array.from(roleWithWithoutXp.options).forEach(opt => {
opt.selected = cfg.roleWithWithoutXp?.includes(opt.value);
});
salonWithWithoutType.value = cfg.salonWithWithoutType;
Array.from(salonWithWithoutXp.options).forEach(opt => {
opt.selected = cfg.salonWithWithoutXp?.includes(opt.value);
});
gainXpOnMessage.checked = cfg.gainXpOnMessage;
gainXpMessageLowerBound.value = cfg.gainXpMessageLowerBound;
gainXpMessageUpperBound.value = cfg.gainXpMessageUpperBound;
cooldownXpMessageSeconds.value = cfg.cooldownXpMessageSeconds;
gainXpOnVoice.checked = cfg.gainXpOnVoice;
gainVoiceXpLowerBound.value = cfg.gainVoiceXpLowerBound;
gainVoiceXpUpperBound.value = cfg.gainVoiceXpUpperBound;
})
.catch(console.error);
levelForm.addEventListener("submit", async e => {
e.preventDefault();
const res = await fetch("/api/bot/save-level-config", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
guildId,
levelEnabled: levelEnabled.checked,
levelAnnouncementsEnabled: levelAnnouncementsEnabled.checked,
levelAnnouncementsChannelId: levelAnnouncementsChannel.value,
levelAnnouncementsMessage: levelAnnouncementsMessage.value,
xpCourbeType: xpCourbeType.value,
multiplierCourbeForLevel: parseInt(multiplierCourbeForLevel.value, 10),
levelAnnouncementEveryLevel: parseInt(levelAnnouncementEveryLevel.value, 10),
levelMax: parseInt(levelMax.value, 10),
roleWithWithoutType: roleWithWithoutType.value,
roleWithWithoutXp: Array.from(roleWithWithoutXp.selectedOptions).map(opt => opt.value),
salonWithWithoutType: salonWithWithoutType.value,
salonWithWithoutXp: Array.from(salonWithWithoutXp.selectedOptions).map(opt => opt.value),
gainXpOnMessage: gainXpOnMessage.checked,
gainXpMessageLowerBound: parseInt(gainXpMessageLowerBound.value, 10),
gainXpMessageUpperBound: parseInt(gainXpMessageUpperBound.value, 10),
cooldownXpMessageSeconds: parseInt(cooldownXpMessageSeconds.value, 10),
gainXpOnVoice: gainXpOnVoice.checked,
gainVoiceXpLowerBound: parseInt(gainVoiceXpLowerBound.value, 10),
gainVoiceXpUpperBound: parseInt(gainVoiceXpUpperBound.value, 10)
})
});
statusLevelForm.textContent = (await res.json()).success
? "Config niveaux sauvegardée ✅"
: "Erreur ❌";
});
+32
View File
@@ -0,0 +1,32 @@
const welcomeForm = document.getElementById("welcome-form");
const welcomeEnabled = document.getElementById("welcome-enabled");
const welcomeChannel = document.getElementById("welcome-channel");
const welcomeMessage = document.getElementById("welcome-message");
const statusWelcomeForm = document.getElementById("status-welcome-form");
fetch(`/api/bot/get-welcome-config/${guildId}`)
.then(res => res.json())
.then(cfg => {
welcomeEnabled.checked = cfg.enabled;
welcomeChannel.value = cfg.channelId;
welcomeMessage.value = cfg.message;
});
welcomeForm.addEventListener("submit", async e => {
e.preventDefault();
const res = await fetch("/api/bot/save-welcome-config", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
guildId,
welcomeEnabled: welcomeEnabled.checked,
channelId: welcomeChannel.value,
welcomeMessage: welcomeMessage.value
})
});
statusWelcomeForm.textContent = (await res.json()).success
? "Config bienvenue sauvegardée ✅"
: "Erreur ❌";
});