UntisBot/src/modules/scanForNotifications.ts

22 lines
778 B
TypeScript

import Discord from "discord.js";
import main from "../index";
const { defaultEmbedColor, untis, db, sendEmbed } = main;
export async function run() {
const news = await untis.getNewsWidget(new Date(), true);
if (!news) return;
news.messagesOfDay.forEach(message => {
if (db.seenMessages.get(`${message.id}`)) return;
console.log("New message found: " + message.text);
const embed = new Discord.MessageEmbed()
.setAuthor("Notification")
.setColor(defaultEmbedColor)
.setTitle(message.subject)
.setDescription(message.text.replace(/<br>/g, "\n"))
.setFooter(`Notification ID: ${message.id}`);
sendEmbed(embed);
db.seenMessages.set(`${message.id}`, true);
});
}