mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 16:57:34 +00:00
feat(notification): add discord groups (#1211)
This commit is contained in:
@@ -180,6 +180,25 @@ const notifications = {
|
||||
desktop: process.env.DESKTOP_NOTIFICATIONS === 'true',
|
||||
discord: {
|
||||
notifyGroup: envOrArray(process.env.DISCORD_NOTIFY_GROUP),
|
||||
notifyGroupSeries: {
|
||||
'3060ti': envOrArray(process.env.DISCORD_NOTIFY_GROUP_3060TI),
|
||||
3070: envOrArray(process.env.DISCORD_NOTIFY_GROUP_3070),
|
||||
3080: envOrArray(process.env.DISCORD_NOTIFY_GROUP_3080),
|
||||
3090: envOrArray(process.env.DISCORD_NOTIFY_GROUP_3090),
|
||||
rx6800: envOrArray(process.env.DISCORD_NOTIFY_GROUP_RX6800),
|
||||
rx6800xt: envOrArray(process.env.DISCORD_NOTIFY_GROUP_RX6800XT),
|
||||
rx6900xt: envOrArray(process.env.DISCORD_NOTIFY_GROUP_RX6900XT),
|
||||
ryzen5600: envOrArray(process.env.DISCORD_NOTIFY_GROUP_RYZEN5600),
|
||||
ryzen5800: envOrArray(process.env.DISCORD_NOTIFY_GROUP_RYZEN5800),
|
||||
ryzen5900: envOrArray(process.env.DISCORD_NOTIFY_GROUP_RYZEN5900),
|
||||
ryzen5950: envOrArray(process.env.DISCORD_NOTIFY_GROUP_RYZEN5950),
|
||||
sf: envOrArray(process.env.DISCORD_NOTIFY_GROUP_CORSAIR_SF),
|
||||
sonyps5c: envOrArray(process.env.DISCORD_NOTIFY_GROUP_SONYPS5C),
|
||||
sonyps5de: envOrArray(process.env.DISCORD_NOTIFY_GROUP_SONYPS5DE),
|
||||
'test:series': envOrArray(process.env.DISCORD_NOTIFY_GROUP_TEST),
|
||||
xboxss: envOrArray(process.env.DISCORD_NOTIFY_GROUP_XBOXSS),
|
||||
xboxsx: envOrArray(process.env.DISCORD_NOTIFY_GROUP_XBOXSX)
|
||||
},
|
||||
webhooks: envOrArray(process.env.DISCORD_WEB_HOOK)
|
||||
},
|
||||
email: {
|
||||
|
||||
@@ -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