Skip to content

Commit

Permalink
core: Fix several function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Apr 3, 2018
1 parent 5a89932 commit dbabb48
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion cluster.js
Expand Up @@ -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})

Expand Down
2 changes: 1 addition & 1 deletion libs/api.js
Expand Up @@ -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 })
}
Expand Down
22 changes: 22 additions & 0 deletions libs/commons.js
Expand Up @@ -3,6 +3,7 @@
var _ = require('lodash')
var chalk = require('chalk')
const debug = require('debug')
const moment = require('moment')

const config = require('../config.json')

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions libs/message.js
Expand Up @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion libs/overlays/stats.js
Expand Up @@ -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,
Expand Down
24 changes: 1 addition & 23 deletions libs/panel.js
Expand Up @@ -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')

Expand Down Expand Up @@ -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,
Expand All @@ -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
10 changes: 5 additions & 5 deletions libs/twitch.js
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit dbabb48

Please sign in to comment.