Compare commits

..

22 Commits

Author SHA1 Message Date
96cd60912b Version 1.2.0 - Ajout des suggestions et de paramètres
All checks were successful
Deployment Pipeline / deploy (push) Successful in 35s
2025-09-07 18:18:52 +02:00
b2aadc7c3c Version 1.1.4 - Correction de Bug
All checks were successful
Deployment Pipeline / deploy (push) Successful in 36s
2025-09-06 15:47:06 +02:00
dcc056455e Version 1.1.3 - Modfication du Proxy
All checks were successful
Deployment Pipeline / deploy (push) Successful in 36s
2025-08-31 16:57:13 +02:00
f777fb821a Version 1.1.2-rc4 - Modif erreur
All checks were successful
Deployment Pipeline / deploy (push) Successful in 37s
2025-08-29 19:44:38 +02:00
ecbda838d3 Merge branch 'main' of https://git.raphix.fr/subsonics/chopin
All checks were successful
Deployment Pipeline / deploy (push) Successful in 35s
2025-08-29 19:41:32 +02:00
5ac195fd46 Version 1.1.2-rc4 - Ajout de agent Cookie 2025-08-29 19:41:08 +02:00
914edbbf13 Version 1.1.2-rc3 - Modification Cookie
All checks were successful
Deployment Pipeline / deploy (push) Successful in 40s
2025-08-29 15:25:22 +02:00
c376e3259c Version 1.1.2-rc2 - Ajout Cookies
All checks were successful
Deployment Pipeline / deploy (push) Successful in 35s
2025-08-29 12:44:25 +02:00
f3b237b74f Version 1.1.2-rc1 - Modif Ytdl
All checks were successful
Deployment Pipeline / deploy (push) Successful in 34s
2025-08-29 12:29:02 +02:00
83e11f3341 Merge branch 'main' of https://git.raphix.fr/subsonics/chopin
All checks were successful
Deployment Pipeline / deploy (push) Successful in 35s
2025-08-29 12:26:32 +02:00
b132041d16 Version 1.1.2 - Modification User-Agent 2025-08-29 12:26:25 +02:00
33da8e8527 Version 1.1.1 - Edit Cookies
All checks were successful
Deployment Pipeline / deploy (push) Successful in 36s
2025-08-29 12:01:13 +02:00
c613d67c60 Version 1.1.1 - Modification du Changelog
All checks were successful
Deployment Pipeline / deploy (push) Successful in 35s
2025-08-29 00:23:21 +02:00
48e5bfad60 Version 1.1.1.rc8 - Changement permissions
All checks were successful
Deployment Pipeline / deploy (push) Successful in 33s
2025-08-29 00:07:11 +02:00
54fd731ab9 Version 1.1.1-rc7.1 - Modif Pipeline
All checks were successful
Deployment Pipeline / deploy (push) Successful in 35s
2025-08-28 23:58:19 +02:00
5b8f591216 Version 1.1.1-rc7 - Modification des valeurs Path
Some checks failed
Deployment Pipeline / deploy (push) Failing after 35s
2025-08-28 23:55:51 +02:00
2fe5d35efe Version 1.1.1-rc6.1 - Modif Erreur Pipeline
Some checks failed
Deployment Pipeline / deploy (push) Failing after 40s
2025-08-28 23:47:34 +02:00
b0f5ccbe5a Version 1.1.1-rc6 - Modif Pipeline
Some checks failed
Deployment Pipeline / deploy (push) Failing after 9s
2025-08-28 23:46:27 +02:00
98e5c41fa5 Version 1.1.1-rc5 - Modif Pipeline Final
Some checks failed
Deployment Pipeline / deploy (push) Failing after 27s
2025-08-28 23:32:40 +02:00
f41eddf1dc Version 1.1.1-rc4.1 - Modif Pipeline
Some checks failed
Deployment Pipeline / deploy (push) Failing after 8s
2025-08-28 23:29:50 +02:00
f12bbe8ad2 Version 1.1.1-rc4 - Modif Pipeline
Some checks failed
Deployment Pipeline / deploy (push) Failing after 8s
2025-08-28 23:28:12 +02:00
0c50874644 Version 1.1.1-rc3 - Modification Pipeline
Some checks failed
Deployment Pipeline / deploy (push) Failing after 7s
2025-08-28 23:27:30 +02:00
10 changed files with 232 additions and 54 deletions

View File

@@ -20,21 +20,35 @@ jobs:
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan raphix.fr >> ~/.ssh/known_hosts
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
ssh-keyscan git.raphix.fr >> ~/.ssh/known_hosts
- name: Deploy Subsonics
- name: Deploy Subsonics as gitlab-ci
run: |
ssh -o StrictHostKeyChecking=no raphix@raphix.fr << 'EOF'
sudo su - gitlab-ci << 'INNER_EOF'
ssh -A -o StrictHostKeyChecking=no raphix@alpha.raphix.fr << 'EOF'
sudo su - gitlab-ci -c '
set -e
echo "[Subsonics-Deploy] - Stage - Déploiement - START "
# Variables PM2 et npm
export PM2_HOME=/home/gitlab-ci/.pm2
export NPM_CONFIG_CACHE=/home/gitlab-ci/.npm
mkdir -p $PM2_HOME $NPM_CONFIG_CACHE
chown -R gitlab-ci:gitlab-ci $PM2_HOME $NPM_CONFIG_CACHE
echo "[Subsonics-Deploy] - Stage - Déploiement - START"
echo "[Subsonics-Deploy] - Arrêt de Subsonics : Processing"
cd /home/gitlab-ci
whoami
pm2 stop "Subsonics" || true
pm2 delete "Subsonics" || true
pm2 stop "Subsonics - Backend" || true
pm2 delete "Subsonics - Backend" || true
echo "[Subsonics-Deploy] - Arrêt de Subsonics : Success"
# Préparer tempdata
if [ ! -d "/home/gitlab-ci/backend/data" ]; then
mkdir -p /home/gitlab-ci/backend/data
fi
mv /home/gitlab-ci/backend/data/ /home/gitlab-ci/tempdata || true
echo "[Subsonics-Deploy] - Suppression de Subsonics : Processing"
@@ -42,13 +56,23 @@ jobs:
echo "[Subsonics-Deploy] - Suppression de Subsonics : Success"
echo "[Subsonics-Deploy] - Installation de Subsonics : Processing"
git clone https://git.raphix.fr/subsonics/chopin.git
git clone https://git.raphix.fr/subsonics/chopin backend
echo "[Subsonics-Deploy] - Installation de Subsonics : Success"
echo "[Subsonics-Deploy] - Installation des dépendances : Processing"
cd /home/gitlab-ci/backend
rm -r /home/gitlab-ci/backend/data || true
mv /home/gitlab-ci/tempdata/ /home/gitlab-ci/backend/data || true
# Nettoyage node_modules et tempdata
rm -rf node_modules
if [ -d "/home/gitlab-ci/tempdata" ]; then
mv /home/gitlab-ci/tempdata/ ./data
fi
# Assurer la propriété gitlab-ci
chown -R gitlab-ci:gitlab-ci /home/gitlab-ci/backend
mkdir -p $NPM_CONFIG_CACHE
chown -R gitlab-ci:gitlab-ci $NPM_CONFIG_CACHE
npm install --omit=dev
echo "[Subsonics-Deploy] - Installation des dépendances : Success"
@@ -56,6 +80,7 @@ jobs:
cd /home/gitlab-ci
pm2 start subsonic.config.js
echo "[Subsonics-Deploy] - Démarrage de Subsonics : Success"
echo "[Subsonics-Deploy] - Stage - Déploiement - END"
INNER_EOF
'
EOF

View File

@@ -1,13 +1,29 @@
<div class="changelog-version changelog-actual">
<h2>Chopin - Version /*1.0.0*/</h2>
<p class="changelog-date">*_Date de sortie_*: *-XX/XX/XXXX-*</p>
<h2>Chopin - Version /*1.2.0*/</h2>
<p class="changelog-date">*_Date de sortie_*: *-07/09/2025-*</p>
<ul>
<li>[FRONTEND] Sortie de la version 1.0.0 de Chopin, le bot Discord pour SubSonics.</li>
<li>[BACKEND] Ajout de la fonctionnalité de gestion des utilisateurs avec un fichier JSON.</li>
<li>[DISCORD] Ajout de la fonctionnalité de gestion des utilisateurs avec un fichier JSON.</li>
<li>[PLAYER] Ajout de la fonctionnalité de gestion des utilisateurs avec un fichier JSON.</li>
<li>[AUTRE] Ajout de la fonctionnalité de gestion des utilisateurs avec un fichier JSON.</li>
<li>[FIX] Ajout de la fonctionnalité de gestion des utilisateurs avec un fichier JSON.</li>
<li>[AJOUT] Ajout de la fonctionnalité de gestion des utilisateurs avec un fichier JSON.</li>
<li>/#[AJOUT][FRONTEND]#/ Suggestion de recherche, depuis Youtube</li>
<li>/#[FIX][FRONTEND]#/ Optimisation des bouttons, avec une modification du composant</li>
<li>/#[AJOUT][DISCORD]#/ Ajout de la sécurité, permettant de restreindre l'utilisation du Bot au Rôle paramétré</li>
</ul>
</div>
<div class="changelog-version">
<h2>Chopin - Version /*1.1.0*/</h2>
<p class="changelog-date">*_Date de sortie_*: *-06/09/2025-*</p>
<ul>
<li>/#[AJOUT][FRONTEND]#/ Désormais, lorsque l'utilisateur n'est pas connecté, les bouttons de lecture sont désactivés au lieu d'être masqués</li>
<li>/#[AJOUT][FRONTEND] #/ Ajout de la prise en charge de plusieurs fichiers en même temps (Impossibilité sur Discord à cause de restriction) !</li>
<li>/#[FIX][BACKEND]#/ La source Youtube est désormais fonctionnelle</li>
<li>/#[FIX][BACKEND]#/ Le changement de channel est désormais fonctionnel.</li>
<li>/#[FIX][FRONTEND]#/ Résolution d'un problème d'affichage du changelog et de la liste de lecture</li>
<li>/#[FIX][FRONTEND]#/ Le "En ligne" est désormais resynchronisé sur le Bot</li>
</ul>
</div>
<div class="changelog-version">
<h2>Chopin - Version /*1.0.0*/</h2>
<p class="changelog-date">*_Date de sortie_*: *-29/08/2025-*</p>
<ul>
<li>/#[FRONTEND]#/ Sortie de la version 1.0.0 de Chopin, le bot Discord pour SubSonics. Refonte graphique et passage sur Vue JS</li>
<li>/#[BACKEND]#/ Refonte de toute la gestion de la musique et ajout de nouvelles fonctionnalités</li>
</ul>
</div>

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "chopin-backend",
"version": "1.1.1",
"version": "1.1.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "chopin-backend",
"version": "1.1.1",
"version": "1.1.2",
"license": "ISC",
"dependencies": {
"@discordjs/voice": "^0.18.0",

View File

@@ -1,6 +1,6 @@
{
"name": "chopin-backend",
"version": "1.1.1",
"version": "1.2.0",
"description": "Discord Bot for music - Fetching everywhere !",
"main": "src/main.js",
"nodemonConfig": {

View File

@@ -7,6 +7,8 @@ const config = require("../utils/Database/Configuration")
const metric = require("webmetrik")
const { Player } = require("../player/Player")
const {refreshAllUserInformation} = require("../server/auth/User")
const serverSettings = require("./ServerSettings")
const { Embed, EmbedError } = require("./Embed")
const dlog = new LogType("Discord")
const glog = new LogType("GuildUpdater")
@@ -49,6 +51,29 @@ function getGuildMembers(guildId) {
return guild.members.cache.map(member => member.user.id)
}
function getGuildMember(guildId, memberId) {
const guild = client.guilds.cache.get(guildId)
if(!guild) {
dlog.error("Guild not found: " + guildId)
return null
}
return guild.members.cache.get(memberId) || null
}
function getGuildRoles(guildId) {
const guild = client.guilds.cache.get(guildId)
if(!guild) {
dlog.error("Guild not found: " + guildId)
return []
}
return guild.roles.cache.map(role => ({
id: role.id,
name: role.name,
color: role.color,
position: role.position
}))
}
function getChannel(guildId, channelId) {
return client.guilds.cache.get(guildId).channels.cache.get(channelId)
}
@@ -77,7 +102,7 @@ function init() {
operational = true
})
client.on("interactionCreate", (interaction) => {
client.on("interactionCreate", async (interaction) => {
if(!interaction.isCommand()) return;
@@ -87,13 +112,27 @@ function init() {
numberOfCommandsServer.setValue(numberOfCommandsServer.getValue() + 1)
const command = client.commands.get(interaction.commandName)
const roleProtected = await serverSettings.getSecureRole(interaction.guild.id) || false
var havePermission = true;
if(roleProtected) {
await interaction.member.fetch()
if(!interaction.member.roles.cache.has(roleProtected.id)) {
havePermission = false;
}
}
try {
// Create a metric to count the number of commands executed by each user
const userCommand = new metric.Metric("userCommand_" + interaction.member.user.username, "Nombre de commandes éxécutées par l'utilisateur : " + interaction.member.user.username)
userCommand.setValue(userCommand.getValue() + 1)
dlog.log(interaction.member.user.username + "-> /" + interaction.commandName)
command.execute(client, interaction)
if(havePermission) {
command.execute(client, interaction)
} else {
const embed = new EmbedError(`L'utilisation du Bot est réservée aux membres ayant le rôle "${roleProtected.name}"`, interaction, true)
embed.setTitle("Accès refusé")
embed.send()
}
} catch(error) {
dlog.error(interaction.member.user.username + "-> /" + interaction.commandName + " : ERREUR RENCONTRE")
@@ -210,23 +249,15 @@ async function refreshGuilds() {
function checkRequiredPermission(guildMember) {
const requiredPermissions = [
'CreateInstantInvite', 'AddReactions',
'Stream', 'ViewChannel',
'SendMessages', 'SendTTSMessages',
'EmbedLinks', 'AttachFiles',
'ReadMessageHistory', 'UseExternalEmojis',
'Connect', 'Speak',
'UseVAD', 'ChangeNickname',
'UseApplicationCommands', 'RequestToSpeak',
'CreatePublicThreads', 'CreatePrivateThreads',
'UseExternalStickers', 'SendMessagesInThreads',
'UseEmbeddedActivities', 'UseSoundboard',
'UseExternalSounds', 'SendVoiceMessages',
'SendPolls', 'UseExternalApps'
]
'ViewChannel', // Voir les salons
'SendMessages', // Envoyer des messages texte
'ReadMessageHistory', // Lire lhistorique des messages
'Connect', // Se connecter aux salons vocaux
'Speak' // Parler dans les salons vocaux
]
return requiredPermissions.filter(permission => !guildMember.permissions.has(permission));
}
module.exports = {init, getClient, getGuilds, getMembersVoices, getChannel, getGuildMembers, isReady}
module.exports = {init, getClient, getGuilds, getMembersVoices, getChannel, getGuildMembers, getGuildMember, isReady, getGuildRoles}

View File

@@ -0,0 +1,38 @@
const { LogType } = require('loguix');
const clog = new LogType('ServerSettings');
const { __glob } = require('../utils/GlobalVars');
const { Database } = require('../utils/Database/Database');
const ServerDB = new Database("server_settings", __glob.SERVER_DB, {});
function getSecureRole(guildId) {
checkKey(guildId);
var role = ServerDB.getData()[guildId].secureRole || null;
if(role) {
if(role.name === "@everyone") {
return null;
}
}
return role;
}
function setSecureRole(guildId, roleId) {
checkKey(guildId);
ServerDB.getData()[guildId].secureRole = roleId;
ServerDB.save();
process.emit("USERS_UPDATE")
return true;
}
async function checkKey(guildId) {
const data = ServerDB.getData();
if (!data[guildId]) {
data[guildId] = { secureRole: null };
ServerDB.save();
}
}
module.exports = {
getSecureRole,
setSecureRole
};

View File

@@ -2,19 +2,35 @@ const {createAudioResource, VoiceConnectionStatus, createAudioPlayer, StreamType
const {LogType} = require('loguix')
const clog = new LogType("Youtube-Stream")
const ytdl = require('@distube/ytdl-core')
const ffmpeg = require('fluent-ffmpeg')
const { getRandomIPv6 } = require("@distube/ytdl-core/lib/utils");
const { __glob } = require('../../utils/GlobalVars');
const fs = require('fs');
async function getStream(song) {
// FIXME: Change youtube provider
try {
let stream = ytdl(song.url, {
const headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' +
'AppleWebKit/537.36 (KHTML, like Gecko) ' +
'Chrome/116.0.5845.97 Safari/537.36',
'Accept-Language': 'en-US,en;q=0.9'
};
var cookies = await JSON.parse(await fs.readFileSync(__glob.COOKIES, 'utf-8'));
const proxy = await JSON.parse(await fs.readFileSync(__glob.PROXY, 'utf-8'));
const agent = ytdl.createProxyAgent(proxy, cookies)
let stream = ytdl(song.url, {
quality: 'highestaudio',
highWaterMark: 1 << 30,
liveBuffer: 20000,
dlChunkSize: 0,
bitrate: 128,
requestOptions: {
headers: headers,
},
agent: agent,
});
return stream

View File

@@ -127,7 +127,7 @@ class Player {
checkConnection() {
if(this.connection === null) {
clog.error(`GUILD : ${this.guildId} - La connection n'est pas définie`)
// clog.error(`GUILD : ${this.guildId} - La connection n'est pas définie`)
return true
}
if(this.player === null) {

View File

@@ -19,6 +19,7 @@ const {__glob} = require("../utils/GlobalVars")
const playlists = require("../playlists/PlaylistManager")
const history = require("../playlists/History")
const lyrics = require("../lyrics/Lyrics")
const serverSettings = require("../discord/ServerSettings")
const mediaBase = require("../discord/MediaBase")
const googleApis = require("../playlists/Google/OAuth2")
const youtubeApi = require("../playlists/Google/YoutubeList")
@@ -34,8 +35,6 @@ const allConnectedUsers = new Array()
const guildConnectedUsers = new Map()
const UsersBySocket = new Map()
//TODO: Separate all request in separate files
function init() {
wlog.step.init("server_init", "Initialisation du serveur Socket.IO")
@@ -419,7 +418,7 @@ function init() {
// CHECKED : 03/05/2025
IORequest("/PLAYER/CHANNEL/CHANGE", () => {
handlePlayerAction(actualGuildId, (player) => {
const channel = getUserChannel()
const channel = getUserChannel(false, true)
if(!channel) {
IOAnswer("/PLAYER/CHANNEL/CHANGE", false)
return
@@ -793,7 +792,36 @@ function init() {
IOAnswer("/OWNER/USERS/SWITCH_MOD", true)
})
IORequest("/OWNER/ROLES/GET", async () => {
if(!actualGuildId) return IOAnswer("/OWNER/ROLES/GET", false)
const guild = discordBot.getGuilds().get(actualGuildId)
if(!socketUser.identity.id === guild.owner) return IOAnswer("/OWNER/ROLES/GET", false)
const rolesSecure = discordBot.getGuildRoles(actualGuildId)
const actualRole = await serverSettings.getSecureRole(actualGuildId)
// Move the actual role at the start of the array
if(actualRole) {
const index = rolesSecure.findIndex(r => r.id === actualRole.id)
if(index > -1) {
rolesSecure.unshift(rolesSecure.splice(index, 1)[0])
}
} else {
// Find the @everyone role and put it at the start of the array
const index = rolesSecure.findIndex(r => r.name === "@everyone")
if(index > -1) {
rolesSecure.unshift(rolesSecure.splice(index, 1)[0])
}
}
IOAnswer("/OWNER/ROLES/GET", await rolesSecure)
})
IORequest("/OWNER/ROLES/SET", async (data) => {
if(!actualGuildId) return IOAnswer("/OWNER/ROLES/SET", false)
const guild = discordBot.getGuilds().get(actualGuildId)
if(!socketUser.identity.id === guild.owner) return IOAnswer("/OWNER/ROLES/SET", false)
await serverSettings.setSecureRole(actualGuildId, data)
IOAnswer("/OWNER/ROLES/SET", true)
})
// CHECKED : 24/04/2025
IORequest("/MOD/USERS/BAN", async (userId) => {
if(!userId || !actualGuildId) return IOAnswer("/MOD/USERS/BAN", false)
@@ -873,9 +901,9 @@ function init() {
// Functions
function getUserChannel(usual) {
function getUserChannel(usual, force) {
const botChannel = getBotChannel()
if(botChannel) {
if(botChannel && !force) {
return botChannel
}
const membersVoices = discordBot.getMembersVoices()
@@ -907,6 +935,18 @@ function init() {
const guildData = guild[1]
guildData['members'] = new Array()
guildData.serverMember = guild[1].allMembers.length
guildData.restricted = false
const secureRole = serverSettings.getSecureRole(guild[0])
if(secureRole && socketUser.identity.id !== discordBot.getGuilds().get(guild[0]).owner) {
const member = discordBot.getGuildMember(guild[0], socketUser.identity.id)
if(!member.roles.cache.has(secureRole.id) && socketUser.identity.id !== guild[1].owner && !socketUser.isAdmin()) {
guildData.restricted = true
} else {
guildData.restricted = false
}
}
guildData.allowed = true
for(var user of guildConnectedUsers.get(guild[0]) || []) {
const userData = users.getUserById(user.id)
if(userData && userData.identity.id != socketUser.identity.id) {
@@ -986,6 +1026,15 @@ function init() {
wlog.warn("Aucun guildId n'est actif pour l'utilisateur : " + socketUser.identity.username)
return false
}
// Check role if secure role is set
const secureRole = serverSettings.getSecureRole(guildId)
if(secureRole && socketUser.identity.id !== discordBot.getGuilds().get(guildId).owner) {
const member = discordBot.getGuildMember(guildId, socketUser.identity.id)
if(member.roles.cache.has(secureRole.id) == false) {
wlog.warn("L'utilisateur '" + socketUser.identity.username + "' n'a pas le rôle requis pour accéder à la guilde : " + guildId)
return false
}
}
// Check if the guildId is referenced in the bot guilds
if(!discordBot.getGuilds().has(guildId)) {
wlog.warn("La guilde : " + guildId + " n'est pas référencée dans le bot")

View File

@@ -8,15 +8,18 @@ const __glob = {
SRC: root + path.sep + "src",
LOGS: root + path.sep + "logs",
DATA: root + path.sep + "data",
COMMANDS: root + path.sep + "src" + path.sep + "discord" + path.sep + "commands",
COMMANDS: root + path.sep + "src" + path.sep + "discord" + path.sep + "Commands",
METRIC_FILE: root + path.sep + "data" + path.sep + "metrics.json",
PREVIOUSFILE: root + path.sep + "data" + path.sep + "previous.json",
USERFILE: root + path.sep + "data" + path.sep + "users.json",
PLAYLISTFILE: root + path.sep + "data" + path.sep + "playlists.json",
HISTORY_DB: root + path.sep + "data" + path.sep + "history.json",
MEDIA_DB: root + path.sep + "data" + path.sep + "media.json",
SERVER_DB: root + path.sep + "data" + path.sep + "servers.json",
VERSION: version,
CHANGELOG_PATH: root + path.sep + "CHANGELOG.html",
COOKIES: root + path.sep + "data" + path.sep + "cookies.json",
PROXY: root + path.sep + "data" + path.sep + "proxy.json"
}
module.exports = {__glob}