Skip to content

Commit

Permalink
feat(cvars): add stream variable with current stream values
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Apr 23, 2019
1 parent a1a0557 commit 3cb1b9f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
40 changes: 39 additions & 1 deletion public/pages/registry/customVariables/edit.html
Expand Up @@ -335,7 +335,44 @@
if (_.isNil(textarea)) return setTimeout(() => this.initializeEvalTextArea(), 1)

this.evalInput = CodeMirror(textarea, {
value: this.evalValueInit ? this.evalValueInit : "/* Available functions\n\turl(link) - load data from API\n\tuser(username?: string): Promise<{ username: string, id: string, is: { follower: boolean, mod: boolean, online: boolean, subscriber: boolean, vip: boolean }}> - returns user object (if null -> sender) \n *\n * Available variables: _, _current, users, random, sender (only in custom commands, keyword), param (only in custom command)\n *\n * IMPORTANT: Must contain return statement!\n */\n\nreturn '';",
value: this.evalValueInit ||
`/* Available functions
url(link) - load data from API
user(username?: string): Promise<{ username: string, id: string, is: { follower: boolean, mod: boolean, online: boolean, subscriber: boolean, vip: boolean }}> - returns user object (if null -> sender)
*
* Available variables
_, _current, users, sender (only in custom commands, keyword), param (only in custom command)
random: {
online: {
viewer: string,
follower: string,
subscriber: string
},
viewer: string,
follower: string,
subscriber: string
}
stream: {
uptime: string,
chatMessages: number,
currentViewers: number,
currentBits: number,
currentFollowers: number,
currentHosts: number,
currentViews: number,
currentTips: number,
currentWatched: number,
currency: string,
maxViewers: number,
newChatters: number,
game: string,
status: string
}
*
* IMPORTANT: Must contain return statement!
*/
return '';`,
mode: "javascript",
lineNumbers: true,
matchBrackets: true,
Expand All @@ -344,6 +381,7 @@
},
gutters: ["CodeMirror-lint-markers"]
})
this.evalInput.setSize(null, 1000);
},
isUnique: function () {
if (this.variableName !== this.variableNameInitial) {
Expand Down
39 changes: 39 additions & 0 deletions src/bot/customvariables.js
Expand Up @@ -174,6 +174,45 @@ class CustomVariables {
_: _,
users: users,
random: randomVar,
stream: {
uptime: commons.getTime((await global.cache.when()).online, false),
currentViewers: _.get((await global.db.engine.findOne('api.current', {
key: 'viewers'
})), 'value', 0),
currentSubscribers: _.get((await global.db.engine.findOne('api.current', {
key: 'subscribers'
})), 'value', 0),
currentBits: _.get((await global.db.engine.findOne('api.current', {
key: 'bits'
})), 'value', 0),
currentTips: _.get((await global.db.engine.findOne('api.current', {
key: 'tips'
})), 'value', 0),
currency: global.currency.symbol(global.currency.settings.currency.mainCurrency),
chatMessages: (await global.cache.isOnline()) ? global.linesParsed - global.api.chatMessagesAtStart : 0,
currentFollowers: _.get((await global.db.engine.findOne('api.current', {
key: 'followers'
})), 'value', 0),
currentViews: _.get((await global.db.engine.findOne('api.current', {
key: 'views'
})), 'value', 0),
maxViewers: _.get((await global.db.engine.findOne('api.max', {
key: 'viewers'
})), 'value', 0),
newChatters: _.get((await global.db.engine.findOne('api.new', {
key: 'chatters'
})), 'value', 0),
game: _.get((await global.db.engine.findOne('api.current', {
key: 'game'
})), 'value', null),
status: _.get((await global.db.engine.findOne('api.current', {
key: 'title'
})), 'value', null),
currentHosts: _.get((await global.db.engine.findOne('api.current', {
key: 'hosts'
})), 'value', 0),
currentWatched: global.api._stream.watchedTime
},
sender,
param: param,
_current: opts._current,
Expand Down

0 comments on commit 3cb1b9f

Please sign in to comment.