From adf3a2d3fe2268c2dc775ee869eb946bd9406af6 Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Fri, 12 Jul 2024 17:29:24 -0400 Subject: [PATCH] Add notification config --- config/notifications.yml | 4 ++++ src/ws/events/admin/handlers/notification.ts | 21 +++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 config/notifications.yml diff --git a/config/notifications.yml b/config/notifications.yml new file mode 100644 index 0000000..0a8b602 --- /dev/null +++ b/config/notifications.yml @@ -0,0 +1,4 @@ +allowXSS: true +maxDuration: 60000 +defaultDuration: 7000 +allTarget: all diff --git a/src/ws/events/admin/handlers/notification.ts b/src/ws/events/admin/handlers/notification.ts index d91c636..4abe9bd 100644 --- a/src/ws/events/admin/handlers/notification.ts +++ b/src/ws/events/admin/handlers/notification.ts @@ -1,16 +1,35 @@ import { ChannelList } from "../../../../channel/ChannelList"; +import { loadConfig } from "../../../../util/config"; import { ServerEventListener } from "../../../../util/types"; import { socketsBySocketID } from "../../../Socket"; +const config = loadConfig<{ + allowXSS: boolean; + maxDuration: number; + defaultDuration: number; + allTarget: string; +}>("config/notifications.yml", { + allowXSS: true, + maxDuration: 60000, + defaultDuration: 7000, + allTarget: "all" +}); + export const notification: ServerEventListener<"notification"> = { id: "notification", callback: async (msg, socket) => { // Send notification to user/channel if (typeof msg.targetChannel == "undefined" && typeof msg.targetUser == "undefined") return; + if (msg.duration) { + if (msg.duration > config.maxDuration) msg.duration = config.maxDuration; + } else { + msg.duration = config.defaultDuration; + } + if (typeof msg.targetChannel !== "undefined") { for (const ch of ChannelList.getList().values()) { - if (ch.getID() == msg.targetChannel) { + if (ch.getID() == msg.targetChannel || msg.targetChannel == config.allTarget) { ch.sendNotification(msg); } }