blob: 7339129fa417f5fa0c4e20884a742eec38ee4c63 [file] [log] [blame]
import client from "./client.js";
import EmojiEmbed from "./generateEmojiEmbed.js";
import { Record as ImmutableRecord } from "immutable";
const severitiesType = ImmutableRecord({
"Critical": "Danger",
"Warning": "Warning",
"Info": "Success"
} as Record<string, "Danger" | "Warning" | "Success">);
const severities = severitiesType();
export default async function(type: string, guild: string, message: string | true, severity: "Critical" | "Warning" | "Info" = "Info") {
const data = await client.database.guilds.read(guild);
if (message === true) {
return await client.database.guilds.write(guild, {[`singleEventNotifications.${type}`]: false});
}
if (data.singleEventNotifications[type]) return;
await client.database.guilds.write(guild, {[`singleEventNotifications.${type}`]: true});
try {
const channel = await client.channels.fetch(data.logging.staff.channel);
if (!channel) return;
await channel.send({embeds: [new EmojiEmbed()
.setTitle(`${severity} notification`)
.setDescription(message)
.setStatus(severities.get(severity))
.setEmoji("CONTROL.BLOCKCROSS")
]});
} catch (err) {
console.error(err);
}
}