blob: 44bb2d0b0dd9f3a661d174e30cf230bfce2fa62c [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import client from "./client.js";
pineafan4edb7762022-06-26 19:21:04 +01002import EmojiEmbed from "./generateEmojiEmbed.js";
pineafanad54d752022-04-18 19:01:43 +01003
pineafan63fc5e22022-08-04 22:04:10 +01004const severities = {
pineafanad54d752022-04-18 19:01:43 +01005 "Critical": "Danger",
6 "Warning": "Warning",
7 "Info": "Success"
pineafan63fc5e22022-08-04 22:04:10 +01008};
pineafanad54d752022-04-18 19:01:43 +01009
pineafane23c4ec2022-07-27 21:56:27 +010010export default async function(type: string, guild: string, message: string | true, severity?: string) {
pineafan63fc5e22022-08-04 22:04:10 +010011 const 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 {
pineafan63fc5e22022-08-04 22:04:10 +010018 const channel = await client.channels.fetch(data.logging.staff.channel);
pineafan6702cef2022-06-13 17:52:37 +010019 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")
pineafan63fc5e22022-08-04 22:04:10 +010025 ]});
pineafanad54d752022-04-18 19:01:43 +010026 } catch (err) {
pineafan63fc5e22022-08-04 22:04:10 +010027 console.error(err);
pineafanad54d752022-04-18 19:01:43 +010028 }
29}