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 | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 3 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 4 | const severities = { |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 5 | "Critical": "Danger", |
| 6 | "Warning": "Warning", |
| 7 | "Info": "Success" |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 8 | }; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 9 | |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 10 | export default async function(type: string, guild: string, message: string | true, severity?: string) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 11 | const data = await client.database.guilds.read(guild); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 12 | if (message === true) { |
| 13 | return await client.database.guilds.write(guild, {[`singleEventNotifications.${type}`]: false}); |
| 14 | } |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 15 | if (data.singleEventNotifications[type]) return; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 16 | await client.database.guilds.write(guild, {[`singleEventNotifications.${type}`]: true}); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 17 | try { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 18 | const channel = await client.channels.fetch(data.logging.staff.channel); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 19 | if (!channel) return; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 20 | await channel.send({embeds: [new EmojiEmbed() |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 21 | .setTitle(`${severity} notification`) |
| 22 | .setDescription(message) |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 23 | .setStatus(severities[severity]) |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 24 | .setEmoji("CONTROL.BLOCKCROSS") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 25 | ]}); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 26 | } catch (err) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 27 | console.error(err); |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 28 | } |
| 29 | } |