blob: f29d7756a44c363250b086ff0f3d4386b437c882 [file] [log] [blame]
pineafan6702cef2022-06-13 17:52:37 +01001import client from './client.js';
pineafan4edb7762022-06-26 19:21:04 +01002import EmojiEmbed from "./generateEmojiEmbed.js";
pineafanad54d752022-04-18 19:01:43 +01003
4let severities = {
5 "Critical": "Danger",
6 "Warning": "Warning",
7 "Info": "Success"
8}
9
pineafane23c4ec2022-07-27 21:56:27 +010010export default async function(type: string, guild: string, message: string | true, severity?: string) {
pineafan4edb7762022-06-26 19:21:04 +010011 let data = await client.database.guilds.read(guild);
pineafane23c4ec2022-07-27 21:56:27 +010012 if (message === true) {
13 return await client.database.guilds.write(guild, {[`singleEventNotifications.${type}`]: false});
14 }
pineafan6702cef2022-06-13 17:52:37 +010015 if (data.singleEventNotifications[type]) return;
pineafane23c4ec2022-07-27 21:56:27 +010016 await client.database.guilds.write(guild, {[`singleEventNotifications.${type}`]: true});
pineafanad54d752022-04-18 19:01:43 +010017 try {
pineafan6702cef2022-06-13 17:52:37 +010018 let channel = await client.channels.fetch(data.logging.staff.channel);
19 if (!channel) return;
pineafan4edb7762022-06-26 19:21:04 +010020 await channel.send({embeds: [new EmojiEmbed()
pineafanad54d752022-04-18 19:01:43 +010021 .setTitle(`${severity} notification`)
22 .setDescription(message)
pineafan6702cef2022-06-13 17:52:37 +010023 .setStatus(severities[severity])
pineafanad54d752022-04-18 19:01:43 +010024 .setEmoji("CONTROL.BLOCKCROSS")
25 ]})
26 } catch (err) {
27 console.error(err)
28 }
29}