blob: e762487dbdebcfb17d404570d20fafa9ffa5e59b [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import client from "./client.js";
pineafan4edb7762022-06-26 19:21:04 +01002import EmojiEmbed from "./generateEmojiEmbed.js";
pineafanbd02b4a2022-08-05 22:01:38 +01003import { Record as ImmutableRecord } from "immutable";
pineafanad54d752022-04-18 19:01:43 +01004
pineafanbd02b4a2022-08-05 22:01:38 +01005const severitiesType = ImmutableRecord({
Skyler Grey75ea9172022-08-06 10:22:23 +01006 Critical: "Danger",
7 Warning: "Warning",
8 Info: "Success"
pineafanbd02b4a2022-08-05 22:01:38 +01009} as Record<string, "Danger" | "Warning" | "Success">);
10const severities = severitiesType();
pineafanad54d752022-04-18 19:01:43 +010011
Skyler Grey75ea9172022-08-06 10:22:23 +010012export default async function (
13 type: string,
14 guild: string,
15 message: string | true,
16 severity: "Critical" | "Warning" | "Info" = "Info"
17) {
pineafan63fc5e22022-08-04 22:04:10 +010018 const data = await client.database.guilds.read(guild);
PineaFan100df682023-01-02 13:26:08 +000019 if (data.logging.staff.channel === null) return;
pineafane23c4ec2022-07-27 21:56:27 +010020 if (message === true) {
Skyler Grey75ea9172022-08-06 10:22:23 +010021 return await client.database.guilds.write(guild, {
22 [`singleEventNotifications.${type}`]: false
23 });
pineafane23c4ec2022-07-27 21:56:27 +010024 }
pineafan6702cef2022-06-13 17:52:37 +010025 if (data.singleEventNotifications[type]) return;
Skyler Grey75ea9172022-08-06 10:22:23 +010026 await client.database.guilds.write(guild, {
27 [`singleEventNotifications.${type}`]: true
28 });
pineafanad54d752022-04-18 19:01:43 +010029 try {
pineafan63fc5e22022-08-04 22:04:10 +010030 const channel = await client.channels.fetch(data.logging.staff.channel);
pineafan6702cef2022-06-13 17:52:37 +010031 if (!channel) return;
PineaFan100df682023-01-02 13:26:08 +000032 if (!channel.isTextBased()) return;
Skyler Grey75ea9172022-08-06 10:22:23 +010033 await channel.send({
34 embeds: [
35 new EmojiEmbed()
36 .setTitle(`${severity} notification`)
37 .setDescription(message)
38 .setStatus(severities.get(severity))
39 .setEmoji("CONTROL.BLOCKCROSS")
40 ]
41 });
pineafanad54d752022-04-18 19:01:43 +010042 } catch (err) {
pineafan63fc5e22022-08-04 22:04:10 +010043 console.error(err);
pineafanad54d752022-04-18 19:01:43 +010044 }
45}