Initial Commit
This commit is contained in:
commit
6d2e379a0c
41 changed files with 5064 additions and 0 deletions
13
.env.example
Normal file
13
.env.example
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
NODE_ENV=test
|
||||||
|
LOCATION=
|
||||||
|
BOT_OWNER=
|
||||||
|
DISCORD_GUILD_ID=
|
||||||
|
SHINUWA_USER_ID=
|
||||||
|
INVITE_LINK=
|
||||||
|
WEB_SERVER_PORT=3000
|
||||||
|
WEB_API_KEY=
|
||||||
|
DISCORD_APPLICATION_ID=
|
||||||
|
DISCORD_TOKEN=
|
||||||
|
VOICE_CHANNEL_ID=
|
||||||
|
TEXT_CHANNEL_ID=
|
||||||
|
GAME_SERVERS_MESSAGE_ID=
|
||||||
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#node
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Local configuration and test data
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
src/static/gameservers-list.json
|
||||||
|
|
||||||
|
#storage
|
||||||
|
storage/permanent/*
|
||||||
|
!storage/permanent/.gitkeep
|
||||||
|
storage/temp/*
|
||||||
|
!storage/temp/.gitkeep
|
||||||
26
README.md
Normal file
26
README.md
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# palico-bot
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
La configuration sensible est stockée dans deux fichiers exclus de Git :
|
||||||
|
|
||||||
|
- `.env.local` pour le bot de test en local ;
|
||||||
|
- `.env.production` pour le bot de production sur la VM.
|
||||||
|
|
||||||
|
Le fichier `.env.example` documente les variables attendues sans contenir de
|
||||||
|
secret. Les fichiers réels doivent rester hors du dépôt.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Lancer le bot local
|
||||||
|
npm start
|
||||||
|
|
||||||
|
# Lancer le bot sur la VM
|
||||||
|
npm run start:prod
|
||||||
|
|
||||||
|
# Déployer les commandes locales ou de production
|
||||||
|
npm run deploy
|
||||||
|
npm run deploy:prod
|
||||||
|
```
|
||||||
|
|
||||||
|
Node.js 20.6 ou supérieur est nécessaire pour la prise en charge native de
|
||||||
|
`--env-file`.
|
||||||
56
deployCommands.js
Normal file
56
deployCommands.js
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
import { REST, Routes } from "discord.js";
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import { config } from "./src/config.js";
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
|
const commands = [];
|
||||||
|
const foldersPath = path.join(__dirname, "src/commands");
|
||||||
|
const commandFolders = fs.readdirSync(foldersPath);
|
||||||
|
|
||||||
|
for (const folder of commandFolders) {
|
||||||
|
if (folder.indexOf("[disabled]") === -1 || config.environnement === "test") {
|
||||||
|
const commandsPath = path.join(foldersPath, folder);
|
||||||
|
const commandFiles = fs
|
||||||
|
.readdirSync(commandsPath)
|
||||||
|
.filter((file) => file.endsWith(".js"));
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const filePath = path.join(commandsPath, file);
|
||||||
|
const commandFile = await import(filePath);
|
||||||
|
if ("data" in commandFile.command && "execute" in commandFile.command) {
|
||||||
|
commands.push(commandFile.command.data.toJSON());
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const rest = new REST().setToken(config.token);
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
console.log(
|
||||||
|
`Started refreshing ${commands.length} application (/) commands.`
|
||||||
|
);
|
||||||
|
|
||||||
|
const data = await rest.put(
|
||||||
|
Routes.applicationGuildCommands(
|
||||||
|
config.applicationId,
|
||||||
|
config.discordGuildId
|
||||||
|
),
|
||||||
|
{ body: commands }
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Successfully reloaded ${data.length} application (/) commands.`
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
})();
|
||||||
64
index.js
Normal file
64
index.js
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
import { Client, Collection, GatewayIntentBits } from "discord.js";
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import { config } from "./src/config.js";
|
||||||
|
import { MusicQueue } from "./src/music/queue.js";
|
||||||
|
import { startWebServer } from "./src/web/server.js";
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
|
const client = new Client({
|
||||||
|
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates],
|
||||||
|
});
|
||||||
|
|
||||||
|
client.commands = new Collection();
|
||||||
|
const foldersPath = path.join(__dirname, "src/commands");
|
||||||
|
const commandFolders = fs.readdirSync(foldersPath);
|
||||||
|
|
||||||
|
for (const folder of commandFolders) {
|
||||||
|
if (folder.indexOf("[disabled]") === -1 || config.environnement === "test") {
|
||||||
|
const commandsPath = path.join(foldersPath, folder);
|
||||||
|
const commandFiles = fs
|
||||||
|
.readdirSync(commandsPath)
|
||||||
|
.filter((file) => file.endsWith(".js"));
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const filePath = path.join(commandsPath, file);
|
||||||
|
const commandFile = await import(filePath);
|
||||||
|
if ("data" in commandFile.command && "execute" in commandFile.command) {
|
||||||
|
client.commands.set(commandFile.command.data.name, commandFile);
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const eventsPath = path.join(__dirname, "src/events");
|
||||||
|
const eventFiles = fs
|
||||||
|
.readdirSync(eventsPath)
|
||||||
|
.filter((file) => file.endsWith(".js"));
|
||||||
|
|
||||||
|
for (const file of eventFiles) {
|
||||||
|
const filePath = path.join(eventsPath, file);
|
||||||
|
const eventFile = await import(filePath);
|
||||||
|
if (eventFile.event.once) {
|
||||||
|
client.once(eventFile.event.name, (...args) =>
|
||||||
|
eventFile.event.execute(...args)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
client.on(eventFile.event.name, (...args) =>
|
||||||
|
eventFile.event.execute(...args)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
client.login(config.token);
|
||||||
|
|
||||||
|
const musicQueue = new MusicQueue(client);
|
||||||
|
startWebServer({ queue: musicQueue });
|
||||||
|
|
||||||
|
export { client, musicQueue };
|
||||||
2020
package-lock.json
generated
Normal file
2020
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
28
package.json
Normal file
28
package.json
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"name": "palico-bot",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node --env-file=.env.local index.js",
|
||||||
|
"start:prod": "node --env-file=.env.production index.js",
|
||||||
|
"deploy": "node --env-file=.env.local deployCommands.js",
|
||||||
|
"deploy:prod": "node --env-file=.env.production deployCommands.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20.6.0"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"description": "",
|
||||||
|
"dependencies": {
|
||||||
|
"@discordjs/opus": "^0.10.0",
|
||||||
|
"@discordjs/voice": "^0.18.0",
|
||||||
|
"discord.js": "^14.18.0",
|
||||||
|
"express": "^5.1.0",
|
||||||
|
"libsodium-wrappers": "^0.7.15",
|
||||||
|
"multer": "^1.4.5-lts.1",
|
||||||
|
"uuid": "^11.0.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
public/img/palico-index.png
Normal file
BIN
public/img/palico-index.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.3 MiB |
BIN
public/img/palico-jukebox.png
Normal file
BIN
public/img/palico-jukebox.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
37
public/index.html
Normal file
37
public/index.html
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Palico Bot</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<link rel="stylesheet" href="/style/styles.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="hero hero--home">
|
||||||
|
<div class="hero__visual">
|
||||||
|
<img src="/img/palico-index.png" alt="Palico Bot" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="hero__content">
|
||||||
|
<p class="pill">Palico Bot</p>
|
||||||
|
<h1>Bienvenue sur la webapp</h1>
|
||||||
|
<p>
|
||||||
|
Lance de la musique sur le Discord et pilote la playlist du salon vocal.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<section class="panel panel--glass">
|
||||||
|
<div class="feature-grid">
|
||||||
|
<a class="feature-grid__card" href="/jukebox/">
|
||||||
|
<p class="pill">Le Jukebox du Palico Bot</p>
|
||||||
|
<p class="panel__subtitle">
|
||||||
|
Upload, gère et pilote la playlist du salon vocal en direct.
|
||||||
|
</p>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
182
public/jukebox.html
Normal file
182
public/jukebox.html
Normal file
|
|
@ -0,0 +1,182 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Palico Jukebox</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<link rel="stylesheet" href="/style/styles.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="hero">
|
||||||
|
<div class="hero__visual">
|
||||||
|
<img src="/img/palico-jukebox.png" alt="Palico Jukebox" />
|
||||||
|
</div>
|
||||||
|
<div class="hero__content">
|
||||||
|
<p class="pill">Le Jukebox du Palico Bot</p>
|
||||||
|
<h1>Un peu de son pour le Discord !</h1>
|
||||||
|
<p>
|
||||||
|
Tu veux chill avec les autres sur un petit fond musical ?<br />
|
||||||
|
T'inquietes pas, je peux m'occuper de ca !<br />
|
||||||
|
<br />
|
||||||
|
Uploade des fichiers et gère la playlist depuis cette interface web.
|
||||||
|
Tout est synchronisé avec le salon vocal.
|
||||||
|
</p>
|
||||||
|
<div class="hero__actions">
|
||||||
|
<button id="heroUploadBtn" class="btn">Ajouter une musique</button>
|
||||||
|
<button id="heroQueueBtn" class="btn btn--ghost">Voir la file</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="hero__auth">
|
||||||
|
<div class="panel panel--glass">
|
||||||
|
<h2>Authentification</h2>
|
||||||
|
<p class="panel__subtitle">
|
||||||
|
Ca sera stocké sur ton navigateur si tu sauvegardes !
|
||||||
|
</p>
|
||||||
|
<form id="settingsForm">
|
||||||
|
<div class="grid grid--two">
|
||||||
|
<div>
|
||||||
|
<label for="displayName">Nom affiché</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="displayName"
|
||||||
|
name="displayName"
|
||||||
|
placeholder="Shinuwa"
|
||||||
|
autocomplete="off"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="apiKey">Mot de passe</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="apiKey"
|
||||||
|
name="apiKey"
|
||||||
|
placeholder="Mot de passe"
|
||||||
|
autocomplete="off"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-actions">
|
||||||
|
<button type="submit" class="btn">Sauvegarder</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<div id="status" class="status status--info" hidden></div>
|
||||||
|
|
||||||
|
<section class="panel panel--glass">
|
||||||
|
<div class="panel__header">
|
||||||
|
<div>
|
||||||
|
<h2>Lecture en cours</h2>
|
||||||
|
<p class="panel__subtitle">
|
||||||
|
État en temps réel du player Discord. Contrôle instantané.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button id="refreshBtn" class="btn btn--ghost btn--small">Rafraîchir</button>
|
||||||
|
</div>
|
||||||
|
<div id="currentTrack" class="player-current player-current--empty">
|
||||||
|
En attente de lecture...
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<button class="btn" data-player-action="play">Play</button>
|
||||||
|
<button
|
||||||
|
id="pauseResumeBtn"
|
||||||
|
class="btn btn--secondary"
|
||||||
|
data-player-action="pause"
|
||||||
|
>
|
||||||
|
Pause
|
||||||
|
</button>
|
||||||
|
<button class="btn" data-player-action="skip">Suivante</button>
|
||||||
|
<button class="btn btn--danger" data-player-action="stop">
|
||||||
|
Stop & vider la file
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="panel panel--glass" id="queueSection">
|
||||||
|
<div class="panel__header">
|
||||||
|
<div>
|
||||||
|
<h2>File d'attente</h2>
|
||||||
|
<p class="panel__subtitle">
|
||||||
|
Réorganise les morceaux, supprime-les ou ajoute ceux de la
|
||||||
|
bibliothèque.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<ul id="queueList" class="list list--stack"></ul>
|
||||||
|
<p id="queueEmpty" class="text--muted">Aucun morceau en attente.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="panel panel--glass">
|
||||||
|
<h2>Bibliothèque permanente</h2>
|
||||||
|
<p class="panel__subtitle">
|
||||||
|
Les fichiers conservés sont listés ici. Ajoute-les à la file ou
|
||||||
|
supprime-les.
|
||||||
|
</p>
|
||||||
|
<ul id="libraryList" class="list list--stack"></ul>
|
||||||
|
<p id="libraryEmpty" class="text--muted">
|
||||||
|
Aucun fichier permanent enregistré.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="panel panel--glass" id="uploadSection">
|
||||||
|
<div class="panel__header">
|
||||||
|
<div>
|
||||||
|
<h2>Uploader une musique</h2>
|
||||||
|
<p class="panel__subtitle">
|
||||||
|
Formats audio supportés par FFmpeg. Les fichiers temporaires sont
|
||||||
|
supprimés automatiquement après lecture.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="badge">Drag & drop supporté</div>
|
||||||
|
</div>
|
||||||
|
<form id="uploadForm">
|
||||||
|
<label for="musicFile">Fichier audio</label>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
id="musicFile"
|
||||||
|
name="musicFile"
|
||||||
|
accept="audio/*"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
|
||||||
|
<label for="uploadNotes" class="u-mt-1">Commentaire (optionnel)</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="uploadNotes"
|
||||||
|
name="notes"
|
||||||
|
placeholder="Titre personnalisé"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="grid grid--two u-mt-1">
|
||||||
|
<label class="form-checkbox">
|
||||||
|
<input type="checkbox" id="permanentFile" class="form-checkbox__input" />
|
||||||
|
<span>Conserver dans la bibliothèque après lecture</span>
|
||||||
|
</label>
|
||||||
|
<label class="form-checkbox">
|
||||||
|
<input type="checkbox" id="enqueueFile" checked class="form-checkbox__input" />
|
||||||
|
<span>Ajouter directement à la file d'attente</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn u-mt-1">Uploader</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<div class="hero__actions hero__actions--centered">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn--ghost btn--small"
|
||||||
|
onclick="window.location.href = '/'"
|
||||||
|
>
|
||||||
|
Retour à l'accueil
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="module" src="/scripts/jukebox.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
118
public/scripts/common.js
Normal file
118
public/scripts/common.js
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
const API_KEY_STORAGE_KEY = "palico-api-key";
|
||||||
|
const DISPLAY_NAME_STORAGE_KEY = "palico-display-name";
|
||||||
|
|
||||||
|
export function getStoredApiKey() {
|
||||||
|
return localStorage.getItem(API_KEY_STORAGE_KEY) || "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setStoredApiKey(value) {
|
||||||
|
localStorage.setItem(API_KEY_STORAGE_KEY, value || "");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getStoredDisplayName() {
|
||||||
|
return localStorage.getItem(DISPLAY_NAME_STORAGE_KEY) || "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setStoredDisplayName(value) {
|
||||||
|
localStorage.setItem(DISPLAY_NAME_STORAGE_KEY, value || "");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createStatusManager(statusElement) {
|
||||||
|
let hideTimeout;
|
||||||
|
|
||||||
|
function setStatus(message, type = "info", autoHide = true) {
|
||||||
|
if (!statusElement) return;
|
||||||
|
statusElement.textContent = message;
|
||||||
|
statusElement.className = `status status--${type}`;
|
||||||
|
statusElement.hidden = false;
|
||||||
|
|
||||||
|
if (autoHide) {
|
||||||
|
clearTimeout(hideTimeout);
|
||||||
|
hideTimeout = setTimeout(() => {
|
||||||
|
statusElement.hidden = true;
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearStatus() {
|
||||||
|
if (!statusElement) return;
|
||||||
|
statusElement.hidden = true;
|
||||||
|
statusElement.textContent = "";
|
||||||
|
clearTimeout(hideTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { setStatus, clearStatus };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function escapeHtml(text = "") {
|
||||||
|
return text
|
||||||
|
.toString()
|
||||||
|
.replace(/&/g, "&")
|
||||||
|
.replace(/</g, "<")
|
||||||
|
.replace(/>/g, ">")
|
||||||
|
.replace(/"/g, """)
|
||||||
|
.replace(/'/g, "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatBytes(bytes = 0) {
|
||||||
|
if (!Number(bytes)) return "0 B";
|
||||||
|
const units = ["B", "KB", "MB", "GB", "TB"];
|
||||||
|
const index = Math.floor(Math.log(bytes) / Math.log(1024));
|
||||||
|
return `${(bytes / Math.pow(1024, index)).toFixed(1)} ${units[index]}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatDate(value) {
|
||||||
|
if (!value) return "?";
|
||||||
|
try {
|
||||||
|
return new Date(value).toLocaleString();
|
||||||
|
} catch (_) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createApiClient({ getApiKey, basePath = "" } = {}) {
|
||||||
|
const normalizedBase = (basePath || "").replace(/\/$/, "");
|
||||||
|
|
||||||
|
return async function apiFetch(path, options = {}) {
|
||||||
|
const url = path.startsWith("http")
|
||||||
|
? path
|
||||||
|
: `${normalizedBase}${path.startsWith("/") ? "" : "/"}${path}`;
|
||||||
|
|
||||||
|
const fetchOptions = {
|
||||||
|
method: options.method || "GET",
|
||||||
|
headers: new Headers(options.headers || {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiKey = typeof getApiKey === "function" ? getApiKey() : null;
|
||||||
|
if (apiKey) {
|
||||||
|
fetchOptions.headers.set("Authorization", `Bearer ${apiKey}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.body instanceof FormData) {
|
||||||
|
fetchOptions.body = options.body;
|
||||||
|
} else if (options.body) {
|
||||||
|
if (!fetchOptions.headers.has("Content-Type")) {
|
||||||
|
fetchOptions.headers.set("Content-Type", "application/json");
|
||||||
|
}
|
||||||
|
fetchOptions.body =
|
||||||
|
typeof options.body === "string" ? options.body : JSON.stringify(options.body);
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(url, fetchOptions);
|
||||||
|
const contentType = response.headers.get("content-type") || "";
|
||||||
|
let payload = null;
|
||||||
|
|
||||||
|
if (contentType.includes("application/json")) {
|
||||||
|
payload = await response.json();
|
||||||
|
} else {
|
||||||
|
payload = await response.text();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorMessage = payload?.error || payload?.message || response.statusText;
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload;
|
||||||
|
};
|
||||||
|
}
|
||||||
319
public/scripts/jukebox.js
Normal file
319
public/scripts/jukebox.js
Normal file
|
|
@ -0,0 +1,319 @@
|
||||||
|
import {
|
||||||
|
createApiClient,
|
||||||
|
createStatusManager,
|
||||||
|
escapeHtml,
|
||||||
|
getStoredApiKey,
|
||||||
|
getStoredDisplayName,
|
||||||
|
formatBytes,
|
||||||
|
formatDate,
|
||||||
|
setStoredApiKey,
|
||||||
|
setStoredDisplayName,
|
||||||
|
} from "./common.js";
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
apiKey: getStoredApiKey(),
|
||||||
|
displayName: getStoredDisplayName(),
|
||||||
|
queue: [],
|
||||||
|
current: null,
|
||||||
|
library: [],
|
||||||
|
status: "idle",
|
||||||
|
};
|
||||||
|
|
||||||
|
const elements = {
|
||||||
|
status: document.getElementById("status"),
|
||||||
|
apiKeyInput: document.getElementById("apiKey"),
|
||||||
|
displayNameInput: document.getElementById("displayName"),
|
||||||
|
settingsForm: document.getElementById("settingsForm"),
|
||||||
|
uploadForm: document.getElementById("uploadForm"),
|
||||||
|
fileInput: document.getElementById("musicFile"),
|
||||||
|
notesInput: document.getElementById("uploadNotes"),
|
||||||
|
permanentCheckbox: document.getElementById("permanentFile"),
|
||||||
|
enqueueCheckbox: document.getElementById("enqueueFile"),
|
||||||
|
currentTrack: document.getElementById("currentTrack"),
|
||||||
|
queueList: document.getElementById("queueList"),
|
||||||
|
queueEmpty: document.getElementById("queueEmpty"),
|
||||||
|
libraryList: document.getElementById("libraryList"),
|
||||||
|
libraryEmpty: document.getElementById("libraryEmpty"),
|
||||||
|
refreshBtn: document.getElementById("refreshBtn"),
|
||||||
|
pauseResumeBtn: document.getElementById("pauseResumeBtn"),
|
||||||
|
playerButtons: document.querySelectorAll("[data-player-action]"),
|
||||||
|
heroUploadBtn: document.getElementById("heroUploadBtn"),
|
||||||
|
heroQueueBtn: document.getElementById("heroQueueBtn"),
|
||||||
|
uploadSection: document.getElementById("uploadSection"),
|
||||||
|
queueSection: document.getElementById("queueSection"),
|
||||||
|
};
|
||||||
|
|
||||||
|
let pollIntervalId = null;
|
||||||
|
|
||||||
|
const { setStatus, clearStatus } = createStatusManager(elements.status);
|
||||||
|
const apiFetch = createApiClient({
|
||||||
|
basePath: "/api",
|
||||||
|
getApiKey: () => state.apiKey,
|
||||||
|
});
|
||||||
|
|
||||||
|
async function refreshAll({ silent = false } = {}) {
|
||||||
|
if (!silent) {
|
||||||
|
clearStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [queueData, libraryData] = await Promise.all([
|
||||||
|
apiFetch("/queue"),
|
||||||
|
apiFetch("/library"),
|
||||||
|
]);
|
||||||
|
|
||||||
|
state.current = queueData.current;
|
||||||
|
state.queue = queueData.upcoming || [];
|
||||||
|
state.library = libraryData.tracks || [];
|
||||||
|
state.status = queueData.status || "idle";
|
||||||
|
|
||||||
|
renderCurrentTrack();
|
||||||
|
renderQueue();
|
||||||
|
renderLibrary();
|
||||||
|
updatePauseResumeButton();
|
||||||
|
} catch (error) {
|
||||||
|
setStatus(`Erreur: ${error.message}`, "error", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderCurrentTrack() {
|
||||||
|
if (!elements.currentTrack) return;
|
||||||
|
if (!state.current) {
|
||||||
|
elements.currentTrack.classList.add("player-current--empty");
|
||||||
|
elements.currentTrack.innerHTML = "En attente de lecture...";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
elements.currentTrack.classList.remove("player-current--empty");
|
||||||
|
const track = state.current;
|
||||||
|
const permanence = track.permanent ? "Permanent" : "Temporaire";
|
||||||
|
elements.currentTrack.innerHTML = `
|
||||||
|
<div class="media-item__title">${escapeHtml(track.title || track.originalName)}</div>
|
||||||
|
<div class="media-item__meta">
|
||||||
|
${permanence} • ${formatBytes(track.size)} • Ajouté par ${escapeHtml(
|
||||||
|
track.uploader || "inconnu"
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="media-item__meta">Commencé à ${formatDate(track.createdAt)}</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderQueue() {
|
||||||
|
if (!elements.queueList) return;
|
||||||
|
elements.queueList.innerHTML = "";
|
||||||
|
|
||||||
|
if (!state.queue || state.queue.length === 0) {
|
||||||
|
elements.queueEmpty.style.display = "block";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
elements.queueEmpty.style.display = "none";
|
||||||
|
|
||||||
|
state.queue.forEach((track, index) => {
|
||||||
|
const li = document.createElement("li");
|
||||||
|
li.className = "media-item media-item--queue";
|
||||||
|
const permanence = track.permanent ? "Permanent" : "Temporaire";
|
||||||
|
li.innerHTML = `
|
||||||
|
<div class="media-item__info">
|
||||||
|
<div class="media-item__title">${escapeHtml(track.title || track.originalName)}</div>
|
||||||
|
<div class="media-item__meta">
|
||||||
|
${permanence} • ${formatBytes(track.size)} • Ajouté par ${escapeHtml(
|
||||||
|
track.uploader || "inconnu"
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="media-item__actions">
|
||||||
|
<button class="btn btn--secondary" data-action="up" data-track="${track.id}">▲</button>
|
||||||
|
<button class="btn btn--secondary" data-action="down" data-track="${track.id}">▼</button>
|
||||||
|
<button class="btn btn--danger" data-action="remove" data-track="${track.id}">Supprimer</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
li.querySelectorAll("button").forEach((btn) => {
|
||||||
|
btn.addEventListener("click", (event) => {
|
||||||
|
const action = event.currentTarget.dataset.action;
|
||||||
|
const trackId = event.currentTarget.dataset.track;
|
||||||
|
handleQueueAction(action, trackId, index);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
elements.queueList.appendChild(li);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderLibrary() {
|
||||||
|
if (!elements.libraryList) return;
|
||||||
|
elements.libraryList.innerHTML = "";
|
||||||
|
|
||||||
|
if (!state.library || state.library.length === 0) {
|
||||||
|
elements.libraryEmpty.style.display = "block";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
elements.libraryEmpty.style.display = "none";
|
||||||
|
|
||||||
|
state.library.forEach((track) => {
|
||||||
|
const li = document.createElement("li");
|
||||||
|
li.className = "media-item media-item--library";
|
||||||
|
li.innerHTML = `
|
||||||
|
<div class="media-item__info">
|
||||||
|
<div class="media-item__title">${escapeHtml(track.originalName)}</div>
|
||||||
|
<div class="media-item__meta">
|
||||||
|
${formatBytes(track.size)} • Ajouté le ${formatDate(track.createdAt)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="media-item__actions">
|
||||||
|
<button class="btn" data-library-action="enqueue" data-library-id="${track.id}">Ajouter</button>
|
||||||
|
<button class="btn btn--danger" data-library-action="delete" data-library-id="${track.id}">
|
||||||
|
Supprimer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
li.querySelectorAll("button").forEach((btn) => {
|
||||||
|
btn.addEventListener("click", (event) => {
|
||||||
|
const action = event.currentTarget.dataset.libraryAction;
|
||||||
|
const libraryId = event.currentTarget.dataset.libraryId;
|
||||||
|
handleLibraryAction(action, libraryId);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
elements.libraryList.appendChild(li);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updatePauseResumeButton() {
|
||||||
|
if (!elements.pauseResumeBtn) return;
|
||||||
|
const normalizedStatus =
|
||||||
|
typeof state.status === "string" ? state.status.toLowerCase() : "idle";
|
||||||
|
const isPaused = normalizedStatus === "paused";
|
||||||
|
const isPlaying = normalizedStatus === "playing";
|
||||||
|
|
||||||
|
if (isPaused) {
|
||||||
|
elements.pauseResumeBtn.textContent = "Reprendre";
|
||||||
|
elements.pauseResumeBtn.dataset.playerAction = "resume";
|
||||||
|
} else {
|
||||||
|
elements.pauseResumeBtn.textContent = "Pause";
|
||||||
|
elements.pauseResumeBtn.dataset.playerAction = "pause";
|
||||||
|
}
|
||||||
|
|
||||||
|
const actionable = isPaused || isPlaying;
|
||||||
|
elements.pauseResumeBtn.disabled = !actionable;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleQueueAction(action, trackId, index) {
|
||||||
|
try {
|
||||||
|
if (action === "remove") {
|
||||||
|
await apiFetch(`/queue/${trackId}`, { method: "DELETE" });
|
||||||
|
} else if (action === "up" || action === "down") {
|
||||||
|
const delta = action === "up" ? -1 : 1;
|
||||||
|
const newPosition = Math.max(0, Math.min(index + delta, state.queue.length - 1));
|
||||||
|
if (newPosition === index) return;
|
||||||
|
await apiFetch(`/queue/${trackId}/move`, {
|
||||||
|
method: "PATCH",
|
||||||
|
body: { position: newPosition },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await refreshAll({ silent: true });
|
||||||
|
} catch (error) {
|
||||||
|
setStatus(`Impossible de mettre à jour la file: ${error.message}`, "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleLibraryAction(action, libraryId) {
|
||||||
|
try {
|
||||||
|
if (action === "enqueue") {
|
||||||
|
await apiFetch(`/library/${libraryId}/enqueue`, {
|
||||||
|
method: "POST",
|
||||||
|
body: { requestedBy: state.displayName || "web-ui" },
|
||||||
|
});
|
||||||
|
} else if (action === "delete") {
|
||||||
|
if (!confirm("Supprimer ce fichier permanent ?")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await apiFetch(`/library/${libraryId}`, { method: "DELETE" });
|
||||||
|
}
|
||||||
|
await refreshAll({ silent: true });
|
||||||
|
} catch (error) {
|
||||||
|
setStatus(`Action bibliothèque impossible: ${error.message}`, "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startPolling() {
|
||||||
|
clearInterval(pollIntervalId);
|
||||||
|
pollIntervalId = setInterval(() => refreshAll({ silent: true }), 5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindEvents() {
|
||||||
|
elements.settingsForm?.addEventListener("submit", (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
state.apiKey = elements.apiKeyInput.value.trim();
|
||||||
|
state.displayName = elements.displayNameInput.value.trim();
|
||||||
|
setStoredApiKey(state.apiKey);
|
||||||
|
setStoredDisplayName(state.displayName);
|
||||||
|
setStatus("Paramètres sauvegardés", "success");
|
||||||
|
refreshAll({ silent: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
elements.uploadForm?.addEventListener("submit", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const file = elements.fileInput.files[0];
|
||||||
|
if (!file) {
|
||||||
|
setStatus("Merci de sélectionner un fichier audio", "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = new FormData();
|
||||||
|
data.append("file", file);
|
||||||
|
data.append("permanent", elements.permanentCheckbox.checked ? "true" : "false");
|
||||||
|
data.append("enqueue", elements.enqueueCheckbox.checked ? "true" : "false");
|
||||||
|
if (state.displayName) {
|
||||||
|
data.append("uploader", state.displayName);
|
||||||
|
}
|
||||||
|
if (elements.notesInput.value) {
|
||||||
|
data.append("notes", elements.notesInput.value.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
setStatus("Upload en cours...", "info", false);
|
||||||
|
await apiFetch("/uploads", { method: "POST", body: data });
|
||||||
|
elements.uploadForm.reset();
|
||||||
|
elements.enqueueCheckbox.checked = true;
|
||||||
|
setStatus("Fichier envoyé avec succès", "success");
|
||||||
|
await refreshAll({ silent: true });
|
||||||
|
} catch (error) {
|
||||||
|
setStatus(`Échec de l'upload: ${error.message}`, "error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
elements.refreshBtn?.addEventListener("click", () => refreshAll());
|
||||||
|
elements.heroUploadBtn?.addEventListener("click", () =>
|
||||||
|
elements.uploadSection?.scrollIntoView({ behavior: "smooth" })
|
||||||
|
);
|
||||||
|
elements.heroQueueBtn?.addEventListener("click", () =>
|
||||||
|
elements.queueSection?.scrollIntoView({ behavior: "smooth" })
|
||||||
|
);
|
||||||
|
|
||||||
|
elements.playerButtons?.forEach((button) => {
|
||||||
|
button.addEventListener("click", async () => {
|
||||||
|
const action = button.dataset.playerAction;
|
||||||
|
try {
|
||||||
|
await apiFetch(`/player/${action}`, { method: "POST" });
|
||||||
|
await refreshAll({ silent: true });
|
||||||
|
} catch (error) {
|
||||||
|
setStatus(`Action player impossible: ${error.message}`, "error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function initialize() {
|
||||||
|
elements.apiKeyInput.value = state.apiKey;
|
||||||
|
elements.displayNameInput.value = state.displayName;
|
||||||
|
bindEvents();
|
||||||
|
updatePauseResumeButton();
|
||||||
|
refreshAll();
|
||||||
|
startPolling();
|
||||||
|
}
|
||||||
|
|
||||||
|
initialize();
|
||||||
415
public/style/styles.css
Normal file
415
public/style/styles.css
Normal file
|
|
@ -0,0 +1,415 @@
|
||||||
|
:root {
|
||||||
|
color-scheme: dark;
|
||||||
|
--bg: #06030d;
|
||||||
|
--bg-card: rgba(22, 14, 36, 0.9);
|
||||||
|
--bg-glass: rgba(42, 25, 66, 0.65);
|
||||||
|
--border: rgba(255, 255, 255, 0.08);
|
||||||
|
--accent: #b259ff;
|
||||||
|
--accent-strong: #d66bff;
|
||||||
|
--muted: #cbc4d5;
|
||||||
|
--muted-dark: #8c7ea7;
|
||||||
|
--danger: #ff4d6d;
|
||||||
|
--success: #59ffa7;
|
||||||
|
--gradient: radial-gradient(circle at 20% 20%, #2d1a49, transparent 45%),
|
||||||
|
radial-gradient(circle at 80% 0%, #551e8c, transparent 40%),
|
||||||
|
radial-gradient(circle at 50% 80%, #150b28, transparent 30%);
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
min-height: 100vh;
|
||||||
|
font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
|
||||||
|
background: var(--gradient), #050109;
|
||||||
|
color: #f7f1ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0 1.5rem 4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3,
|
||||||
|
h4 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text--muted {
|
||||||
|
color: var(--muted);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 2rem;
|
||||||
|
padding: 3rem 1.5rem;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero--home {
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
text-align: left;
|
||||||
|
gap: 2.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero--home .hero__visual img {
|
||||||
|
max-width: 320px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero__content {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 280px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero__content h1 {
|
||||||
|
font-size: 2.2rem;
|
||||||
|
line-height: 1.1;
|
||||||
|
margin-top: 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero__content p {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 1.05rem;
|
||||||
|
max-width: 500px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero__actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero__actions--centered {
|
||||||
|
justify-content: center;
|
||||||
|
margin: 2rem auto 3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero__visual {
|
||||||
|
min-width: 200px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero__visual img {
|
||||||
|
max-width: 200px;
|
||||||
|
width: 100%;
|
||||||
|
filter: drop-shadow(0 25px 45px rgba(0, 0, 0, 0.45));
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero__visual--large img {
|
||||||
|
max-width: 270px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero__auth {
|
||||||
|
max-width: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pill {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.45rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
padding: 0.35rem 0.85rem;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: rgba(255, 255, 255, 0.08);
|
||||||
|
color: var(--muted);
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel {
|
||||||
|
border-radius: 18px;
|
||||||
|
padding: 1.75rem;
|
||||||
|
margin-bottom: 1.75rem;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel--glass {
|
||||||
|
background: var(--bg-glass);
|
||||||
|
box-shadow: 0 20px 38px rgba(2, 0, 8, 0.45);
|
||||||
|
backdrop-filter: blur(18px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel__subtitle {
|
||||||
|
color: var(--muted);
|
||||||
|
margin-top: 0.35rem;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel__header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-bottom: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge {
|
||||||
|
padding: 0.35rem 0.9rem;
|
||||||
|
background: rgba(178, 89, 255, 0.2);
|
||||||
|
color: var(--accent);
|
||||||
|
border-radius: 12px;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
color: var(--muted);
|
||||||
|
margin-bottom: 0.35rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="text"],
|
||||||
|
input[type="file"],
|
||||||
|
select,
|
||||||
|
textarea {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.7rem 0.9rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="file"] {
|
||||||
|
padding: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:focus,
|
||||||
|
textarea:focus,
|
||||||
|
select:focus {
|
||||||
|
outline: 2px solid rgba(178, 89, 255, 0.5);
|
||||||
|
border-color: rgba(178, 89, 255, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-checkbox {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 0.5rem;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-checkbox__input {
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
border: none;
|
||||||
|
border-radius: 999px;
|
||||||
|
padding: 0.65rem 1.55rem;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
background: linear-gradient(120deg, var(--accent), var(--accent-strong));
|
||||||
|
color: #08010f;
|
||||||
|
transition: transform 0.15s ease, box-shadow 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn:hover {
|
||||||
|
transform: translateY(-1px);
|
||||||
|
box-shadow: 0 10px 25px rgba(178, 89, 255, 0.35);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn:disabled {
|
||||||
|
opacity: 0.55;
|
||||||
|
cursor: not-allowed;
|
||||||
|
box-shadow: none;
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn--secondary {
|
||||||
|
background: rgba(255, 255, 255, 0.15);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn--danger {
|
||||||
|
background: linear-gradient(120deg, #ff4d6d, #ff89a5);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn--ghost {
|
||||||
|
background: transparent;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.35);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn--small {
|
||||||
|
padding: 0.4rem 1rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-group {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.75rem;
|
||||||
|
margin-top: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid {
|
||||||
|
display: grid;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid--two {
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
.u-mt-1 {
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-actions {
|
||||||
|
margin-top: 1.25rem;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status {
|
||||||
|
padding: 0.85rem 1.25rem;
|
||||||
|
border-radius: 999px;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
margin: 1rem 0 2rem;
|
||||||
|
max-width: 600px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status--info {
|
||||||
|
background: rgba(178, 89, 255, 0.2);
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status--error {
|
||||||
|
background: rgba(255, 77, 109, 0.15);
|
||||||
|
color: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status--success {
|
||||||
|
background: rgba(89, 255, 167, 0.15);
|
||||||
|
color: var(--success);
|
||||||
|
}
|
||||||
|
|
||||||
|
.list {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list--stack > li {
|
||||||
|
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-item {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.9rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-item__info {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-item__title {
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-item__meta {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-item__actions {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.player-current {
|
||||||
|
background: rgba(0, 0, 0, 0.25);
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 1.2rem;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.player-current--empty {
|
||||||
|
color: var(--muted);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.feature-grid {
|
||||||
|
display: grid;
|
||||||
|
gap: 1rem;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
.feature-grid__card {
|
||||||
|
text-decoration: none;
|
||||||
|
color: inherit;
|
||||||
|
display: block;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 18px;
|
||||||
|
padding: 1.25rem 1.5rem;
|
||||||
|
background: var(--bg-card);
|
||||||
|
transition: transform 0.15s ease, box-shadow 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.feature-grid__card:hover {
|
||||||
|
transform: translateY(-3px);
|
||||||
|
box-shadow: 0 15px 30px rgba(2, 0, 8, 0.45);
|
||||||
|
}
|
||||||
|
|
||||||
|
.feature-grid__card .pill {
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.hero,
|
||||||
|
.hero--home {
|
||||||
|
flex-direction: column;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero__content p {
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero__actions {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel__header {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.btn,
|
||||||
|
input[type="text"],
|
||||||
|
input[type="file"],
|
||||||
|
select,
|
||||||
|
textarea {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-group {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
}
|
||||||
417
public/style/styles.scss
Normal file
417
public/style/styles.scss
Normal file
|
|
@ -0,0 +1,417 @@
|
||||||
|
:root {
|
||||||
|
color-scheme: dark;
|
||||||
|
--bg: #06030d;
|
||||||
|
--bg-card: rgba(22, 14, 36, 0.9);
|
||||||
|
--bg-glass: rgba(42, 25, 66, 0.65);
|
||||||
|
--border: rgba(255, 255, 255, 0.08);
|
||||||
|
--accent: #b259ff;
|
||||||
|
--accent-strong: #d66bff;
|
||||||
|
--muted: #cbc4d5;
|
||||||
|
--muted-dark: #8c7ea7;
|
||||||
|
--danger: #ff4d6d;
|
||||||
|
--success: #59ffa7;
|
||||||
|
--gradient: radial-gradient(circle at 20% 20%, #2d1a49, transparent 45%),
|
||||||
|
radial-gradient(circle at 80% 0%, #551e8c, transparent 40%),
|
||||||
|
radial-gradient(circle at 50% 80%, #150b28, transparent 30%);
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
min-height: 100vh;
|
||||||
|
font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
|
||||||
|
background: var(--gradient), #050109;
|
||||||
|
color: #f7f1ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0 1.5rem 4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3,
|
||||||
|
h4 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text {
|
||||||
|
&--muted {
|
||||||
|
color: var(--muted);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 2rem;
|
||||||
|
padding: 3rem 1.5rem;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
|
||||||
|
&--home {
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
text-align: left;
|
||||||
|
gap: 2.75rem;
|
||||||
|
|
||||||
|
.hero__visual img {
|
||||||
|
max-width: 320px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 280px;
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 2.2rem;
|
||||||
|
line-height: 1.1;
|
||||||
|
margin-top: 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 1.05rem;
|
||||||
|
max-width: 500px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
|
||||||
|
&--centered {
|
||||||
|
justify-content: center;
|
||||||
|
margin: 2rem auto 3rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__visual {
|
||||||
|
min-width: 200px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
img {
|
||||||
|
max-width: 200px;
|
||||||
|
width: 100%;
|
||||||
|
filter: drop-shadow(0 25px 45px rgba(0, 0, 0, 0.45));
|
||||||
|
}
|
||||||
|
|
||||||
|
&--large img {
|
||||||
|
max-width: 270px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__auth {
|
||||||
|
max-width: 300px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.pill {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.45rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
padding: 0.35rem 0.85rem;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: rgba(255, 255, 255, 0.08);
|
||||||
|
color: var(--muted);
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel {
|
||||||
|
border-radius: 18px;
|
||||||
|
padding: 1.75rem;
|
||||||
|
margin-bottom: 1.75rem;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
|
||||||
|
&--glass {
|
||||||
|
background: var(--bg-glass);
|
||||||
|
box-shadow: 0 20px 38px rgba(2, 0, 8, 0.45);
|
||||||
|
backdrop-filter: blur(18px);
|
||||||
|
}
|
||||||
|
|
||||||
|
&__subtitle {
|
||||||
|
color: var(--muted);
|
||||||
|
margin-top: 0.35rem;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-bottom: 1.25rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge {
|
||||||
|
padding: 0.35rem 0.9rem;
|
||||||
|
background: rgba(178, 89, 255, 0.2);
|
||||||
|
color: var(--accent);
|
||||||
|
border-radius: 12px;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
color: var(--muted);
|
||||||
|
margin-bottom: 0.35rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="text"],
|
||||||
|
input[type="file"],
|
||||||
|
select,
|
||||||
|
textarea {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.7rem 0.9rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="file"] {
|
||||||
|
padding: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:focus,
|
||||||
|
textarea:focus,
|
||||||
|
select:focus {
|
||||||
|
outline: 2px solid rgba(178, 89, 255, 0.5);
|
||||||
|
border-color: rgba(178, 89, 255, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-checkbox {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 0.5rem;
|
||||||
|
color: var(--muted);
|
||||||
|
|
||||||
|
&__input {
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
border: none;
|
||||||
|
border-radius: 999px;
|
||||||
|
padding: 0.65rem 1.55rem;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
background: linear-gradient(120deg, var(--accent), var(--accent-strong));
|
||||||
|
color: #08010f;
|
||||||
|
transition: transform 0.15s ease, box-shadow 0.15s ease;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
transform: translateY(-1px);
|
||||||
|
box-shadow: 0 10px 25px rgba(178, 89, 255, 0.35);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
opacity: 0.55;
|
||||||
|
cursor: not-allowed;
|
||||||
|
box-shadow: none;
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--secondary {
|
||||||
|
background: rgba(255, 255, 255, 0.15);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--danger {
|
||||||
|
background: linear-gradient(120deg, #ff4d6d, #ff89a5);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--ghost {
|
||||||
|
background: transparent;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.35);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--small {
|
||||||
|
padding: 0.4rem 1rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-group {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.75rem;
|
||||||
|
margin-top: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid {
|
||||||
|
display: grid;
|
||||||
|
gap: 1rem;
|
||||||
|
|
||||||
|
&--two {
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.u-mt-1 {
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-actions {
|
||||||
|
margin-top: 1.25rem;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status {
|
||||||
|
padding: 0.85rem 1.25rem;
|
||||||
|
border-radius: 999px;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
margin: 1rem 0 2rem;
|
||||||
|
max-width: 600px;
|
||||||
|
|
||||||
|
&--info {
|
||||||
|
background: rgba(178, 89, 255, 0.2);
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
&--error {
|
||||||
|
background: rgba(255, 77, 109, 0.15);
|
||||||
|
color: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
&--success {
|
||||||
|
background: rgba(89, 255, 167, 0.15);
|
||||||
|
color: var(--success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.list {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
&--stack > li {
|
||||||
|
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-item {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.9rem 0;
|
||||||
|
|
||||||
|
&__info {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__title {
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__meta {
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__actions {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.4rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.player-current {
|
||||||
|
background: rgba(0, 0, 0, 0.25);
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 1.2rem;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||||
|
|
||||||
|
&--empty {
|
||||||
|
color: var(--muted);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.feature-grid {
|
||||||
|
display: grid;
|
||||||
|
gap: 1rem;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
||||||
|
|
||||||
|
&__card {
|
||||||
|
text-decoration: none;
|
||||||
|
color: inherit;
|
||||||
|
display: block;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 18px;
|
||||||
|
padding: 1.25rem 1.5rem;
|
||||||
|
background: var(--bg-card);
|
||||||
|
transition: transform 0.15s ease, box-shadow 0.15s ease;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
transform: translateY(-3px);
|
||||||
|
box-shadow: 0 15px 30px rgba(2, 0, 8, 0.45);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pill {
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.hero,
|
||||||
|
.hero--home {
|
||||||
|
flex-direction: column;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero__content p {
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero__actions {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel__header {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.btn,
|
||||||
|
input[type="text"],
|
||||||
|
input[type="file"],
|
||||||
|
select,
|
||||||
|
textarea {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-group {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
}
|
||||||
71
src/commands/game/dice.js
Normal file
71
src/commands/game/dice.js
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
import { SlashCommandBuilder, subtext } from "discord.js";
|
||||||
|
import { setTimeout } from "node:timers/promises";
|
||||||
|
import { getRandomInt } from "../../features/utilities.js";
|
||||||
|
|
||||||
|
const command = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("dice")
|
||||||
|
.setDescription("Lance un ou plusieurs dés")
|
||||||
|
.addIntegerOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("number")
|
||||||
|
.setDescription("Nombre de dés a lancer")
|
||||||
|
.setRequired(true)
|
||||||
|
)
|
||||||
|
.addIntegerOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("faces")
|
||||||
|
.setDescription("Nombre de faces sur le dé")
|
||||||
|
.setRequired(true)
|
||||||
|
),
|
||||||
|
async execute(interaction) {
|
||||||
|
const number = interaction.options.getInteger("number");
|
||||||
|
const faces = interaction.options.getInteger("faces");
|
||||||
|
var sum = 0;
|
||||||
|
var message = "Alors du coup... 🥁\n";
|
||||||
|
var tails = 0;
|
||||||
|
var heads = 0;
|
||||||
|
|
||||||
|
if (faces === 1 || faces === 0) {
|
||||||
|
await interaction.reply({
|
||||||
|
content: "Ouais ouais, bien sur. Allez, bisous !",
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (faces === 2) {
|
||||||
|
message = message + subtext(`Pile = 1 et Face = 2\n`);
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.reply(message);
|
||||||
|
|
||||||
|
for (let i = 0; i < number; i++) {
|
||||||
|
await setTimeout(1_500);
|
||||||
|
let random = getRandomInt(faces) + 1;
|
||||||
|
random === 1 ? tails++ : heads++;
|
||||||
|
sum = sum + random;
|
||||||
|
|
||||||
|
message = message + `[ ${random} ] ${i === number - 1 ? "\n" : " "}`;
|
||||||
|
interaction.editReply(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (number > 1 && faces > 2) {
|
||||||
|
await setTimeout(1_000);
|
||||||
|
message = message + subtext(`Soit au total : ${sum}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (number > 1 && faces === 2) {
|
||||||
|
await setTimeout(1_000);
|
||||||
|
message =
|
||||||
|
message +
|
||||||
|
subtext(
|
||||||
|
`Soit au total : ${sum}, ou bien ${tails} piles et ${heads} faces \n`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interaction.editReply(message);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export { command };
|
||||||
44
src/commands/game/maketeam.js
Normal file
44
src/commands/game/maketeam.js
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
|
|
||||||
|
const command = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("maketeam")
|
||||||
|
.setDescription("Crée des equipes au hasard")
|
||||||
|
.addIntegerOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("number")
|
||||||
|
.setDescription("Nombre d'équipe")
|
||||||
|
.setRequired(true)
|
||||||
|
)
|
||||||
|
.addStringOption((option) =>
|
||||||
|
option
|
||||||
|
.setName("players")
|
||||||
|
.setDescription("Liste des joueurs, séparés par un espace")
|
||||||
|
.setRequired(true)
|
||||||
|
),
|
||||||
|
async execute(interaction) {
|
||||||
|
const teamNumber = interaction.options.getInteger("number");
|
||||||
|
const players = interaction.options.getString("players");
|
||||||
|
const playersArray = players.split(" ");
|
||||||
|
|
||||||
|
const teams = Array.from({ length: teamNumber }, () => []);
|
||||||
|
const shuffledPlayers = [...playersArray].sort(() => Math.random() - 0.5);
|
||||||
|
|
||||||
|
shuffledPlayers.forEach((player, index) => {
|
||||||
|
const teamIndex = index % teamNumber;
|
||||||
|
teams[teamIndex].push(player);
|
||||||
|
});
|
||||||
|
|
||||||
|
let message = "";
|
||||||
|
let teamList = "";
|
||||||
|
|
||||||
|
teams.forEach((team, index) => {
|
||||||
|
teamList = `${teamList}\n${index + 1}. ${team.join(", ")}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
message = `Yop ! Voici les équipes proposés :\n${teamList}`;
|
||||||
|
await interaction.reply(message);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export { command };
|
||||||
31
src/commands/utility/deletemsgs.js
Normal file
31
src/commands/utility/deletemsgs.js
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
|
|
||||||
|
const command = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("deletemsgs")
|
||||||
|
.setDescription("Supprime tous les messages, sauf ceux épinglés"),
|
||||||
|
async execute(interaction) {
|
||||||
|
let textChannel = interaction.client.channels.cache.get(
|
||||||
|
interaction.channelId
|
||||||
|
);
|
||||||
|
|
||||||
|
textChannel.messages
|
||||||
|
.fetch({ limit: 100 })
|
||||||
|
.then((fetched) => {
|
||||||
|
const notPinned = fetched.filter((fetchedMsg) => !fetchedMsg.pinned);
|
||||||
|
textChannel.bulkDelete(notPinned, true);
|
||||||
|
console.log(
|
||||||
|
`[${new Date().toLocaleString()}] Command : Delete Messages used`
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
|
||||||
|
interaction.reply("Et voila, c'est tout propre ! 🐱").then(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
interaction.deleteReply();
|
||||||
|
}, 7000);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export { command };
|
||||||
27
src/commands/utility/listcommand.js
Normal file
27
src/commands/utility/listcommand.js
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
|
|
||||||
|
const command = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("listcommand")
|
||||||
|
.setDescription("Affiche la liste des commandes disponibles"),
|
||||||
|
async execute(interaction) {
|
||||||
|
let message = `Voila la liste des commandes que tu peux utiliser :
|
||||||
|
__Categorie Utililaires__ :
|
||||||
|
\`/deletemsgs\`: Supprime les 100 derniers messages non épinglés
|
||||||
|
|
||||||
|
__Categorie Vocal__ :
|
||||||
|
\`/muteall\`: Rends tout le monde muet
|
||||||
|
\`/unmuteall\`: Rends la parole à tout le monde
|
||||||
|
\`/deafall\`: Rends tout le monde sourd
|
||||||
|
\`/undeafall\`: Rends l'ouïe à tout le monde
|
||||||
|
|
||||||
|
__Categorie Jeux__ :
|
||||||
|
\`/dice\`: Lance un ou plusieurs dés avec un nombre de faces choisi
|
||||||
|
\`/maketeam\`: Crée un certain nombre d'équipes en renseignant des joueurs (séparés par un espace)
|
||||||
|
`;
|
||||||
|
|
||||||
|
await interaction.reply({ content: message, ephemeral: true });
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export { command };
|
||||||
13
src/commands/utility/ping.js
Normal file
13
src/commands/utility/ping.js
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
|
|
||||||
|
const command = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("ping")
|
||||||
|
.setDescription("Reponds avec Pong"),
|
||||||
|
async execute(interaction) {
|
||||||
|
console.log(interaction);
|
||||||
|
await interaction.reply({ content: "Euh... Pong ! 🐱", ephemeral: true });
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export { command };
|
||||||
14
src/commands/vocal/deafall.js
Normal file
14
src/commands/vocal/deafall.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
|
import { changeVoiceStatus } from "../../features/utilities.js";
|
||||||
|
|
||||||
|
const command = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("deafall")
|
||||||
|
.setDescription("Deaf tout le monde dans le lounge"),
|
||||||
|
async execute(interaction) {
|
||||||
|
changeVoiceStatus(interaction.client, "deaf", "all");
|
||||||
|
await interaction.reply("On n'entends plus rien ! 🐱");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export { command };
|
||||||
14
src/commands/vocal/muteall.js
Normal file
14
src/commands/vocal/muteall.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
|
import { changeVoiceStatus } from "../../features/utilities.js";
|
||||||
|
|
||||||
|
const command = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("muteall")
|
||||||
|
.setDescription("Mute tout le monde dans le lounge"),
|
||||||
|
async execute(interaction) {
|
||||||
|
changeVoiceStatus(interaction.client, "mute", "all");
|
||||||
|
await interaction.reply("Voila, tout le monde est mioute ! 🐱");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export { command };
|
||||||
14
src/commands/vocal/undeafall.js
Normal file
14
src/commands/vocal/undeafall.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
|
import { changeVoiceStatus } from "../../features/utilities.js";
|
||||||
|
|
||||||
|
const command = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("undeafall")
|
||||||
|
.setDescription("Undeaf tout le monde dans le lounge"),
|
||||||
|
async execute(interaction) {
|
||||||
|
changeVoiceStatus(interaction.client, "undeaf", "all");
|
||||||
|
await interaction.reply("Voila, les oreilles sont réparées ! 🐱");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export { command };
|
||||||
14
src/commands/vocal/unmuteall.js
Normal file
14
src/commands/vocal/unmuteall.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { SlashCommandBuilder } from "discord.js";
|
||||||
|
import { changeVoiceStatus } from "../../features/utilities.js";
|
||||||
|
|
||||||
|
const command = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("unmuteall")
|
||||||
|
.setDescription("Unmute tout le monde dans le lounge"),
|
||||||
|
async execute(interaction) {
|
||||||
|
changeVoiceStatus(interaction.client, "unmute", "all");
|
||||||
|
await interaction.reply("Et.... unmioute ! 🐱");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export { command };
|
||||||
49
src/config.js
Normal file
49
src/config.js
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
const requiredVariables = [
|
||||||
|
"NODE_ENV",
|
||||||
|
"LOCATION",
|
||||||
|
"BOT_OWNER",
|
||||||
|
"DISCORD_GUILD_ID",
|
||||||
|
"SHINUWA_USER_ID",
|
||||||
|
"INVITE_LINK",
|
||||||
|
"WEB_SERVER_PORT",
|
||||||
|
"WEB_API_KEY",
|
||||||
|
"DISCORD_APPLICATION_ID",
|
||||||
|
"DISCORD_TOKEN",
|
||||||
|
"VOICE_CHANNEL_ID",
|
||||||
|
"TEXT_CHANNEL_ID",
|
||||||
|
"GAME_SERVERS_MESSAGE_ID",
|
||||||
|
];
|
||||||
|
|
||||||
|
const missingVariables = requiredVariables.filter(
|
||||||
|
(name) => !process.env[name]?.trim()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (missingVariables.length > 0) {
|
||||||
|
throw new Error(
|
||||||
|
`Variables d'environnement manquantes : ${missingVariables.join(", ")}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const webServerPort = Number(process.env.WEB_SERVER_PORT);
|
||||||
|
|
||||||
|
if (!Number.isInteger(webServerPort) || webServerPort <= 0) {
|
||||||
|
throw new Error("WEB_SERVER_PORT doit être un entier positif");
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = Object.freeze({
|
||||||
|
environnement: process.env.NODE_ENV,
|
||||||
|
location: process.env.LOCATION,
|
||||||
|
botOwner: process.env.BOT_OWNER,
|
||||||
|
discordGuildId: process.env.DISCORD_GUILD_ID,
|
||||||
|
shinuwaUserId: process.env.SHINUWA_USER_ID,
|
||||||
|
inviteLink: process.env.INVITE_LINK,
|
||||||
|
webServerPort,
|
||||||
|
webApiKey: process.env.WEB_API_KEY,
|
||||||
|
applicationId: process.env.DISCORD_APPLICATION_ID,
|
||||||
|
token: process.env.DISCORD_TOKEN,
|
||||||
|
voiceChannelId: process.env.VOICE_CHANNEL_ID,
|
||||||
|
textChannelId: process.env.TEXT_CHANNEL_ID,
|
||||||
|
gameServersMessageId: process.env.GAME_SERVERS_MESSAGE_ID,
|
||||||
|
});
|
||||||
|
|
||||||
|
export { config };
|
||||||
38
src/events/interactionCreate.js
Normal file
38
src/events/interactionCreate.js
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
import { Events } from "discord.js";
|
||||||
|
|
||||||
|
const event = {
|
||||||
|
name: Events.InteractionCreate,
|
||||||
|
async execute(interaction) {
|
||||||
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
|
const command = interaction.client.commands.get(
|
||||||
|
interaction.commandName
|
||||||
|
).command;
|
||||||
|
|
||||||
|
if (!command) {
|
||||||
|
console.error(
|
||||||
|
`No command matching ${interaction.commandName} was found.`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await command.execute(interaction);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
if (interaction.replied || interaction.deferred) {
|
||||||
|
await interaction.followUp({
|
||||||
|
content: "There was an error while executing this command!",
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await interaction.reply({
|
||||||
|
content: "There was an error while executing this command!",
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export { event };
|
||||||
26
src/events/ready.js
Normal file
26
src/events/ready.js
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
import { Events } from "discord.js";
|
||||||
|
import { config } from "../config.js";
|
||||||
|
import { showGameServers } from "../features/showGameServers.js";
|
||||||
|
import { sendMessage } from "../features/sendMessage.js";
|
||||||
|
import { isConnectedToVoiceChannel } from "../features/utilities.js";
|
||||||
|
|
||||||
|
const event = {
|
||||||
|
name: Events.ClientReady,
|
||||||
|
once: true,
|
||||||
|
execute(client) {
|
||||||
|
console.log(
|
||||||
|
`[${new Date().toLocaleString()}] Logged in as ${client.user.tag}`
|
||||||
|
);
|
||||||
|
|
||||||
|
showGameServers(
|
||||||
|
client,
|
||||||
|
config.textChannelId,
|
||||||
|
config.gameServersMessageId,
|
||||||
|
config.shinuwaUserId
|
||||||
|
);
|
||||||
|
|
||||||
|
//sendMessage(client, 'jukebox')
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export { event };
|
||||||
59
src/features/sendMessage.js
Normal file
59
src/features/sendMessage.js
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
import {
|
||||||
|
ActionRowBuilder,
|
||||||
|
ButtonBuilder,
|
||||||
|
ButtonStyle,
|
||||||
|
channelMention,
|
||||||
|
codeBlock,
|
||||||
|
} from "discord.js";
|
||||||
|
import { config } from "../config.js";
|
||||||
|
|
||||||
|
function sendMessage(client, type) {
|
||||||
|
const channel = client.channels.cache.get(config.textChannelId);
|
||||||
|
var message = { content: "Message réservé" };
|
||||||
|
|
||||||
|
if (type && type === "invitation") {
|
||||||
|
message.content = inviteMessage();
|
||||||
|
} else if (type && type === "jukebox") {
|
||||||
|
message = jukeboxMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
channel.send(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
function inviteMessage() {
|
||||||
|
var message =
|
||||||
|
"Pour inviter quelqu'un, il faut utiliser cette invitation temporaire !\n";
|
||||||
|
|
||||||
|
message = message + codeBlock(config.inviteLink);
|
||||||
|
|
||||||
|
message =
|
||||||
|
message +
|
||||||
|
"*Pour une invitation permanente, il suffit d'attribuer le role*" +
|
||||||
|
" ***Hangaround*** " +
|
||||||
|
"*à la personne concernée.*\n\n" +
|
||||||
|
"";
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jukeboxMessage() {
|
||||||
|
const description =
|
||||||
|
"Yo ! 😺\n\n" +
|
||||||
|
`J'ai installé un jukebox dans ${channelMention(config.voiceChannelId)} !\n` +
|
||||||
|
"Tu peux le contrôler facilement via une petite interface ! 😽.\n\n" +
|
||||||
|
"Clique sur le bouton ci-dessous pour ouvrir le tableau de bord.\n\n";
|
||||||
|
|
||||||
|
const buttonRow = new ActionRowBuilder().addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setLabel("Ouvrir le Jukebox 🎵")
|
||||||
|
.setStyle(ButtonStyle.Link)
|
||||||
|
.setURL("https://palico-bot.shinuwa.fr/jukebox/")
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
content: description,
|
||||||
|
components: [buttonRow],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export { sendMessage, inviteMessage, jukeboxMessage };
|
||||||
64
src/features/showGameServers.js
Normal file
64
src/features/showGameServers.js
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
import { config } from "../config.js";
|
||||||
|
import { getJSONData } from "./utilities.js";
|
||||||
|
|
||||||
|
var currentStatus = [];
|
||||||
|
|
||||||
|
function checkServersStatus(client) {
|
||||||
|
const data = getJSONData("src/static/gameservers-list.json");
|
||||||
|
const newStatus = data.servers.map((server) => server.active);
|
||||||
|
|
||||||
|
if (JSON.stringify(newStatus) === JSON.stringify(currentStatus)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateMessage(client, data);
|
||||||
|
currentStatus = newStatus;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateMessage(client, data) {
|
||||||
|
var newMessage = `Hello 😺 ! Voila les serveurs de jeux qu'on a chez nous :\n\n`;
|
||||||
|
|
||||||
|
data.servers.forEach((server) => {
|
||||||
|
newMessage =
|
||||||
|
newMessage +
|
||||||
|
"```ansi\n" +
|
||||||
|
`${server.game} : ` +
|
||||||
|
`${server.active ? "[2;32mOnline[0m" : "[2;31mOffline[0m"}\n` +
|
||||||
|
`${server.address}\n` +
|
||||||
|
"```";
|
||||||
|
});
|
||||||
|
|
||||||
|
newMessage =
|
||||||
|
newMessage +
|
||||||
|
"\nAh d'ailleurs ! Si le serveur est sécurisé, le mot de passe c'est surement **0117**.";
|
||||||
|
newMessage =
|
||||||
|
newMessage +
|
||||||
|
`\nPour mettre en ligne un serveur, faut voir avec <@${config.shinuwaUserId}> , c'est lui qui gère ca !\n`;
|
||||||
|
|
||||||
|
const channel = client.channels.cache.get(config.textChannelId);
|
||||||
|
|
||||||
|
channel.messages
|
||||||
|
.fetch(config.gameServersMessageId)
|
||||||
|
.then((message) => {
|
||||||
|
message
|
||||||
|
.edit(newMessage)
|
||||||
|
.then(
|
||||||
|
console.log(
|
||||||
|
`[${new Date().toLocaleString()}] showGameServers: Game servers message updated`
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.catch(console.error);
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showGameServers(client) {
|
||||||
|
const data = getJSONData("src/static/gameservers-list.json");
|
||||||
|
currentStatus = data.servers.map((server) => server.active);
|
||||||
|
|
||||||
|
updateMessage(client, data);
|
||||||
|
setInterval(checkServersStatus, 120000, client);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { showGameServers };
|
||||||
74
src/features/utilities.js
Normal file
74
src/features/utilities.js
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
import fs from "fs";
|
||||||
|
import { config } from "../config.js";
|
||||||
|
|
||||||
|
function changeVoiceStatus(client, status, members) {
|
||||||
|
const changeStatus = (type, value, members) => {
|
||||||
|
switch (type) {
|
||||||
|
case "mute":
|
||||||
|
for (let member of members) {
|
||||||
|
member[1].voice.setMute(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "deaf":
|
||||||
|
for (let member of members) {
|
||||||
|
member[1].voice.setDeaf(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var voiceChannel = client.channels.cache.get(config.voiceChannelId);
|
||||||
|
var connectedMembers = voiceChannel.members;
|
||||||
|
|
||||||
|
if (members == "all") {
|
||||||
|
members = connectedMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (status) {
|
||||||
|
case "mute":
|
||||||
|
changeStatus("mute", true, members);
|
||||||
|
break;
|
||||||
|
case "unmute":
|
||||||
|
changeStatus("mute", false, members);
|
||||||
|
break;
|
||||||
|
case "deaf":
|
||||||
|
changeStatus("deaf", true, members);
|
||||||
|
break;
|
||||||
|
case "undeaf":
|
||||||
|
changeStatus("deaf", false, members);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getJSONData(file) {
|
||||||
|
const jsonFile = fs.readFileSync(file);
|
||||||
|
const data = JSON.parse(jsonFile);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRandomInt(max) {
|
||||||
|
return Math.floor(Math.random() * max);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isConnectedToVoiceChannel(client, userId) {
|
||||||
|
var voiceChannel = client.channels.cache.get(config.voiceChannelId);
|
||||||
|
var connectedMembers = voiceChannel.members;
|
||||||
|
|
||||||
|
var selectedMember = connectedMembers.filter(
|
||||||
|
(member) => member.user.id === userId
|
||||||
|
);
|
||||||
|
|
||||||
|
if (selectedMember.size === 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
changeVoiceStatus,
|
||||||
|
getJSONData,
|
||||||
|
getRandomInt,
|
||||||
|
isConnectedToVoiceChannel,
|
||||||
|
};
|
||||||
370
src/music/queue.js
Normal file
370
src/music/queue.js
Normal file
|
|
@ -0,0 +1,370 @@
|
||||||
|
import fs from "fs";
|
||||||
|
import { EventEmitter } from "events";
|
||||||
|
import {
|
||||||
|
AudioPlayerStatus,
|
||||||
|
NoSubscriberBehavior,
|
||||||
|
VoiceConnectionStatus,
|
||||||
|
createAudioPlayer,
|
||||||
|
createAudioResource,
|
||||||
|
entersState,
|
||||||
|
joinVoiceChannel,
|
||||||
|
} from "@discordjs/voice";
|
||||||
|
import { Events } from "discord.js";
|
||||||
|
import { config } from "../config.js";
|
||||||
|
import {
|
||||||
|
deleteTrackFile,
|
||||||
|
handleTrackCompletion,
|
||||||
|
} from "../web/storage/storageManager.js";
|
||||||
|
|
||||||
|
const AUTO_DISCONNECT_DELAY = 5 * 60 * 1000;
|
||||||
|
|
||||||
|
class MusicQueue extends EventEmitter {
|
||||||
|
constructor(client) {
|
||||||
|
super();
|
||||||
|
this.client = client;
|
||||||
|
this.queue = [];
|
||||||
|
this.currentTrack = null;
|
||||||
|
this.connection = null;
|
||||||
|
this.playbackStatus = AudioPlayerStatus.Idle;
|
||||||
|
this.idleDisconnectTimeout = null;
|
||||||
|
this.aloneDisconnectTimeout = null;
|
||||||
|
this.suspendedForAlone = false;
|
||||||
|
this.audioPlayer = createAudioPlayer({
|
||||||
|
behaviors: {
|
||||||
|
noSubscriber: NoSubscriberBehavior.Play,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
this.voiceStateListener = (oldState, newState) => {
|
||||||
|
if (
|
||||||
|
oldState.channelId === config.voiceChannelId ||
|
||||||
|
newState.channelId === config.voiceChannelId
|
||||||
|
) {
|
||||||
|
this.evaluateAloneStatus();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.client.on(Events.VoiceStateUpdate, this.voiceStateListener);
|
||||||
|
|
||||||
|
this.audioPlayer.on(AudioPlayerStatus.Idle, () => {
|
||||||
|
if (this.currentTrack) {
|
||||||
|
handleTrackCompletion(this.currentTrack);
|
||||||
|
}
|
||||||
|
this.currentTrack = null;
|
||||||
|
this.playNext();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.audioPlayer.on("error", (error) => {
|
||||||
|
console.error("Audio player encountered an error", error);
|
||||||
|
this.currentTrack = null;
|
||||||
|
this.playNext();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.audioPlayer.on("stateChange", (oldState, newState) => {
|
||||||
|
this.playbackStatus = newState.status;
|
||||||
|
this.emit("queueUpdate", this.snapshot());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshot() {
|
||||||
|
return {
|
||||||
|
current: this.currentTrack,
|
||||||
|
upcoming: this.queue,
|
||||||
|
status: this.playbackStatus,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async ensureConnection() {
|
||||||
|
if (
|
||||||
|
this.connection &&
|
||||||
|
this.connection.joinConfig.channelId === config.voiceChannelId
|
||||||
|
) {
|
||||||
|
return this.connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
let channel = this.client.channels.cache.get(config.voiceChannelId);
|
||||||
|
|
||||||
|
if (!channel) {
|
||||||
|
try {
|
||||||
|
channel = await this.client.channels.fetch(config.voiceChannelId);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Unable to fetch voice channel", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!channel) {
|
||||||
|
throw new Error("Voice channel configured for music playback was not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
const connection = joinVoiceChannel({
|
||||||
|
channelId: channel.id,
|
||||||
|
guildId: channel.guild.id,
|
||||||
|
adapterCreator: channel.guild.voiceAdapterCreator,
|
||||||
|
selfDeaf: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.connection = connection;
|
||||||
|
connection.subscribe(this.audioPlayer);
|
||||||
|
await entersState(connection, VoiceConnectionStatus.Ready, 30_000);
|
||||||
|
this.evaluateAloneStatus();
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
enqueue(track) {
|
||||||
|
this.queue.push(track);
|
||||||
|
this.cancelIdleDisconnect();
|
||||||
|
this.emit("queueUpdate", this.snapshot());
|
||||||
|
if (!this.currentTrack) {
|
||||||
|
return this.playNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
return track;
|
||||||
|
}
|
||||||
|
|
||||||
|
async playNext() {
|
||||||
|
if (this.suspendedForAlone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.queue.length === 0) {
|
||||||
|
this.scheduleIdleDisconnect();
|
||||||
|
this.emit("queueUpdate", this.snapshot());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.cancelIdleDisconnect();
|
||||||
|
|
||||||
|
const nextTrack = this.queue.shift();
|
||||||
|
this.emit("queueUpdate", this.snapshot());
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.ensureConnection();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Unable to connect to the configured voice channel", error);
|
||||||
|
deleteTrackFile(nextTrack);
|
||||||
|
this.currentTrack = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const stream = fs.createReadStream(nextTrack.path);
|
||||||
|
const resource = createAudioResource(stream, {
|
||||||
|
inlineVolume: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.currentTrack = nextTrack;
|
||||||
|
this.audioPlayer.play(resource);
|
||||||
|
this.emit("trackStart", nextTrack);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Unable to play track", error);
|
||||||
|
deleteTrackFile(nextTrack);
|
||||||
|
this.currentTrack = null;
|
||||||
|
return this.playNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async remove(trackId) {
|
||||||
|
const index = this.queue.findIndex((track) => track.id === trackId);
|
||||||
|
if (index === -1) {
|
||||||
|
if (this.currentTrack && this.currentTrack.id === trackId) {
|
||||||
|
this.skip();
|
||||||
|
return this.currentTrack;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [removed] = this.queue.splice(index, 1);
|
||||||
|
deleteTrackFile(removed);
|
||||||
|
this.emit("queueUpdate", this.snapshot());
|
||||||
|
if (this.queue.length === 0 && !this.currentTrack) {
|
||||||
|
this.scheduleIdleDisconnect();
|
||||||
|
}
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
move(trackId, newPosition) {
|
||||||
|
const index = this.queue.findIndex((track) => track.id === trackId);
|
||||||
|
if (index === -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [track] = this.queue.splice(index, 1);
|
||||||
|
const boundedPosition = Math.max(0, Math.min(newPosition, this.queue.length));
|
||||||
|
this.queue.splice(boundedPosition, 0, track);
|
||||||
|
this.emit("queueUpdate", this.snapshot());
|
||||||
|
return this.snapshot();
|
||||||
|
}
|
||||||
|
|
||||||
|
skip() {
|
||||||
|
this.audioPlayer.stop(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
this.queue.forEach((track) => deleteTrackFile(track));
|
||||||
|
this.queue = [];
|
||||||
|
this.audioPlayer.stop(true);
|
||||||
|
this.emit("queueUpdate", this.snapshot());
|
||||||
|
}
|
||||||
|
|
||||||
|
pause() {
|
||||||
|
this.audioPlayer.pause(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
resume() {
|
||||||
|
this.audioPlayer.unpause();
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
this.suspendedForAlone = false;
|
||||||
|
this.cancelIdleDisconnect();
|
||||||
|
if (!this.currentTrack) {
|
||||||
|
return this.playNext();
|
||||||
|
}
|
||||||
|
return this.currentTrack;
|
||||||
|
}
|
||||||
|
|
||||||
|
removeByLibraryId(libraryTrackId) {
|
||||||
|
if (!libraryTrackId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const removed = this.queue.filter(
|
||||||
|
(track) => track.libraryTrackId === libraryTrackId
|
||||||
|
);
|
||||||
|
|
||||||
|
this.queue = this.queue.filter(
|
||||||
|
(track) => track.libraryTrackId !== libraryTrackId
|
||||||
|
);
|
||||||
|
|
||||||
|
removed.forEach((track) => deleteTrackFile(track));
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.currentTrack &&
|
||||||
|
this.currentTrack.libraryTrackId === libraryTrackId
|
||||||
|
) {
|
||||||
|
this.skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (removed.length > 0) {
|
||||||
|
this.emit("queueUpdate", this.snapshot());
|
||||||
|
}
|
||||||
|
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
destroyConnection(reason, { suspend = false } = {}) {
|
||||||
|
if (!this.connection && this.playbackStatus === AudioPlayerStatus.Idle) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (suspend) {
|
||||||
|
this.suspendedForAlone = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cancelIdleDisconnect();
|
||||||
|
this.cancelAloneDisconnect();
|
||||||
|
|
||||||
|
if (this.connection) {
|
||||||
|
try {
|
||||||
|
this.connection.destroy();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to destroy voice connection", error);
|
||||||
|
}
|
||||||
|
this.connection = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.audioPlayer.stop(true);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to stop audio player", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentTrack = null;
|
||||||
|
this.emit("queueUpdate", this.snapshot());
|
||||||
|
console.log(
|
||||||
|
`[${new Date().toLocaleString()}] MusicQueue disconnected (${reason})`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
scheduleIdleDisconnect() {
|
||||||
|
if (
|
||||||
|
this.idleDisconnectTimeout ||
|
||||||
|
this.queue.length > 0 ||
|
||||||
|
this.currentTrack ||
|
||||||
|
!this.connection
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.idleDisconnectTimeout = setTimeout(() => {
|
||||||
|
this.idleDisconnectTimeout = null;
|
||||||
|
if (!this.currentTrack && this.queue.length === 0 && this.connection) {
|
||||||
|
this.destroyConnection("idle timeout");
|
||||||
|
}
|
||||||
|
}, AUTO_DISCONNECT_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelIdleDisconnect() {
|
||||||
|
if (this.idleDisconnectTimeout) {
|
||||||
|
clearTimeout(this.idleDisconnectTimeout);
|
||||||
|
this.idleDisconnectTimeout = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scheduleAloneDisconnect() {
|
||||||
|
if (this.aloneDisconnectTimeout || !this.connection) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.aloneDisconnectTimeout = setTimeout(() => {
|
||||||
|
this.aloneDisconnectTimeout = null;
|
||||||
|
if (this.connection && this.isBotAlone()) {
|
||||||
|
this.destroyConnection("alone timeout", { suspend: true });
|
||||||
|
}
|
||||||
|
}, AUTO_DISCONNECT_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelAloneDisconnect() {
|
||||||
|
if (this.aloneDisconnectTimeout) {
|
||||||
|
clearTimeout(this.aloneDisconnectTimeout);
|
||||||
|
this.aloneDisconnectTimeout = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
evaluateAloneStatus() {
|
||||||
|
if (!this.connection) {
|
||||||
|
this.cancelAloneDisconnect();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isBotAlone()) {
|
||||||
|
this.scheduleAloneDisconnect();
|
||||||
|
} else {
|
||||||
|
const wasSuspended = this.suspendedForAlone;
|
||||||
|
this.suspendedForAlone = false;
|
||||||
|
this.cancelAloneDisconnect();
|
||||||
|
if (wasSuspended && !this.currentTrack && this.queue.length > 0) {
|
||||||
|
this.playNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isBotAlone() {
|
||||||
|
const channel = this.client.channels.cache.get(config.voiceChannelId);
|
||||||
|
if (!channel) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const clientId = this.client.user?.id;
|
||||||
|
if (!clientId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!channel.members.has(clientId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const others = channel.members.filter((member) => member.id !== clientId);
|
||||||
|
return others.size === 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { MusicQueue };
|
||||||
18
src/web/middlewares/auth.js
Normal file
18
src/web/middlewares/auth.js
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { config } from "../../config.js";
|
||||||
|
|
||||||
|
function authMiddleware(req, res, next) {
|
||||||
|
if (!config.webApiKey) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
const header = req.headers.authorization || "";
|
||||||
|
const token = header.replace("Bearer ", "");
|
||||||
|
|
||||||
|
if (token === config.webApiKey) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(401).json({ error: "Unauthorized" });
|
||||||
|
}
|
||||||
|
|
||||||
|
export { authMiddleware };
|
||||||
44
src/web/routes/library.js
Normal file
44
src/web/routes/library.js
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { Router } from "express";
|
||||||
|
import {
|
||||||
|
createQueueTrackFromLibrary,
|
||||||
|
deletePermanentTrack,
|
||||||
|
findPermanentTrack,
|
||||||
|
getPermanentLibrary,
|
||||||
|
} from "../storage/storageManager.js";
|
||||||
|
|
||||||
|
function libraryRouter({ queue }) {
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get("/", (req, res) => {
|
||||||
|
res.json({ tracks: getPermanentLibrary() });
|
||||||
|
});
|
||||||
|
|
||||||
|
router.delete("/:libraryId", (req, res) => {
|
||||||
|
const track = deletePermanentTrack(req.params.libraryId);
|
||||||
|
|
||||||
|
if (!track) {
|
||||||
|
return res.status(404).json({ error: "Fichier permanent introuvable" });
|
||||||
|
}
|
||||||
|
|
||||||
|
queue.removeByLibraryId(track.id);
|
||||||
|
res.json({ removed: track });
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post("/:libraryId/enqueue", (req, res) => {
|
||||||
|
const baseTrack = findPermanentTrack(req.params.libraryId);
|
||||||
|
if (!baseTrack) {
|
||||||
|
return res.status(404).json({ error: "Fichier permanent introuvable" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const queueTrack = createQueueTrackFromLibrary(
|
||||||
|
baseTrack,
|
||||||
|
req.body?.requestedBy
|
||||||
|
);
|
||||||
|
queue.enqueue(queueTrack);
|
||||||
|
res.status(201).json({ track: queueTrack });
|
||||||
|
});
|
||||||
|
|
||||||
|
return router;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { libraryRouter };
|
||||||
34
src/web/routes/player.js
Normal file
34
src/web/routes/player.js
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
import { Router } from "express";
|
||||||
|
|
||||||
|
function playerRouter({ queue }) {
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.post("/play", async (req, res) => {
|
||||||
|
await queue.start();
|
||||||
|
res.json(queue.snapshot());
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post("/pause", (req, res) => {
|
||||||
|
queue.pause();
|
||||||
|
res.json(queue.snapshot());
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post("/resume", (req, res) => {
|
||||||
|
queue.resume();
|
||||||
|
res.json(queue.snapshot());
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post("/skip", (req, res) => {
|
||||||
|
queue.skip();
|
||||||
|
res.json(queue.snapshot());
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post("/stop", (req, res) => {
|
||||||
|
queue.stop();
|
||||||
|
res.json(queue.snapshot());
|
||||||
|
});
|
||||||
|
|
||||||
|
return router;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { playerRouter };
|
||||||
56
src/web/routes/queue.js
Normal file
56
src/web/routes/queue.js
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
import { Router } from "express";
|
||||||
|
import { createQueueTrackFromLibrary, findPermanentTrack } from "../storage/storageManager.js";
|
||||||
|
|
||||||
|
function queueRouter({ queue }) {
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get("/", (req, res) => {
|
||||||
|
res.json(queue.snapshot());
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post("/", (req, res) => {
|
||||||
|
const { libraryTrackId, requestedBy } = req.body;
|
||||||
|
|
||||||
|
if (!libraryTrackId) {
|
||||||
|
return res.status(400).json({ error: "libraryTrackId manquant" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const libraryTrack = findPermanentTrack(libraryTrackId);
|
||||||
|
|
||||||
|
if (!libraryTrack) {
|
||||||
|
return res.status(404).json({ error: "Fichier permanent introuvable" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const track = createQueueTrackFromLibrary(libraryTrack, requestedBy);
|
||||||
|
queue.enqueue(track);
|
||||||
|
res.status(201).json({ track });
|
||||||
|
});
|
||||||
|
|
||||||
|
router.delete("/:trackId", async (req, res) => {
|
||||||
|
const removed = await queue.remove(req.params.trackId);
|
||||||
|
if (!removed) {
|
||||||
|
return res.status(404).json({ error: "Piste introuvable" });
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({ removed });
|
||||||
|
});
|
||||||
|
|
||||||
|
router.patch("/:trackId/move", (req, res) => {
|
||||||
|
const position = Number(req.body?.position);
|
||||||
|
if (Number.isNaN(position)) {
|
||||||
|
return res.status(400).json({ error: "position doit être un nombre" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const snapshot = queue.move(req.params.trackId, position);
|
||||||
|
|
||||||
|
if (!snapshot) {
|
||||||
|
return res.status(404).json({ error: "Piste introuvable" });
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json(snapshot);
|
||||||
|
});
|
||||||
|
|
||||||
|
return router;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { queueRouter };
|
||||||
40
src/web/routes/uploads.js
Normal file
40
src/web/routes/uploads.js
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
import { Router } from "express";
|
||||||
|
import multer from "multer";
|
||||||
|
import { TEMP_DIR, registerUploadedFile } from "../storage/storageManager.js";
|
||||||
|
|
||||||
|
const upload = multer({
|
||||||
|
dest: TEMP_DIR,
|
||||||
|
limits: {
|
||||||
|
fileSize: 150 * 1024 * 1024,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
function uploadsRouter({ queue }) {
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.post("/", upload.single("file"), async (req, res, next) => {
|
||||||
|
if (!req.file) {
|
||||||
|
return res.status(400).json({ error: "Aucun fichier reçu" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const permanent = req.body?.permanent === "true";
|
||||||
|
const enqueue = req.body?.enqueue !== "false";
|
||||||
|
const uploader = req.body?.uploader || "web-ui";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const track = registerUploadedFile(req.file, { permanent, uploader });
|
||||||
|
|
||||||
|
if (enqueue) {
|
||||||
|
queue.enqueue(track);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(201).json({ track, enqueued: enqueue });
|
||||||
|
} catch (error) {
|
||||||
|
return next(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return router;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { uploadsRouter };
|
||||||
43
src/web/server.js
Normal file
43
src/web/server.js
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
import express from "express";
|
||||||
|
import path from "path";
|
||||||
|
import { config } from "../config.js";
|
||||||
|
import { authMiddleware } from "./middlewares/auth.js";
|
||||||
|
import { libraryRouter } from "./routes/library.js";
|
||||||
|
import { playerRouter } from "./routes/player.js";
|
||||||
|
import { queueRouter } from "./routes/queue.js";
|
||||||
|
import { uploadsRouter } from "./routes/uploads.js";
|
||||||
|
import { ensureStorageLayout } from "./storage/storageManager.js";
|
||||||
|
|
||||||
|
const PUBLIC_DIR = path.join(process.cwd(), "public");
|
||||||
|
|
||||||
|
function startWebServer(dependencies) {
|
||||||
|
ensureStorageLayout();
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
const apiRouter = express.Router();
|
||||||
|
apiRouter.use(authMiddleware);
|
||||||
|
apiRouter.use("/uploads", uploadsRouter(dependencies));
|
||||||
|
apiRouter.use("/queue", queueRouter(dependencies));
|
||||||
|
apiRouter.use("/library", libraryRouter(dependencies));
|
||||||
|
apiRouter.use("/player", playerRouter(dependencies));
|
||||||
|
|
||||||
|
app.use("/api", apiRouter);
|
||||||
|
app.get(["/jukebox", "/jukebox/"], (_req, res) =>
|
||||||
|
res.sendFile(path.join(PUBLIC_DIR, "jukebox.html"))
|
||||||
|
);
|
||||||
|
app.use(express.static(PUBLIC_DIR));
|
||||||
|
|
||||||
|
const port = Number(process.env.PORT || config.webServerPort || 3000);
|
||||||
|
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.log(
|
||||||
|
`[${new Date().toLocaleString()}] Web control server listening on port ${port}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { startWebServer };
|
||||||
166
src/web/storage/storageManager.js
Normal file
166
src/web/storage/storageManager.js
Normal file
|
|
@ -0,0 +1,166 @@
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
import { v4 as uuid } from "uuid";
|
||||||
|
|
||||||
|
const STORAGE_ROOT = path.join(process.cwd(), "storage");
|
||||||
|
const PERMANENT_DIR = path.join(STORAGE_ROOT, "permanent");
|
||||||
|
const TEMP_DIR = path.join(STORAGE_ROOT, "temp");
|
||||||
|
const LIBRARY_FILE = path.join(STORAGE_ROOT, "library.json");
|
||||||
|
|
||||||
|
function ensureStorageLayout() {
|
||||||
|
if (!fs.existsSync(STORAGE_ROOT)) {
|
||||||
|
fs.mkdirSync(STORAGE_ROOT, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(PERMANENT_DIR)) {
|
||||||
|
fs.mkdirSync(PERMANENT_DIR, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(TEMP_DIR)) {
|
||||||
|
fs.mkdirSync(TEMP_DIR, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(LIBRARY_FILE)) {
|
||||||
|
fs.writeFileSync(LIBRARY_FILE, JSON.stringify([]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function readLibrary() {
|
||||||
|
try {
|
||||||
|
const raw = fs.readFileSync(LIBRARY_FILE, { encoding: "utf8" });
|
||||||
|
return JSON.parse(raw);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to read library file", error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeLibrary(entries) {
|
||||||
|
fs.writeFileSync(LIBRARY_FILE, JSON.stringify(entries, null, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerUploadedFile(file, { permanent, uploader = "unknown" }) {
|
||||||
|
ensureStorageLayout();
|
||||||
|
const createdAt = new Date().toISOString();
|
||||||
|
let finalPath = file.path;
|
||||||
|
let storedName = path.basename(file.path);
|
||||||
|
let permanentEntry = null;
|
||||||
|
|
||||||
|
if (permanent) {
|
||||||
|
const extension = path.extname(file.originalname) || "";
|
||||||
|
storedName = `${uuid()}${extension}`;
|
||||||
|
finalPath = path.join(PERMANENT_DIR, storedName);
|
||||||
|
fs.renameSync(file.path, finalPath);
|
||||||
|
permanentEntry = {
|
||||||
|
id: uuid(),
|
||||||
|
originalName: file.originalname,
|
||||||
|
storedName,
|
||||||
|
path: finalPath,
|
||||||
|
size: file.size,
|
||||||
|
mimetype: file.mimetype,
|
||||||
|
uploader,
|
||||||
|
createdAt,
|
||||||
|
};
|
||||||
|
const library = readLibrary();
|
||||||
|
library.push(permanentEntry);
|
||||||
|
writeLibrary(library);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: uuid(),
|
||||||
|
title: file.originalname,
|
||||||
|
originalName: file.originalname,
|
||||||
|
path: finalPath,
|
||||||
|
storedName,
|
||||||
|
size: file.size,
|
||||||
|
mimetype: file.mimetype,
|
||||||
|
permanent,
|
||||||
|
uploader,
|
||||||
|
libraryTrackId: permanentEntry ? permanentEntry.id : null,
|
||||||
|
createdAt,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPermanentLibrary() {
|
||||||
|
ensureStorageLayout();
|
||||||
|
return readLibrary();
|
||||||
|
}
|
||||||
|
|
||||||
|
function findPermanentTrack(id) {
|
||||||
|
return getPermanentLibrary().find((entry) => entry.id === id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createQueueTrackFromLibrary(libraryTrack, requestedBy = "library") {
|
||||||
|
if (!libraryTrack) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: uuid(),
|
||||||
|
title: libraryTrack.originalName,
|
||||||
|
originalName: libraryTrack.originalName,
|
||||||
|
path: libraryTrack.path,
|
||||||
|
storedName: libraryTrack.storedName,
|
||||||
|
size: libraryTrack.size,
|
||||||
|
mimetype: libraryTrack.mimetype,
|
||||||
|
permanent: true,
|
||||||
|
uploader: requestedBy,
|
||||||
|
libraryTrackId: libraryTrack.id,
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteFileSafe(filePath) {
|
||||||
|
if (!filePath) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.existsSync(filePath) && fs.unlinkSync(filePath);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Failed to delete file ${filePath}`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deletePermanentTrack(id) {
|
||||||
|
const library = getPermanentLibrary();
|
||||||
|
const index = library.findIndex((entry) => entry.id === id);
|
||||||
|
if (index === -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [removed] = library.splice(index, 1);
|
||||||
|
writeLibrary(library);
|
||||||
|
deleteFileSafe(removed.path);
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleTrackCompletion(track) {
|
||||||
|
if (!track || track.permanent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
deleteFileSafe(track.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteTrackFile(track) {
|
||||||
|
if (!track) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!track.permanent) {
|
||||||
|
deleteFileSafe(track.path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
PERMANENT_DIR,
|
||||||
|
TEMP_DIR,
|
||||||
|
ensureStorageLayout,
|
||||||
|
registerUploadedFile,
|
||||||
|
getPermanentLibrary,
|
||||||
|
findPermanentTrack,
|
||||||
|
createQueueTrackFromLibrary,
|
||||||
|
deletePermanentTrack,
|
||||||
|
handleTrackCompletion,
|
||||||
|
deleteTrackFile,
|
||||||
|
};
|
||||||
32
storage/library.json
Normal file
32
storage/library.json
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "67e8cb3f-c079-4961-b9ff-4b3b16cd8dc5",
|
||||||
|
"originalName": "Monster Hunter Wilds [OST] - Credits Music (Wyverian Song).mp3",
|
||||||
|
"storedName": "7d39cc0e-3a29-43c4-b265-1eb15b9b52b9.mp3",
|
||||||
|
"path": "/home/shinuwa/projects/palico-bot/storage/permanent/7d39cc0e-3a29-43c4-b265-1eb15b9b52b9.mp3",
|
||||||
|
"size": 3813641,
|
||||||
|
"mimetype": "audio/mpeg",
|
||||||
|
"uploader": "Shinuwa",
|
||||||
|
"createdAt": "2025-11-18T16:48:46.726Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2b461bf4-2917-4faa-ae39-1111b6c478f7",
|
||||||
|
"originalName": "Dark Hallway.mp3",
|
||||||
|
"storedName": "3f4c096b-e316-4614-86f7-3f223ad9e362.mp3",
|
||||||
|
"path": "/home/shinuwa/projects/palico-bot/storage/permanent/3f4c096b-e316-4614-86f7-3f223ad9e362.mp3",
|
||||||
|
"size": 3090274,
|
||||||
|
"mimetype": "audio/mpeg",
|
||||||
|
"uploader": "Shinuwa",
|
||||||
|
"createdAt": "2025-11-18T16:50:42.461Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "c96b0e12-df38-4967-aeca-96335a3cf2a2",
|
||||||
|
"originalName": "Nintendo - Christmas Mix.mp3",
|
||||||
|
"storedName": "3c790e19-35a2-4e04-9956-736cb34e010a.mp3",
|
||||||
|
"path": "/home/shinuwa/projects/palico-bot/storage/permanent/3c790e19-35a2-4e04-9956-736cb34e010a.mp3",
|
||||||
|
"size": 122621211,
|
||||||
|
"mimetype": "audio/mpeg",
|
||||||
|
"uploader": "Shinuwa",
|
||||||
|
"createdAt": "2025-11-18T20:50:10.029Z"
|
||||||
|
}
|
||||||
|
]
|
||||||
0
storage/permanent/.gitkeep
Normal file
0
storage/permanent/.gitkeep
Normal file
0
storage/temp/.gitkeep
Normal file
0
storage/temp/.gitkeep
Normal file
Loading…
Add table
Add a link
Reference in a new issue