mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 08:47:43 +00:00
chore: refactor config and fix audits (#406)
This commit is contained in:
+35
-30
@@ -1,38 +1,43 @@
|
||||
import {Link, Store} from '../store/model';
|
||||
import {MessageBuilder, Webhook} from 'discord-webhook-node';
|
||||
import {Config} from '../config';
|
||||
import {Logger} from '../logger';
|
||||
import {config} from '../config';
|
||||
import {logger} from '../logger';
|
||||
|
||||
const hooks = Config.notifications.discord.webHookUrl;
|
||||
const notifyGroup = Config.notifications.discord.notifyGroup;
|
||||
const discord = config.notifications.discord;
|
||||
const hooks = discord.webHookUrl;
|
||||
const notifyGroup = discord.notifyGroup;
|
||||
|
||||
export function sendDiscordMessage(link: Link, store: Store) {
|
||||
(async () => {
|
||||
try {
|
||||
const embed = new MessageBuilder();
|
||||
embed.setTitle('Stock Notification');
|
||||
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);
|
||||
if (discord.webHookUrl.length > 0) {
|
||||
logger.debug('↗ sending discord message');
|
||||
|
||||
if (notifyGroup) {
|
||||
embed.setText(notifyGroup.join(' '));
|
||||
(async () => {
|
||||
try {
|
||||
const embed = new MessageBuilder();
|
||||
embed.setTitle('Stock Notification');
|
||||
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);
|
||||
|
||||
if (notifyGroup) {
|
||||
embed.setText(notifyGroup.join(' '));
|
||||
}
|
||||
|
||||
embed.setColor(0x76B900);
|
||||
embed.setTimestamp();
|
||||
|
||||
const promises = [];
|
||||
for (const hook of hooks) {
|
||||
promises.push(new Webhook(hook).send(embed));
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
|
||||
logger.info('✔ discord message sent');
|
||||
} catch (error) {
|
||||
logger.error('✖ couldn\'t send discord message', error);
|
||||
}
|
||||
|
||||
embed.setColor(0x76B900);
|
||||
embed.setTimestamp();
|
||||
|
||||
const promises = [];
|
||||
for (const hook of hooks) {
|
||||
promises.push(new Webhook(hook).send(embed));
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
|
||||
Logger.info('✔ discord message sent');
|
||||
} catch (error) {
|
||||
Logger.error('✖ couldn\'t send discord message', error);
|
||||
}
|
||||
})();
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user