diff --git a/app/bot.js b/app/bot.js index 5596ce7..7791ce6 100644 --- a/app/bot.js +++ b/app/bot.js @@ -42,6 +42,18 @@ client.on(Events.GuildMemberAdd, member => { } } ); + db.get( + "SELECT enabled, role_id FROM autorole_newuser_config WHERE guild_id = ?", + [member.guild.id], + (err, row) => { + if (err || !row || !row.enabled) return; + + const role = member.guild.roles.cache.get(row.role_id); + if (role) { + member.roles.add(role); + } + } + ); }); @@ -67,6 +79,42 @@ client.on(Events.GuildMemberRemove, member => { }); +client.on(Events.VoiceStateUpdate, (oldState, newState) => { + if (newState.member.user.bot) return; + + const guildId = newState.guild.id; + + db.get( + "SELECT enabled, role_id, exclude_channel_ids FROM autorole_vocal_config WHERE guild_id = ?", + [guildId], + (err, row) => { + if (err || !row || !row.enabled) return; + + let excludeChannelIds = []; + try { + excludeChannelIds = row.exclude_channel_ids + ? JSON.parse(row.exclude_channel_ids) + : []; + } catch (err) { + console.error("Erreur parsing exclude_channel_ids", err); + excludeChannelIds = []; + } + + const role = newState.guild.roles.cache.get(row.role_id); + if (!role) return; + + // User joins a voice channel and it's not excluded et a pas déjà le rôle + if (newState.channelId && !excludeChannelIds.includes(newState.channelId) && !newState.member.roles.cache.has(role.id)) { + newState.member.roles.add(role); + } + // User leaves a voice channel or joins an excluded one + else if (!newState.channelId || excludeChannelIds.includes(newState.channelId)) { + newState.member.roles.remove(role); + } + } + ); +}); + client.login(process.env.BOT_TOKEN); module.exports = client; diff --git a/app/db.js b/app/db.js index 9ba6d5e..f3323e4 100644 --- a/app/db.js +++ b/app/db.js @@ -24,6 +24,19 @@ db.exec(` enabled INTEGER NOT NULL, message TEXT NOT NULL ); + + CREATE TABLE IF NOT EXISTS autorole_newuser_config ( + guild_id TEXT PRIMARY KEY, + role_id TEXT, + enabled INTEGER NOT NULL + ); + + CREATE TABLE IF NOT EXISTS autorole_vocal_config ( + guild_id TEXT PRIMARY KEY, + role_id TEXT, + exclude_channel_ids TEXT, + enabled INTEGER NOT NULL + ); `); module.exports = db; diff --git a/app/public/guild.css b/app/public/guild.css index 5598f6f..f5f356b 100644 --- a/app/public/guild.css +++ b/app/public/guild.css @@ -139,4 +139,61 @@ small code { form { padding: 15px; } -} \ No newline at end of file +} + +#autorole-vocal-exclude-channel { + background-color: #0f1115; + color: #e5e7eb; + + border: 1px solid #2a2f3a; + border-radius: 8px; + + padding: 8px; + font-size: 14px; + + min-width: 240px; + + outline: none; +} + +/* options */ +#autorole-vocal-exclude-channel option { + background-color: #0f1115; + color: #e5e7eb; + padding: 6px; +} + +/* hover */ +#autorole-vocal-exclude-channel option:hover { + background-color: #1f2937; +} + +/* sélection */ +#autorole-vocal-exclude-channel option:checked { + background-color: #2563eb; /* bleu */ + color: #ffffff; +} + +/* focus */ +#autorole-vocal-exclude-channel:focus { + border-color: #2563eb; + box-shadow: 0 0 0 1px #2563eb; +} + +/* scrollbar (Chrome / Edge) */ +#autorole-vocal-exclude-channel::-webkit-scrollbar { + width: 8px; +} + +#autorole-vocal-exclude-channel::-webkit-scrollbar-track { + background: #0f1115; +} + +#autorole-vocal-exclude-channel::-webkit-scrollbar-thumb { + background: #2a2f3a; + border-radius: 4px; +} + +#autorole-vocal-exclude-channel::-webkit-scrollbar-thumb:hover { + background: #3b4252; +} diff --git a/app/public/guild.html b/app/public/guild.html index 20fe235..7e16abe 100644 --- a/app/public/guild.html +++ b/app/public/guild.html @@ -88,6 +88,49 @@
+ + + + + +