Add a notify websocket event

This commit is contained in:
Eldritch-Oliver 2025-10-08 23:06:17 -06:00
parent 822094077b
commit e06c500b5c
2 changed files with 58 additions and 0 deletions

View file

@ -1,8 +1,10 @@
import { localizer } from "../utils/Localizer.mjs"; import { localizer } from "../utils/Localizer.mjs";
import { Logger } from "../utils/Logger.mjs"; import { Logger } from "../utils/Logger.mjs";
import { notify } from "./notify.mjs";
import { updateSands } from "./updateSands.mjs"; import { updateSands } from "./updateSands.mjs";
const events = { const events = {
notify,
updateSands, updateSands,
}; };

56
module/sockets/notify.mjs Normal file
View file

@ -0,0 +1,56 @@
import { localizer } from "../utils/Localizer.mjs";
export function notify(payload) {
// #region Payload Validity
const {
message,
users = [],
type = `info`,
permanent = false,
} = payload;
if (!message) {
ui.notifications.error(localizer(
`RipCrypt.notifs.error.malformed-socket-payload`,
{
event: `notify`,
details: `A message must be provided`,
},
));
return;
};
if (users && !Array.isArray(users)) {
ui.notifications.error(localizer(
`RipCrypt.notifs.error.malformed-socket-payload`,
{
event: `notify`,
details: `"users" must be an array of user IDs`,
},
));
return;
};
if (![`info`, `error`, `success`].includes(type)) {
ui.notifications.error(localizer(
`RipCrypt.notifs.error.malformed-socket-payload`,
{
event: `notify`,
details: `An invalid notification type was provided.`,
},
));
return;
}
// #endregion Payload Validity
// Act
if (users.length === 0 || users.includes(game.user.id)) {
ui.notifications[type]?.(
localizer(message),
{
console: false,
permanent,
},
);
};
};