mirror of
https://github.com/arthur-pbty/LazyBot.git
synced 2026-06-03 15:07:29 +02:00
add system of temporary vocal
This commit is contained in:
@@ -161,6 +161,21 @@ db.exec(`
|
|||||||
purchased_at INTEGER NOT NULL,
|
purchased_at INTEGER NOT NULL,
|
||||||
FOREIGN KEY (item_id) REFERENCES shop_items(id)
|
FOREIGN KEY (item_id) REFERENCES shop_items(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS privateroom_config (
|
||||||
|
guild_id TEXT PRIMARY KEY,
|
||||||
|
enabled INTEGER NOT NULL DEFAULT 0,
|
||||||
|
creator_channel_id TEXT,
|
||||||
|
category_id TEXT,
|
||||||
|
channel_name_format TEXT NOT NULL DEFAULT '🔊 Salon de {user}'
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS temp_voice_channels (
|
||||||
|
channel_id TEXT PRIMARY KEY,
|
||||||
|
guild_id TEXT NOT NULL,
|
||||||
|
owner_id TEXT NOT NULL,
|
||||||
|
created_at INTEGER NOT NULL
|
||||||
|
);
|
||||||
`);
|
`);
|
||||||
|
|
||||||
module.exports = db;
|
module.exports = db;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const { Events } = require("discord.js");
|
const { Events, ChannelType, PermissionFlagsBits } = require("discord.js");
|
||||||
const db = require("../db");
|
const db = require("../db");
|
||||||
|
|
||||||
// Store voice join times and intervals for economy
|
// Store voice join times and intervals for economy
|
||||||
@@ -8,6 +8,9 @@ const voiceMoneyIntervals = new Map(); // guildId_userId -> intervalId
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
name: Events.VoiceStateUpdate,
|
name: Events.VoiceStateUpdate,
|
||||||
async execute(client, oldState, newState) {
|
async execute(client, oldState, newState) {
|
||||||
|
// ===== PRIVATE ROOM (TEMP VOICE CHANNELS) =====
|
||||||
|
await handlePrivateRoom(client, oldState, newState);
|
||||||
|
|
||||||
if (newState.member.user.bot) return;
|
if (newState.member.user.bot) return;
|
||||||
|
|
||||||
const guildId = newState.guild.id;
|
const guildId = newState.guild.id;
|
||||||
@@ -114,3 +117,108 @@ module.exports = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ===== PRIVATE ROOM HANDLER =====
|
||||||
|
async function handlePrivateRoom(client, oldState, newState) {
|
||||||
|
const guildId = newState.guild.id;
|
||||||
|
const member = newState.member;
|
||||||
|
|
||||||
|
// Récupérer la configuration
|
||||||
|
const config = await db.getAsync(
|
||||||
|
"SELECT enabled, creator_channel_id, category_id, channel_name_format FROM privateroom_config WHERE guild_id = ?",
|
||||||
|
[guildId]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!config || !config.enabled) {
|
||||||
|
// Même si désactivé, vérifier si un salon temp doit être supprimé
|
||||||
|
await checkAndDeleteEmptyTempChannel(oldState);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Utilisateur rejoint le salon créateur
|
||||||
|
if (newState.channelId === config.creator_channel_id) {
|
||||||
|
try {
|
||||||
|
// Formater le nom du salon
|
||||||
|
let channelName = config.channel_name_format || '🔊 Salon de {user}';
|
||||||
|
channelName = channelName
|
||||||
|
.replace(/{user}/g, member.user.username)
|
||||||
|
.replace(/{displayname}/g, member.displayName);
|
||||||
|
|
||||||
|
// Créer le salon vocal
|
||||||
|
const newChannel = await newState.guild.channels.create({
|
||||||
|
name: channelName,
|
||||||
|
type: ChannelType.GuildVoice,
|
||||||
|
parent: config.category_id || null,
|
||||||
|
permissionOverwrites: [
|
||||||
|
{
|
||||||
|
id: member.id,
|
||||||
|
allow: [
|
||||||
|
PermissionFlagsBits.ManageChannels,
|
||||||
|
PermissionFlagsBits.MuteMembers,
|
||||||
|
PermissionFlagsBits.DeafenMembers,
|
||||||
|
PermissionFlagsBits.MoveMembers,
|
||||||
|
PermissionFlagsBits.Connect,
|
||||||
|
PermissionFlagsBits.Speak
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
// Enregistrer le salon dans la base de données
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
db.run(
|
||||||
|
"INSERT INTO temp_voice_channels (channel_id, guild_id, owner_id, created_at) VALUES (?, ?, ?, ?)",
|
||||||
|
[newChannel.id, guildId, member.id, Date.now()],
|
||||||
|
(err) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Déplacer l'utilisateur dans le nouveau salon
|
||||||
|
await member.voice.setChannel(newChannel);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Erreur création salon temporaire:", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier si l'ancien salon était un salon temporaire vide
|
||||||
|
await checkAndDeleteEmptyTempChannel(oldState);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkAndDeleteEmptyTempChannel(oldState) {
|
||||||
|
if (!oldState.channelId) return;
|
||||||
|
|
||||||
|
const oldChannel = oldState.guild.channels.cache.get(oldState.channelId);
|
||||||
|
if (!oldChannel) return;
|
||||||
|
|
||||||
|
// Vérifier si c'est un salon temporaire
|
||||||
|
const tempChannel = await db.getAsync(
|
||||||
|
"SELECT channel_id FROM temp_voice_channels WHERE channel_id = ?",
|
||||||
|
[oldState.channelId]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!tempChannel) return;
|
||||||
|
|
||||||
|
// Vérifier si le salon est vide
|
||||||
|
if (oldChannel.members.size === 0) {
|
||||||
|
try {
|
||||||
|
// Supprimer le salon
|
||||||
|
await oldChannel.delete("Salon temporaire vide");
|
||||||
|
|
||||||
|
// Supprimer de la base de données
|
||||||
|
db.run(
|
||||||
|
"DELETE FROM temp_voice_channels WHERE channel_id = ?",
|
||||||
|
[oldState.channelId]
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Erreur suppression salon temporaire:", err);
|
||||||
|
// Si le salon n'existe plus, le supprimer quand même de la DB
|
||||||
|
db.run(
|
||||||
|
"DELETE FROM temp_voice_channels WHERE channel_id = ?",
|
||||||
|
[oldState.channelId]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -516,6 +516,24 @@ body {
|
|||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ===== Info Box ===== */
|
||||||
|
.info-box {
|
||||||
|
background: linear-gradient(135deg, rgba(88, 101, 242, 0.1), rgba(88, 101, 242, 0.05));
|
||||||
|
border: 1px solid rgba(88, 101, 242, 0.3);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
padding: var(--spacing-md);
|
||||||
|
margin-bottom: var(--spacing-lg);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: 0.9rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-box strong {
|
||||||
|
color: var(--primary);
|
||||||
|
display: block;
|
||||||
|
margin-bottom: var(--spacing-xs);
|
||||||
|
}
|
||||||
|
|
||||||
/* ===== Mobile Sidebar Toggle ===== */
|
/* ===== Mobile Sidebar Toggle ===== */
|
||||||
.mobile-toggle {
|
.mobile-toggle {
|
||||||
display: none;
|
display: none;
|
||||||
|
|||||||
@@ -50,6 +50,10 @@
|
|||||||
<span class="nav-item-icon">💰</span>
|
<span class="nav-item-icon">💰</span>
|
||||||
Économie
|
Économie
|
||||||
</a>
|
</a>
|
||||||
|
<a class="nav-item" data-section="privateroom">
|
||||||
|
<span class="nav-item-icon">🔊</span>
|
||||||
|
Salons temporaires
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
@@ -599,6 +603,58 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- Section: Salons vocaux temporaires -->
|
||||||
|
<section class="config-section" id="section-privateroom">
|
||||||
|
<div class="config-card">
|
||||||
|
<div class="config-card-header">
|
||||||
|
<div class="config-card-title">
|
||||||
|
<span class="icon">🔊</span>
|
||||||
|
<h3>Salons vocaux temporaires</h3>
|
||||||
|
</div>
|
||||||
|
<label class="toggle-switch">
|
||||||
|
<input type="checkbox" id="privateroom-enabled">
|
||||||
|
<span class="toggle-slider"></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="config-card-body">
|
||||||
|
<div class="info-box">
|
||||||
|
<strong>💡 Comment ça marche ?</strong><br>
|
||||||
|
Quand un membre rejoint le salon "créateur", un nouveau salon vocal est automatiquement créé pour lui.
|
||||||
|
Le salon est supprimé quand il devient vide.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="form-label">Salon créateur</label>
|
||||||
|
<span class="form-sublabel">Le salon vocal que les membres rejoignent pour créer leur salon</span>
|
||||||
|
<select class="form-select" id="privateroom-creator-channel"></select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="form-label">Catégorie des salons créés</label>
|
||||||
|
<span class="form-sublabel">Les salons temporaires seront créés dans cette catégorie</span>
|
||||||
|
<select class="form-select" id="privateroom-category"></select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="form-label">Format du nom du salon</label>
|
||||||
|
<input type="text" class="form-input" id="privateroom-name-format" value="🔊 Salon de {user}" placeholder="🔊 Salon de {user}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="variables-box">
|
||||||
|
<div class="variables-box-title">Variables disponibles</div>
|
||||||
|
<div class="variables-list">
|
||||||
|
<span class="variable-tag"><code>{user}</code> <span>→ nom d'utilisateur</span></span>
|
||||||
|
<span class="variable-tag"><code>{displayname}</code> <span>→ pseudo serveur</span></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="config-card-footer">
|
||||||
|
<div id="status-privateroom-form" class="status-message"></div>
|
||||||
|
<button type="button" class="btn btn-primary" id="save-privateroom">Sauvegarder</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
@@ -613,5 +669,6 @@
|
|||||||
<script src="/guild/autoroleVocalForm.js"></script>
|
<script src="/guild/autoroleVocalForm.js"></script>
|
||||||
<script src="/guild/levelForm.js"></script>
|
<script src="/guild/levelForm.js"></script>
|
||||||
<script src="/guild/economyForm.js"></script>
|
<script src="/guild/economyForm.js"></script>
|
||||||
|
<script src="/guild/privateroomForm.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
// ===== PRIVATE ROOM FORM =====
|
||||||
|
(async function () {
|
||||||
|
const enabledCheckbox = document.getElementById("privateroom-enabled");
|
||||||
|
const creatorChannelSelect = document.getElementById("privateroom-creator-channel");
|
||||||
|
const categorySelect = document.getElementById("privateroom-category");
|
||||||
|
const nameFormatInput = document.getElementById("privateroom-name-format");
|
||||||
|
const saveBtn = document.getElementById("save-privateroom");
|
||||||
|
const statusDiv = document.getElementById("status-privateroom-form");
|
||||||
|
|
||||||
|
// Charger les salons vocaux
|
||||||
|
async function loadVoiceChannels() {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/bot/get-voice-channels/${guildId}`);
|
||||||
|
const channels = await res.json();
|
||||||
|
creatorChannelSelect.innerHTML = '<option value="">-- Sélectionner un salon --</option>';
|
||||||
|
channels.forEach(ch => {
|
||||||
|
const opt = document.createElement("option");
|
||||||
|
opt.value = ch.id;
|
||||||
|
opt.textContent = ch.name;
|
||||||
|
creatorChannelSelect.appendChild(opt);
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Erreur chargement salons vocaux:", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Charger les catégories
|
||||||
|
async function loadCategories() {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/bot/get-categories/${guildId}`);
|
||||||
|
const categories = await res.json();
|
||||||
|
categorySelect.innerHTML = '<option value="">-- Sélectionner une catégorie --</option>';
|
||||||
|
categories.forEach(cat => {
|
||||||
|
const opt = document.createElement("option");
|
||||||
|
opt.value = cat.id;
|
||||||
|
opt.textContent = cat.name;
|
||||||
|
categorySelect.appendChild(opt);
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Erreur chargement catégories:", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Charger la configuration
|
||||||
|
async function loadConfig() {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/bot/get-privateroom-config/${guildId}`);
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
enabledCheckbox.checked = data.enabled;
|
||||||
|
nameFormatInput.value = data.channelNameFormat || '🔊 Salon de {user}';
|
||||||
|
|
||||||
|
// Attendre que les selects soient remplis
|
||||||
|
await Promise.all([loadVoiceChannels(), loadCategories()]);
|
||||||
|
|
||||||
|
if (data.creatorChannelId) {
|
||||||
|
creatorChannelSelect.value = data.creatorChannelId;
|
||||||
|
}
|
||||||
|
if (data.categoryId) {
|
||||||
|
categorySelect.value = data.categoryId;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Erreur chargement config privateroom:", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sauvegarder
|
||||||
|
saveBtn.addEventListener("click", async () => {
|
||||||
|
saveBtn.disabled = true;
|
||||||
|
saveBtn.textContent = "Sauvegarde...";
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
guildId,
|
||||||
|
enabled: enabledCheckbox.checked,
|
||||||
|
creatorChannelId: creatorChannelSelect.value || null,
|
||||||
|
categoryId: categorySelect.value || null,
|
||||||
|
channelNameFormat: nameFormatInput.value || '🔊 Salon de {user}'
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/bot/save-privateroom-config", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
});
|
||||||
|
const result = await res.json();
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
showStatus("status-privateroom-form", "Configuration sauvegardée ✅", "success");
|
||||||
|
} else {
|
||||||
|
showStatus("status-privateroom-form", "Erreur lors de la sauvegarde ❌", "error");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Erreur sauvegarde:", err);
|
||||||
|
showStatus("status-privateroom-form", "Erreur de connexion ❌", "error");
|
||||||
|
}
|
||||||
|
|
||||||
|
saveBtn.disabled = false;
|
||||||
|
saveBtn.textContent = "Sauvegarder";
|
||||||
|
});
|
||||||
|
|
||||||
|
// Init
|
||||||
|
loadConfig();
|
||||||
|
})();
|
||||||
@@ -72,6 +72,11 @@
|
|||||||
<h3>Rôles Automatiques</h3>
|
<h3>Rôles Automatiques</h3>
|
||||||
<p>Attribuez automatiquement des rôles aux nouveaux membres ou aux utilisateurs en vocal. Configurez les salons à exclure.</p>
|
<p>Attribuez automatiquement des rôles aux nouveaux membres ou aux utilisateurs en vocal. Configurez les salons à exclure.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="feature-card">
|
||||||
|
<div class="feature-icon">🔊</div>
|
||||||
|
<h3>Salons Temporaires</h3>
|
||||||
|
<p>Créez des salons vocaux privés à la demande. Quand un membre rejoint le salon créateur, un salon personnel est créé automatiquement.</p>
|
||||||
|
</div>
|
||||||
<div class="feature-card">
|
<div class="feature-card">
|
||||||
<div class="feature-icon">⚙️</div>
|
<div class="feature-icon">⚙️</div>
|
||||||
<h3>Dashboard Intuitif</h3>
|
<h3>Dashboard Intuitif</h3>
|
||||||
|
|||||||
@@ -748,5 +748,86 @@ module.exports = (app, db, client) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ===== PRIVATE ROOM CONFIG =====
|
||||||
|
router.post("/bot/save-privateroom-config", express.json(), (req, res) => {
|
||||||
|
const { guildId, enabled, creatorChannelId, categoryId, channelNameFormat } = req.body;
|
||||||
|
|
||||||
|
if (!req.session.guilds) {
|
||||||
|
return res.status(401).json({ success: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
const isAdmin = req.session.guilds.find(
|
||||||
|
g => g.id === guildId && (BigInt(g.permissions) & 0x8n) === 0x8n
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isAdmin) {
|
||||||
|
return res.status(403).json({ success: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
db.run(
|
||||||
|
`INSERT INTO privateroom_config (guild_id, enabled, creator_channel_id, category_id, channel_name_format)
|
||||||
|
VALUES (?, ?, ?, ?, ?)
|
||||||
|
ON CONFLICT(guild_id) DO UPDATE SET
|
||||||
|
enabled = ?, creator_channel_id = ?, category_id = ?, channel_name_format = ?`,
|
||||||
|
[
|
||||||
|
guildId,
|
||||||
|
enabled ? 1 : 0,
|
||||||
|
creatorChannelId,
|
||||||
|
categoryId,
|
||||||
|
channelNameFormat || '🔊 Salon de {user}',
|
||||||
|
enabled ? 1 : 0,
|
||||||
|
creatorChannelId,
|
||||||
|
categoryId,
|
||||||
|
channelNameFormat || '🔊 Salon de {user}'
|
||||||
|
],
|
||||||
|
err => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json({ success: false });
|
||||||
|
}
|
||||||
|
res.json({ success: true });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get("/bot/get-privateroom-config/:guildId", (req, res) => {
|
||||||
|
const { guildId } = req.params;
|
||||||
|
|
||||||
|
db.get(
|
||||||
|
"SELECT enabled, creator_channel_id, category_id, channel_name_format FROM privateroom_config WHERE guild_id = ?",
|
||||||
|
[guildId],
|
||||||
|
(err, row) => {
|
||||||
|
if (err || !row) {
|
||||||
|
return res.json({
|
||||||
|
enabled: false,
|
||||||
|
creatorChannelId: null,
|
||||||
|
categoryId: null,
|
||||||
|
channelNameFormat: '🔊 Salon de {user}'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.json({
|
||||||
|
enabled: !!row.enabled,
|
||||||
|
creatorChannelId: row.creator_channel_id,
|
||||||
|
categoryId: row.category_id,
|
||||||
|
channelNameFormat: row.channel_name_format || '🔊 Salon de {user}'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get("/bot/get-categories/:guildId", (req, res) => {
|
||||||
|
const { guildId } = req.params;
|
||||||
|
const guild = client.guilds.cache.get(guildId);
|
||||||
|
if (!guild) {
|
||||||
|
return res.status(404).json({ error: "Serveur non trouvé" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const categories = guild.channels.cache
|
||||||
|
.filter(c => c.type === 4) // 4 = GuildCategory
|
||||||
|
.map(c => ({ id: c.id, name: c.name }));
|
||||||
|
|
||||||
|
res.json(categories);
|
||||||
|
});
|
||||||
|
|
||||||
app.use("/api", router);
|
app.use("/api", router);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user