feat(notification): add discord groups (#1211)

This commit is contained in:
Sebastian
2020-12-09 20:54:51 +01:00
committed by GitHub
parent 9dc04b3638
commit 2632386a5b
4 changed files with 64 additions and 2 deletions
+15 -2
View File
@@ -4,7 +4,7 @@ import {config} from '../config';
import {logger} from '../logger';
const discord = config.notifications.discord;
const {notifyGroup, webhooks} = discord;
const {notifyGroup, webhooks, notifyGroupSeries} = discord;
function getIdAndToken(webhook: string) {
const match = /.*\/webhooks\/(\d+)\/(.+)/.exec(webhook);
@@ -44,13 +44,26 @@ export function sendDiscordMessage(link: Link, store: Store) {
embed.addField('Model', link.model, true);
embed.addField('Series', link.series, true);
embed.setTimestamp();
let notifyText: string[] = [];
if (Object.keys(notifyGroupSeries).indexOf(link.series) !== 0) {
notifyText = notifyText.concat(
notifyGroupSeries[link.series]
);
} else if (notifyGroup) {
notifyText = notifyText.concat(notifyGroup); // If there is no group for the series we
}
const promises = [];
for (const webhook of webhooks) {
const {id, token} = getIdAndToken(webhook);
const client = new Discord.WebhookClient(id, token);
promises.push({
client,
message: client.send(notifyGroup.join(' '), {
message: client.send(notifyText.join(' '), {
embeds: [embed],
username: 'streetmerchant'
})