Skip to content

Commit

Permalink
system/interface: Add dynamic collection getter
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Aug 2, 2018
1 parent 25998b9 commit 23d049c
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 55 deletions.
6 changes: 1 addition & 5 deletions libs/games/duel.js
Expand Up @@ -20,10 +20,6 @@ const ERROR_MINIMAL_BET = '3'

class Duel extends Game {
constructor () {
const collection = {
settings: 'games.duel.settings',
users: 'games.duel.users'
}
const settings = {
timestamp: 0,
cooldown: String(new Date()),
Expand All @@ -32,7 +28,7 @@ class Duel extends Game {
]
}

super({ collection, settings })
super({ settings })

global.configuration.register('duelCooldown', 'gambling.cooldown.duel', 'number', 0)
global.configuration.register('duelDuration', 'gambling.duel.duration', 'number', 5)
Expand Down
6 changes: 1 addition & 5 deletions libs/games/fightme.js
Expand Up @@ -13,18 +13,14 @@ const Game = require('./_interface')

class FightMe extends Game {
constructor () {
const collection = {
settings: 'games.fightme.settings',
users: 'games.fightme.users'
}
const settings = {
cooldown: String(new Date()),
commands: [
'!fightme'
]
}

super({ collection, settings })
super({ settings })

global.configuration.register('fightmeTimeout', 'gambling.fightme.timeout', 'number', 10)
global.configuration.register('fightmeCooldown', 'gambling.cooldown.fightme', 'number', 0)
Expand Down
5 changes: 1 addition & 4 deletions libs/games/gamble.js
Expand Up @@ -18,9 +18,6 @@ const ERROR_MINIMAL_BET = '3'

class Gamble extends Game {
constructor () {
const collection = {
settings: 'games.gamble.settings'
}
const dependsOn = [
'systems.points'
]
Expand All @@ -30,7 +27,7 @@ class Gamble extends Game {
]
}

super({ collection, settings, dependsOn })
super({ settings, dependsOn })

global.configuration.register('gamblingCooldownBypass', 'gambling.cooldown.bypass', 'bool', false)
global.configuration.register('gamblingChanceToWin', 'gambling.gamble.chanceToWin', 'number', 50)
Expand Down
5 changes: 1 addition & 4 deletions libs/games/roulette.js
Expand Up @@ -12,9 +12,6 @@ const Game = require('./_interface')

class Roulette extends Game {
constructor () {
const collection = {
settings: 'games.roulette.settings'
}
const dependsOn = [
'systems.points'
]
Expand All @@ -24,7 +21,7 @@ class Roulette extends Game {
]
}

super({ collection, settings, dependsOn })
super({ settings, dependsOn })

global.configuration.register('rouletteTimeout', 'gambling.roulette.timeout', 'number', 10)
}
Expand Down
5 changes: 1 addition & 4 deletions libs/games/seppuku.js
Expand Up @@ -6,15 +6,12 @@ const Game = require('./_interface')

class Seppuku extends Game {
constructor () {
const collection = {
settings: 'games.seppuku.settings'
}
const settings = {
commands: [
'!seppuku'
]
}
super({collection, settings})
super({settings})

global.configuration.register('seppukuTimeout', 'gambling.seppuku.timeout', 'number', 10)
}
Expand Down
12 changes: 10 additions & 2 deletions libs/systems/_interface.js
Expand Up @@ -6,7 +6,6 @@ const constants = require('../constants')

class System {
constructor (opts) {
this.collection = opts.collection || {}
this.dependsOn = opts.dependsOn || []
this.socket = null

Expand All @@ -15,12 +14,21 @@ class System {
this._parsers = []
this._name = 'systems'

this.collection = new Proxy({}, {
get: (target, name, receiver) => {
if (_.isSymbol(name)) return undefined
let collection = ''
if (name === 'data') collection = `${this._name}.${this.constructor.name.toLowerCase()}`
else collection = `${this._name}.${this.constructor.name.toLowerCase()}.${name}`
return collection
}
})

// populate this._settings
this._prepare(opts.settings)
this._sockets()
this.status()
}

_sockets () {
if (_.isNil(global.panel)) return new Timeout().recursive({ this: this, uid: `${this.constructor.name}.sockets`, wait: 1000, fnc: this._sockets })
else if (cluster.isMaster) {
Expand Down
6 changes: 1 addition & 5 deletions libs/systems/alias.js
Expand Up @@ -22,10 +22,6 @@ const System = require('./_interface')

class Alias extends System {
constructor () {
const collection = {
data: 'systems.alias',
settings: 'systems.alias.settings'
}
const settings = {
commands: [
{name: '!alias add', permission: constants.OWNER_ONLY},
Expand All @@ -40,7 +36,7 @@ class Alias extends System {
{ name: 'run', fireAndForget: true }
]
}
super({ collection, settings })
super({ settings })

this.addMenu({category: 'manage', name: 'aliases', id: 'alias/list'})
}
Expand Down
7 changes: 1 addition & 6 deletions libs/systems/bets.js
Expand Up @@ -36,11 +36,6 @@ const DEBUG_BET_CHECK_IF_EXPIRED = debug('bets:checkIfBetExpired')

class Bets extends System {
constructor () {
const collection = {
data: 'systems.bets',
settings: 'systems.bets.settings',
users: 'systems.bets.users'
}
const dependsOn = [
'systems.points'
]
Expand All @@ -53,7 +48,7 @@ class Bets extends System {
]
}

super({ collection, settings, dependsOn })
super({ settings, dependsOn })

this.timeouts = {}

Expand Down
5 changes: 1 addition & 4 deletions libs/systems/commercial.js
Expand Up @@ -16,16 +16,13 @@ const System = require('./_interface')

class Commercial extends System {
constructor () {
const collection = {
settings: 'systems.commercial.settings'
}
const settings = {
commands: [
{name: '!commercial', permission: constants.OWNER_ONLY, isHelper: true}
]
}

super({ collection, settings })
super({ settings })
}

async main (opts) {
Expand Down
7 changes: 1 addition & 6 deletions libs/systems/cooldown.js
Expand Up @@ -19,11 +19,6 @@ const debug = require('debug')('systems:cooldown')

class Cooldown extends System {
constructor () {
const collection = {
data: 'systems.cooldown',
settings: 'systems.cooldown.settings',
viewers: 'systems.cooldown.viewers'
}
const settings = {
cooldownNotifyAsWhisper: false,
commands: [
Expand All @@ -36,7 +31,7 @@ class Cooldown extends System {
{name: 'check', priority: constants.HIGH}
]
}
super({ collection, settings })
super({ settings })

this.addMenu({category: 'manage', name: 'cooldowns', id: 'cooldown/list'})
}
Expand Down
6 changes: 1 addition & 5 deletions libs/systems/customCommands.js
Expand Up @@ -21,10 +21,6 @@ const System = require('./_interface')

class CustomCommands extends System {
constructor () {
const collection = {
settings: 'systems.customcommands.settings',
data: 'systems.customcommands'
}
const settings = {
commands: [
{ name: '!command add', permission: constants.OWNER_ONLY },
Expand All @@ -39,7 +35,7 @@ class CustomCommands extends System {
{ name: 'run', priority: constants.LOW, fireAndForget: true }
]
}
super({collection, settings})
super({settings})

this.addMenu({category: 'manage', name: 'custom-commands', id: 'customcommands/list'})
}
Expand Down
6 changes: 1 addition & 5 deletions libs/systems/highlights.js
Expand Up @@ -22,17 +22,13 @@ const ERROR_STREAM_NOT_ONLINE = '1'

class Highlights extends System {
constructor () {
const collection = {
data: 'systems.highlights',
settings: 'systems.highlights.settings'
}
const settings = {
commands: [
{ name: '!highlight list', permission: constants.OWNER_ONLY },
{ name: '!highlight', permission: constants.OWNER_ONLY }
]
}
super({collection, settings})
super({settings})

if (cluster.isMaster) {
global.panel.addMenu({category: 'manage', name: 'highlights', id: 'highlights/list'})
Expand Down

0 comments on commit 23d049c

Please sign in to comment.