Replace request with node-fetch

This commit is contained in:
Nanobyte
2021-01-05 01:18:34 +01:00
parent 5927a24f16
commit aabeb5f493
4 changed files with 98 additions and 66 deletions

View File

@@ -1,6 +1,6 @@
import {config} from '../config';
import {Logger} from '../utils/logger';
import request from 'request';
import fetch from 'node-fetch';
function getVoteAuthorRaw(submissionCount: number, isVIP: boolean, isOwnSubmission: boolean): string {
if (isOwnSubmission) {
@@ -36,12 +36,15 @@ function dispatchEvent(scope: string, data: any): void {
let scopes = webhook.scopes || [];
if (!scopes.includes(scope.toLowerCase())) return;
request.post(webhookURL, {
json: data, headers: {
fetch(webhookURL, {
method: 'POST',
body: JSON.stringify(data),
headers: {
"Authorization": authKey,
"Event-Type": scope, // Maybe change this in the future?
},
}).on('error', (e) => {
})
.catch(err => {
Logger.warn('Couldn\'t send webhook to ' + webhook.url);
Logger.warn(e.message);
});