diff --git a/cluster.js b/cluster.js index 9b50ca2df0b..5fa5aebdcd5 100644 --- a/cluster.js +++ b/cluster.js @@ -86,7 +86,7 @@ function cluster () { const parse = new Parser({ sender: sender, message: message, skip: skip }) - if (!skip && sender['message-type'] === 'whisper' && (!(await global.configuration.getValue('disableWhisperListener')) || global.parser.isOwner(sender))) { + if (!skip && sender['message-type'] === 'whisper' && (!(await global.configuration.getValue('disableWhisperListener')) || global.commons.isOwner(sender))) { global.log.whisperIn(message, {username: sender.username}) } else if (!skip && !global.commons.isBot(sender.username)) global.log.chatIn(message, {username: sender.username}) diff --git a/libs/api.js b/libs/api.js index 039c771bd8d..14b9e0ce09d 100644 --- a/libs/api.js +++ b/libs/api.js @@ -394,7 +394,7 @@ class API { type: 'follow', username: user.username }) - if (!quiet && !global.parser.isBot(user.username)) { + if (!quiet && !global.commons.isBot(user.username)) { global.log.follow(user.username) global.events.fire('follow', { username: user.username }) } diff --git a/libs/commons.js b/libs/commons.js index 83047c767c7..d96bec69620 100644 --- a/libs/commons.js +++ b/libs/commons.js @@ -3,6 +3,7 @@ var _ = require('lodash') var chalk = require('chalk') const debug = require('debug') +const moment = require('moment') const config = require('../config.json') @@ -74,6 +75,27 @@ Commons.prototype.prepare = function (translate, attr) { return msg } +Commons.prototype.getTime = function (time, isChat) { + var now, days, hours, minutes, seconds + now = _.isNull(time) || !time ? {days: 0, hours: 0, minutes: 0, seconds: 0} : moment().preciseDiff(time, true) + if (isChat) { + days = now.days > 0 ? now.days : '' + hours = now.hours > 0 ? now.hours : '' + minutes = now.minutes > 0 ? now.minutes : '' + seconds = now.seconds > 0 ? now.seconds : '' + return { days: days, + hours: hours, + minutes: minutes, + seconds: seconds } + } else { + days = now.days > 0 ? now.days + 'd' : '' + hours = now.hours >= 0 && now.hours < 10 ? '0' + now.hours + ':' : now.hours + ':' + minutes = now.minutes >= 0 && now.minutes < 10 ? '0' + now.minutes + ':' : now.minutes + ':' + seconds = now.seconds >= 0 && now.seconds < 10 ? '0' + now.seconds : now.seconds + return days + hours + minutes + seconds + } +} + Commons.prototype.sendMessage = async function (message, sender, attr) { if (cluster.isMaster && (_.isNil(global.client) || global.client.readyState() !== 'OPEN')) return setTimeout(() => this.sendMessage(message, sender, attr), 10) // wait for proper connection debug('commons:sendMessage')('sendMessage(%s, %j, %j)', message, sender, attr) diff --git a/libs/message.js b/libs/message.js index 24a8d0a1740..6a13e972048 100644 --- a/libs/message.js +++ b/libs/message.js @@ -94,8 +94,8 @@ class Message { let custom = { '$_#': async function (filter) { let variable = filter.replace('$_', '') - let isMod = await global.parser.isMod(attr.sender) - if ((global.parser.isOwner(attr.sender) || isMod) && + let isMod = await global.commons.isMod(attr.sender) + if ((global.commons.isOwner(attr.sender) || isMod) && (!_.isUndefined(attr.param) && attr.param.length !== 0)) { await global.db.engine.update('customvars', { key: variable }, { key: variable, value: attr.param }) let msg = global.commons.prepare('filters.setVariable', { value: attr.param, variable: variable }) diff --git a/libs/overlays/stats.js b/libs/overlays/stats.js index 1f59f51ce81..486602561d8 100644 --- a/libs/overlays/stats.js +++ b/libs/overlays/stats.js @@ -10,7 +10,7 @@ function Stats () { Stats.prototype._get = async function (self, socket) { const when = await global.cache.when() const stats = { - uptime: global.twitch.getTime(await global.cache.isOnline() ? when.online : 0, false), + uptime: global.commons.getTime(await global.cache.isOnline() ? when.online : 0, false), viewers: global.api.current.viewers, followers: global.api.current.followers, subscribers: global.api.current.subscribers, diff --git a/libs/panel.js b/libs/panel.js index ffefcd1477f..c1af9ca21df 100644 --- a/libs/panel.js +++ b/libs/panel.js @@ -7,7 +7,6 @@ var path = require('path') var basicAuth = require('basic-auth') const flatten = require('flat') var _ = require('lodash') -const moment = require('moment') const cluster = require('cluster') @@ -343,7 +342,7 @@ Panel.prototype.registerSockets = function (options) { Panel.prototype.sendStreamData = async function (self, socket) { const whenOnline = (await global.cache.when()).online var data = { - uptime: self.getTime(whenOnline, false), + uptime: global.commons.getTime(whenOnline, false), currentViewers: global.api.current.viewers, currentSubscribers: global.api.current.subscribers, currentBits: global.api.current.bits, @@ -362,25 +361,4 @@ Panel.prototype.sendStreamData = async function (self, socket) { socket.emit('stats', data) } -Panel.prototype.getTime = function (time, isChat) { - var now, days, hours, minutes, seconds - now = _.isNull(time) || !time ? {days: 0, hours: 0, minutes: 0, seconds: 0} : moment().preciseDiff(time, true) - if (isChat) { - days = now.days > 0 ? now.days : '' - hours = now.hours > 0 ? now.hours : '' - minutes = now.minutes > 0 ? now.minutes : '' - seconds = now.seconds > 0 ? now.seconds : '' - return { days: days, - hours: hours, - minutes: minutes, - seconds: seconds } - } else { - days = now.days > 0 ? now.days + 'd' : '' - hours = now.hours >= 0 && now.hours < 10 ? '0' + now.hours + ':' : now.hours + ':' - minutes = now.minutes >= 0 && now.minutes < 10 ? '0' + now.minutes + ':' : now.minutes + ':' - seconds = now.seconds >= 0 && now.seconds < 10 ? '0' + now.seconds : now.seconds - return days + hours + minutes + seconds - } -} - module.exports = Panel diff --git a/libs/twitch.js b/libs/twitch.js index c8277f962dc..7a7af25d65e 100644 --- a/libs/twitch.js +++ b/libs/twitch.js @@ -54,8 +54,8 @@ class Twitch { } async uptime (self, sender) { - const when = await self.when() - const time = self.getTime(self.isOnline ? when.online : when.offline, true) + const when = await global.cache.when() + const time = global.commons.getTime(self.isOnline ? when.online : when.offline, true) global.commons.sendMessage(global.translate(self.isOnline ? 'uptime.online' : 'uptime.offline') .replace(/\$days/g, time.days) .replace(/\$hours/g, time.hours) @@ -294,10 +294,10 @@ class Twitch { let users = await global.users.getAll() if (type === 'points' && global.commons.isSystemEnabled('points')) { message = global.translate('top.listPoints').replace(/\$amount/g, 10) - sorted = _.orderBy(_.filter(users, function (o) { return !_.isNil(o.points) && !global.parser.isOwner(o.username) && o.username !== config.settings.bot_username }), 'points', 'desc') + sorted = _.orderBy(_.filter(users, function (o) { return !_.isNil(o.points) && !global.commons.isOwner(o.username) && o.username !== config.settings.bot_username }), 'points', 'desc') } else if (type === 'time') { message = global.translate('top.listWatched').replace(/\$amount/g, 10) - sorted = _.orderBy(_.filter(users, function (o) { return !_.isNil(o.time) && !_.isNil(o.time.watched) && !global.parser.isOwner(o.username) && o.username !== config.settings.bot_username }), 'time.watched', 'desc') + sorted = _.orderBy(_.filter(users, function (o) { return !_.isNil(o.time) && !_.isNil(o.time.watched) && !global.commons.isOwner(o.username) && o.username !== config.settings.bot_username }), 'time.watched', 'desc') } else if (type === 'tips') { sorted = {} message = global.translate('top.listTips').replace(/\$amount/g, 10) @@ -309,7 +309,7 @@ class Twitch { sorted = _.orderBy(sorted, 'amount', 'desc') } else { message = global.translate('top.listMessages').replace(/\$amount/g, 10) - sorted = _.orderBy(_.filter(users, function (o) { return !_.isNil(o.stats) && !_.isNil(o.stats.messages) && !global.parser.isOwner(o.username) && o.username !== config.settings.bot_username }), 'stats.messages', 'desc') + sorted = _.orderBy(_.filter(users, function (o) { return !_.isNil(o.stats) && !_.isNil(o.stats.messages) && !global.commons.isOwner(o.username) && o.username !== config.settings.bot_username }), 'stats.messages', 'desc') } // remove ignored users