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 | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame^] | 19 | if (data.logging.staff.channel === null) return; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 20 | if (message === true) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 21 | return await client.database.guilds.write(guild, { |
| 22 | [`singleEventNotifications.${type}`]: false |
| 23 | }); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 24 | } |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 25 | if (data.singleEventNotifications[type]) return; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 26 | await client.database.guilds.write(guild, { |
| 27 | [`singleEventNotifications.${type}`]: true |
| 28 | }); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 29 | try { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 30 | const channel = await client.channels.fetch(data.logging.staff.channel); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 31 | if (!channel) return; |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame^] | 32 | if (!channel.isTextBased()) return; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 33 | 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 | }); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 42 | } catch (err) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 43 | console.error(err); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 44 | } |
| 45 | } |