Update gitignore

This commit is contained in:
Bashy 2026-11-20 18:53:12 +01:00
commit 9e0ddb8182
32 changed files with 3863 additions and 0 deletions

37
src/dispatch.js Normal file
View file

@ -0,0 +1,37 @@
const db = require('./db');
const ws = require('./ws');
const { isOnCooldown, setCooldown } = require('./cooldowns');
function dispatchEvent(eventType, eventDetail = null, username = null, data = null) {
const actions = db.getMatchingActions(eventType, eventDetail);
let fired = 0;
for (const action of actions) {
if (isOnCooldown(action.id, action.cooldown_seconds)) {
console.log(`[dispatch] Action ${action.id} on cooldown — skipping`);
continue;
}
let mediaUrl = null;
if (action.media_file_id) {
const media = db.getMediaFile(action.media_file_id);
if (media) mediaUrl = `/media/${media.filename}`;
}
ws.broadcast({
event_type: eventType,
action_type: action.action_type,
media_url: mediaUrl,
alert_text: action.alert_text,
username,
});
setCooldown(action.id);
fired++;
console.log(`[dispatch] Fired action ${action.id} (${action.name}) — event: ${eventType}, user: ${username}`);
}
db.logActivity(eventType, eventDetail, username, data, fired);
}
module.exports = { dispatchEvent };