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