chore(misc): normalize logs (#242)

This commit is contained in:
Jef LeCompte
2020-09-23 14:20:06 -04:00
committed by GitHub
parent 8466f9f398
commit 7c50e2b5aa
21 changed files with 239 additions and 183 deletions
+7 -5
View File
@@ -1,17 +1,18 @@
import {Link, Store} from '../store/model';
import {MessageBuilder, Webhook} from 'discord-webhook-node';
import {Config} from '../config';
import {Link} from '../store/model';
import {Logger} from '../logger';
const hook = new Webhook(Config.notifications.discord.webHookUrl);
const notifyGroup = Config.notifications.discord.notifyGroup;
export function sendDiscordMessage(cartUrl: string, link: Link) {
export function sendDiscordMessage(link: Link, store: Store) {
(async () => {
try {
const embed = new MessageBuilder();
embed.setTitle('Stock Notification');
embed.addField('URL', cartUrl, true);
embed.addField('URL', link.cartUrl ? link.cartUrl : link.url, true);
embed.addField('Store', store.name, true);
embed.addField('Brand', link.brand, true);
embed.addField('Model', link.model, true);
@@ -22,9 +23,10 @@ export function sendDiscordMessage(cartUrl: string, link: Link) {
embed.setColor(0x76B900);
embed.setTimestamp();
await hook.send(embed);
Logger.info(`↗ discord message sent: ${cartUrl}`);
Logger.info('✔ discord message sent');
} catch (error) {
Logger.error(error);
Logger.error('✖ couldn\'t send discord message', error);
}
})();
}