mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 08:47:43 +00:00
feat(notification): add discord groups (#1211)
This commit is contained in:
@@ -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'
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user