UNPKG

lemmy-bot

Version:

A bot API for Lemmy, the fediverse link aggregator.

38 lines (37 loc) 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractInstanceFromActorId = exports.getListingType = exports.parseHandlers = exports.shouldProcess = exports.futureDaysToUnixTime = exports.correctVote = void 0; const types_1 = require("./types"); const correctVote = (vote) => { if (vote < -1) { vote = types_1.Vote.Downvote; } if (vote > 1) { vote = types_1.Vote.Upvote; } return vote; }; exports.correctVote = correctVote; const futureDaysToUnixTime = (days) => days ? Math.trunc(new Date(Date.now() + 1000 * 60 * 60 * 24 * days).getTime() / 1000) : undefined; exports.futureDaysToUnixTime = futureDaysToUnixTime; const shouldProcess = ({ exists, reprocessTime }) => !exists || (reprocessTime && reprocessTime < new Date(Date.now())); exports.shouldProcess = shouldProcess; const parseHandlers = (handlers) => handlers ? Object.entries(handlers).reduce((acc, [key, val]) => (Object.assign(Object.assign({}, acc), { [key]: typeof val === 'function' ? { handle: val } : val })), {}) : {}; exports.parseHandlers = parseHandlers; const getListingType = (options) => { if (options.allowList && options.allowList.length === 1 && typeof options.allowList[0] === 'string') { return 'Local'; } else { return 'All'; } }; exports.getListingType = getListingType; const extractInstanceFromActorId = (actorId) => actorId.match(/https?:\/\/(.*)\/(?:c|u|m)\/.*/)[1]; exports.extractInstanceFromActorId = extractInstanceFromActorId;