mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
start upgrading eslint
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import got from 'got';
|
||||
import { isURL } from 'validator';
|
||||
import logger from './logger';
|
||||
import nconf from 'nconf';
|
||||
import logger from './logger';
|
||||
import {
|
||||
model as User,
|
||||
} from '../models/user';
|
||||
@@ -17,7 +17,7 @@ function sendWebhook (url, body) {
|
||||
|
||||
function isValidWebhook (hook) {
|
||||
return hook.enabled && isURL(hook.url, {
|
||||
require_tld: IS_PRODUCTION ? true : false, // eslint-disable-line camelcase
|
||||
require_tld: !!IS_PRODUCTION, // eslint-disable-line camelcase
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ export class WebhookSender {
|
||||
}
|
||||
|
||||
send (user, data) {
|
||||
const webhooks = user.webhooks;
|
||||
const { webhooks } = user;
|
||||
|
||||
let hooks = webhooks.filter((hook) => {
|
||||
const hooks = webhooks.filter(hook => {
|
||||
if (!isValidWebhook(hook)) return false;
|
||||
if (hook.type === 'globalActivity') return true;
|
||||
|
||||
@@ -56,34 +56,36 @@ export class WebhookSender {
|
||||
return; // prevents running the body creation code if there are no webhooks to send
|
||||
}
|
||||
|
||||
let body = this.transformData(data);
|
||||
const body = this.transformData(data);
|
||||
this.attachDefaultData(user, body);
|
||||
|
||||
hooks.forEach((hook) => {
|
||||
hooks.forEach(hook => {
|
||||
sendWebhook(hook.url, body);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export let taskScoredWebhook = new WebhookSender({
|
||||
export const taskScoredWebhook = new WebhookSender({
|
||||
type: 'taskActivity',
|
||||
webhookFilter (hook) {
|
||||
let scored = hook.options && hook.options.scored;
|
||||
const scored = hook.options && hook.options.scored;
|
||||
|
||||
return scored;
|
||||
},
|
||||
transformData (data) {
|
||||
let { user, task, direction, delta } = data;
|
||||
const {
|
||||
user, task, direction, delta,
|
||||
} = data;
|
||||
|
||||
let extendedStats = User.addComputedStatsToJSONObj(user.stats.toJSON(), user);
|
||||
const extendedStats = User.addComputedStatsToJSONObj(user.stats.toJSON(), user);
|
||||
|
||||
let userData = {
|
||||
const userData = {
|
||||
// _id: user._id, added automatically when the webhook is sent
|
||||
_tmp: user._tmp,
|
||||
stats: extendedStats,
|
||||
};
|
||||
|
||||
let dataToSend = {
|
||||
const dataToSend = {
|
||||
type: 'scored',
|
||||
direction,
|
||||
delta,
|
||||
@@ -95,32 +97,32 @@ export let taskScoredWebhook = new WebhookSender({
|
||||
},
|
||||
});
|
||||
|
||||
export let taskActivityWebhook = new WebhookSender({
|
||||
export const taskActivityWebhook = new WebhookSender({
|
||||
type: 'taskActivity',
|
||||
webhookFilter (hook, data) {
|
||||
let { type } = data;
|
||||
const { type } = data;
|
||||
return hook.options[type];
|
||||
},
|
||||
});
|
||||
|
||||
export let userActivityWebhook = new WebhookSender({
|
||||
export const userActivityWebhook = new WebhookSender({
|
||||
type: 'userActivity',
|
||||
webhookFilter (hook, data) {
|
||||
let { type } = data;
|
||||
const { type } = data;
|
||||
return hook.options[type];
|
||||
},
|
||||
});
|
||||
|
||||
export let questActivityWebhook = new WebhookSender({
|
||||
export const questActivityWebhook = new WebhookSender({
|
||||
type: 'questActivity',
|
||||
webhookFilter (hook, data) {
|
||||
let { type } = data;
|
||||
const { type } = data;
|
||||
return hook.options[type];
|
||||
},
|
||||
transformData (data) {
|
||||
let { group, quest, type } = data;
|
||||
const { group, quest, type } = data;
|
||||
|
||||
let dataToSend = {
|
||||
const dataToSend = {
|
||||
type,
|
||||
group: {
|
||||
id: group.id,
|
||||
@@ -135,15 +137,15 @@ export let questActivityWebhook = new WebhookSender({
|
||||
},
|
||||
});
|
||||
|
||||
export let groupChatReceivedWebhook = new WebhookSender({
|
||||
export const groupChatReceivedWebhook = new WebhookSender({
|
||||
type: 'groupChatReceived',
|
||||
webhookFilter (hook, data) {
|
||||
return hook.options.groupId === data.group.id;
|
||||
},
|
||||
transformData (data) {
|
||||
let { group, chat } = data;
|
||||
const { group, chat } = data;
|
||||
|
||||
let dataToSend = {
|
||||
const dataToSend = {
|
||||
group: {
|
||||
id: group.id,
|
||||
name: group.name,
|
||||
|
||||
Reference in New Issue
Block a user