pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import client from "./client.js"; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 2 | import EmojiEmbed from "./generateEmojiEmbed.js"; |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 3 | import { Record as ImmutableRecord } from "immutable"; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 4 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 5 | const severitiesType = ImmutableRecord({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 6 | Critical: "Danger", |
| 7 | Warning: "Warning", |
| 8 | Info: "Success" |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 9 | } as Record<string, "Danger" | "Warning" | "Success">); |
| 10 | const severities = severitiesType(); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 11 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 12 | export default async function ( |
| 13 | type: string, |
| 14 | guild: string, |
| 15 | message: string | true, |
| 16 | severity: "Critical" | "Warning" | "Info" = "Info" |
| 17 | ) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 18 | const data = await client.database.guilds.read(guild); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 19 | if (message === true) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 20 | return await client.database.guilds.write(guild, { |
| 21 | [`singleEventNotifications.${type}`]: false |
| 22 | }); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 23 | } |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 24 | if (data.singleEventNotifications[type]) return; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 25 | await client.database.guilds.write(guild, { |
| 26 | [`singleEventNotifications.${type}`]: true |
| 27 | }); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 28 | try { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 29 | const channel = await client.channels.fetch(data.logging.staff.channel); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 30 | if (!channel) return; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 31 | 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 | }); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 40 | } catch (err) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 41 | console.error(err); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 42 | } |
| 43 | } |