blob: 7339129fa417f5fa0c4e20884a742eec38ee4c63 [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({
pineafanad54d752022-04-18 19:01:43 +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
pineafanbd02b4a2022-08-05 22:01:38 +010012export default async function(type: string, guild: string, message: string | true, severity: "Critical" | "Warning" | "Info" = "Info") {
pineafan63fc5e22022-08-04 22:04:10 +010013 const data = await client.database.guilds.read(guild);
pineafane23c4ec2022-07-27 21:56:27 +010014 if (message === true) {
15 return await client.database.guilds.write(guild, {[`singleEventNotifications.${type}`]: false});
16 }
pineafan6702cef2022-06-13 17:52:37 +010017 if (data.singleEventNotifications[type]) return;
pineafane23c4ec2022-07-27 21:56:27 +010018 await client.database.guilds.write(guild, {[`singleEventNotifications.${type}`]: true});
pineafanad54d752022-04-18 19:01:43 +010019 try {
pineafan63fc5e22022-08-04 22:04:10 +010020 const channel = await client.channels.fetch(data.logging.staff.channel);
pineafan6702cef2022-06-13 17:52:37 +010021 if (!channel) return;
pineafan4edb7762022-06-26 19:21:04 +010022 await channel.send({embeds: [new EmojiEmbed()
pineafanad54d752022-04-18 19:01:43 +010023 .setTitle(`${severity} notification`)
24 .setDescription(message)
pineafanbd02b4a2022-08-05 22:01:38 +010025 .setStatus(severities.get(severity))
pineafanad54d752022-04-18 19:01:43 +010026 .setEmoji("CONTROL.BLOCKCROSS")
pineafan63fc5e22022-08-04 22:04:10 +010027 ]});
pineafanad54d752022-04-18 19:01:43 +010028 } catch (err) {
pineafan63fc5e22022-08-04 22:04:10 +010029 console.error(err);
pineafanad54d752022-04-18 19:01:43 +010030 }
31}