discord-multipurpose-bot/utils/musicSettings.js
Ayden cb5a906850
Some checks are pending
Docker / build (push) Waiting to run
Feat/Add Music Commands (#1)
* add simple music functionality

* update workflow

* update Dockerfile

* update Dockerfile

* update Dockerfile

* update Dockerfile

* add few more music commands

* add lyrics command

* update lyrics command

* add loop, and add categories to all commands

* change discord status

* seperate distube and change startup console theme

* Update README

* UPDATE LICENSE file

* fix docker compose image, add better error handling for distube and update tagging workflow

* switch to node-alpine image for docker

* switch to node-alpine image for docker

* update ascii

* music commands imporvements, implement live lyrics, some guards and bot leaving on empty

* use ffmpeg package rather than ffmpeg-static
2025-09-21 01:26:18 +01:00

34 lines
867 B
JavaScript

const MusicSettings = require("../models/MusicSettings");
/** in-memory cache to cut Mongo roundtrips */
const cache = new Map(); // guildId -> settings doc (lean POJO)
async function ensure(guildId) {
if (!guildId) throw new Error("Missing guildId");
if (cache.has(guildId)) return cache.get(guildId);
let doc = await MusicSettings.findOne({ guildId }).lean();
if (!doc) {
doc = await MusicSettings.create({ guildId });
doc = doc.toObject();
}
cache.set(guildId, doc);
return doc;
}
async function set(guildId, patch) {
const updated = await MusicSettings.findOneAndUpdate(
{ guildId },
{ $set: patch },
{ upsert: true, new: true }
).lean();
cache.set(guildId, updated);
return updated;
}
function clear(guildId) {
if (guildId) cache.delete(guildId);
else cache.clear();
}
module.exports = { ensure, set, clear };