blob: 8f011e362e39bff3fcf1f205e022e3ee84824b0c [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);
pineafane23c4ec2022-07-27 21:56:27 +010019 if (message === true) {
Skyler Grey75ea9172022-08-06 10:22:23 +010020 return await client.database.guilds.write(guild, {
21 [`singleEventNotifications.${type}`]: false
22 });
pineafane23c4ec2022-07-27 21:56:27 +010023 }
pineafan6702cef2022-06-13 17:52:37 +010024 if (data.singleEventNotifications[type]) return;
Skyler Grey75ea9172022-08-06 10:22:23 +010025 await client.database.guilds.write(guild, {
26 [`singleEventNotifications.${type}`]: true
27 });
pineafanad54d752022-04-18 19:01:43 +010028 try {
pineafan63fc5e22022-08-04 22:04:10 +010029 const channel = await client.channels.fetch(data.logging.staff.channel);
pineafan6702cef2022-06-13 17:52:37 +010030 if (!channel) return;
Skyler Grey75ea9172022-08-06 10:22:23 +010031 await channel.send({
32 embeds: [
33 new EmojiEmbed()
34 .setTitle(`${severity} notification`)
35 .setDescription(message)
36 .setStatus(severities.get(severity))
37 .setEmoji("CONTROL.BLOCKCROSS")
38 ]
39 });
pineafanad54d752022-04-18 19:01:43 +010040 } catch (err) {
pineafan63fc5e22022-08-04 22:04:10 +010041 console.error(err);
pineafanad54d752022-04-18 19:01:43 +010042 }
43}