fixing code style issues in new discord adapter

This commit is contained in:
orangecoding
2025-09-27 14:24:05 +02:00
parent 7cb0d6e382
commit fa234d2d78

View File

@@ -16,7 +16,7 @@ const generateColorFromString = (str) => {
for (let i = 0; i < input.length; i++) {
// hash * 33 + charCode
hash = ((hash << 5) + hash) + input.charCodeAt(i);
hash = (hash << 5) + hash + input.charCodeAt(i);
// Ensure the hash is 32 bit
hash |= 0;
}
@@ -59,14 +59,14 @@ const buildEmbed = (jobKey, listing) => {
value: String(listing.address ?? 'n/a'),
inline: true,
},
]
];
const embed = {
title: title,
color: generateColorFromString(jobKey),
url: listing.link,
fields: fields,
}
};
if (listing.image) {
embed.image = {
@@ -74,13 +74,13 @@ const buildEmbed = (jobKey, listing) => {
};
}
return embed
return embed;
};
export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
const adapter = notificationConfig.find((adapter) => adapter.id === config.id);
const webhookUrl = adapter?.fields?.webhookUrl;
if (!webhookUrl || newListings.length == 0) return Promise.resolve([]);
if (!webhookUrl || newListings.length === 0) return Promise.resolve([]);
const job = getJob(jobKey);
const jobName = job?.name || jobKey;
@@ -98,14 +98,13 @@ export const send = ({ serviceName, newListings, notificationConfig, jobKey }) =
const body = JSON.stringify({
content: content,
embeds: embedChunk,
})
});
const fetchPromise = fetch(webhookUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body,
})
.catch(error => {
}).catch((error) => {
console.error(`Error sending Discord webhook for chunk starting at ${i}:`, error);
return Promise.reject(new Error(`Webhook failed: ${error.message}`));
});