mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
fixing code style issues in new discord adapter
This commit is contained in:
@@ -16,7 +16,7 @@ const generateColorFromString = (str) => {
|
|||||||
|
|
||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
// hash * 33 + charCode
|
// hash * 33 + charCode
|
||||||
hash = ((hash << 5) + hash) + input.charCodeAt(i);
|
hash = (hash << 5) + hash + input.charCodeAt(i);
|
||||||
// Ensure the hash is 32 bit
|
// Ensure the hash is 32 bit
|
||||||
hash |= 0;
|
hash |= 0;
|
||||||
}
|
}
|
||||||
@@ -59,14 +59,14 @@ const buildEmbed = (jobKey, listing) => {
|
|||||||
value: String(listing.address ?? 'n/a'),
|
value: String(listing.address ?? 'n/a'),
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
]
|
];
|
||||||
|
|
||||||
const embed = {
|
const embed = {
|
||||||
title: title,
|
title: title,
|
||||||
color: generateColorFromString(jobKey),
|
color: generateColorFromString(jobKey),
|
||||||
url: listing.link,
|
url: listing.link,
|
||||||
fields: fields,
|
fields: fields,
|
||||||
}
|
};
|
||||||
|
|
||||||
if (listing.image) {
|
if (listing.image) {
|
||||||
embed.image = {
|
embed.image = {
|
||||||
@@ -74,13 +74,13 @@ const buildEmbed = (jobKey, listing) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return embed
|
return embed;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
|
export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
|
||||||
const adapter = notificationConfig.find((adapter) => adapter.id === config.id);
|
const adapter = notificationConfig.find((adapter) => adapter.id === config.id);
|
||||||
const webhookUrl = adapter?.fields?.webhookUrl;
|
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 job = getJob(jobKey);
|
||||||
const jobName = job?.name || jobKey;
|
const jobName = job?.name || jobKey;
|
||||||
@@ -98,14 +98,13 @@ export const send = ({ serviceName, newListings, notificationConfig, jobKey }) =
|
|||||||
const body = JSON.stringify({
|
const body = JSON.stringify({
|
||||||
content: content,
|
content: content,
|
||||||
embeds: embedChunk,
|
embeds: embedChunk,
|
||||||
})
|
});
|
||||||
|
|
||||||
const fetchPromise = fetch(webhookUrl, {
|
const fetchPromise = fetch(webhookUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body,
|
body,
|
||||||
})
|
}).catch((error) => {
|
||||||
.catch(error => {
|
|
||||||
console.error(`Error sending Discord webhook for chunk starting at ${i}:`, error);
|
console.error(`Error sending Discord webhook for chunk starting at ${i}:`, error);
|
||||||
return Promise.reject(new Error(`Webhook failed: ${error.message}`));
|
return Promise.reject(new Error(`Webhook failed: ${error.message}`));
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user