init commit

This commit is contained in:
zino
2021-02-16 23:07:41 +01:00
parent ec3fc78e0f
commit 12b4ef5db4
5000 changed files with 2596132 additions and 0 deletions

View File

@@ -0,0 +1,316 @@
/*
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Function that querys all of the data we need.
$(function () {
// Chart configs. This should not be changed.
let chartConfig = {"type": "doughnut", "data": {"datasets": [{"data": [], "backgroundColor": []}], "labels": []}, "options": {"responsive": false, "title": {"display": true}}},
chartContext = $('#betting-chart').get(0).getContext('2d'),
chart = new Chart(chartContext, chartConfig),
isActive = false;
/*
* @function Inits the chart.
*/
const initChart = function () {
socket.getDBValues('get_betting_options', {
tables: ['bettingPanel', 'bettingPanel'],
keys: ['options', 'title']
}, true, function (e) {
if (e.options !== null) {
socket.getDBTableValues('get_betting_votes', 'bettingVotes', function (votes) {
// Set the chart title.
chartConfig.options.title.text = e.title;
// Set the labels.
chartConfig.data.labels = e.options.split('%space_option%');
// Get all the data.
let ops = e.options.split('%space_option%');
for (let i = 0; i < ops.length; i++) {
if (ops[i].indexOf(' ') !== -1) {
ops[i] = ops[i].split(' ').join('%space_option%');
}
for (let j = 0; j < votes.length; j++) {
if (votes[j].key === ops[i]) {
chartConfig.data.datasets[0].data.push(parseInt(votes[j].value));
chartConfig.data.datasets[0].backgroundColor.push(helpers.getRandomRgbColor());
}
}
}
// Update the chart.
chart.update();
// Mark as active.
isActive = true;
});
}
});
};
initChart();
/*
* @function Updates the chart during a bet.
*/
const updateChart = function () {
socket.getDBValue('get_betting_active_update', 'bettingPanel', 'isActive', function (e) {
if (e.bettingPanel === 'false' || e.bettingPanel === null) {
isActive = false;
return;
} else if (chartConfig.data.datasets[0].backgroundColor.length !== 0 && isActive === false) {
resetChart();
}
// No current chart is done, start a new one.
if (chartConfig.data.datasets[0].backgroundColor.length === 0) {
initChart();
return;
}
socket.getDBValue('get_betting_options_update', 'bettingPanel', 'options', function (e) {
socket.getDBTableValues('get_betting_votes_update', 'bettingVotes', function (votes) {
// Get all the data.
let ops = e.bettingPanel.split('%space_option%');
// Remove current data.
chartConfig.data.datasets[0].data = [];
for (let i = 0; i < ops.length; i++) {
if (ops[i].indexOf(' ') !== -1) {
ops[i] = ops[i].split(' ').join('%space_option%');
}
for (let j = 0; j < votes.length; j++) {
if (votes[j].key === ops[i]) {
chartConfig.data.datasets[0].data.push(parseInt(votes[j].value));
}
}
}
// Update the chart.
chart.update();
});
});
});
};
/*
* @function Resets the bet.
*
* @param {Function} callback
*/
const resetBet = function (callback) {
socket.removeDBValues('reset_betting_options', {
tables: ['bettingPanel', 'bettingPanel'],
keys: ['options', 'isActive']
}, function () {
// Reset the chart.
resetChart();
// Update the chart.
chart.update();
// Alert the user.
toastr.success('Successfully reset the bet.');
// Callback if possible.
if (typeof callback === 'function') {
callback();
}
});
};
/*
* @function Resets the chart.
*/
const resetChart = function () {
// Mark as not acive.
isActive = false;
// Reset the title.
chartConfig.options.title.text = '';
// Reset lables.
chartConfig.data.labels = [];
// Reset the data.
chartConfig.data.datasets[0].data = [];
// Reset the colors.
chartConfig.data.datasets[0].backgroundColor = [];
};
// Reset bet button.
$('#reset-betting').on('click', function () {
helpers.getModal('betting-reset', 'Reset Bet', 'Reset', $('<form/>', {
'role': 'form'
})
// Add refund option
.append(helpers.getCheckBox('bet-refund', false, 'Refund all bets',
'if everyone who placed a bet should get their points back.')),
function () {
resetBet();
if (isActive) {
socket.sendCommand('reset_end_bet_cmd', 'bet reset' + ($('#bet-refund').prop('checked') === true ? ' -refund' : ''), new Function());
isActive = false;
}
$('#betting-reset').modal('toggle');
}).modal('toggle');
});
// Close bet button
$('#close-betting').on('click', function () {
helpers.getModal('betting-close', 'Close Bet', 'Close', $('<form/>', {
'role': 'form'
})
// Append options.
.append(helpers.getInputGroup('bet-winning', 'text', 'Winning Option', 'Option that won the bet. Leave this empty to just close the bet and pick a winning option later.', '',
'Option that won the bet. Leave this empty to just close the bet and pick a winning option later.')),
function () {
socket.sendCommand('close_bet_cmd', 'bet close ' + $('#bet-winning').val(), function () {
toastr.success('Successfully closed the bet.');
$('#betting-close').modal('toggle');
});
}).modal('toggle');
});
// Open bet button.
$('#open-betting').on('click', function () {
helpers.getModal('betting-open', 'Open Bet', 'Open', $('<form/>', {
'role': 'form'
})
// Append bet title.
.append(helpers.getTextAreaGroup('bet-title', 'text', 'Title', 'Which team is going to win?', '', 'Title of the bet.'))
// Append options.
.append(helpers.getInputGroup('bet-options', 'text', 'Options', 'Red, Blue', '',
'Options to be betted on. Each option should be seperated with a comma and space.'))
// Append min bet.
.append(helpers.getInputGroup('bet-min', 'number', 'Minimum Bet', '', '1',
'What is the minimum amount of points users can bet on an option.'))
// Append max bet.
.append(helpers.getInputGroup('bet-max', 'number', 'Maximum Bet', '', '0',
'What is the maximum amount of points users can bet on an option. 0 removes the limit.'))
// Append min bet.
.append(helpers.getInputGroup('bet-timer', 'number', 'Timer (Minutes)', '', '0',
'Timer in minutes of how long the bet will be opened for. 0 means until closed.')),
function () {
let title = $('#bet-title'),
options = $('#bet-options'),
minBet = $('#bet-min'),
maxBet = $('#bet-max'),
timer = $('#bet-timer');
switch (false) {
case helpers.handleInputString(title):
case helpers.handleInputString(options):
case helpers.handleInputNumber(minBet, 1):
case helpers.handleInputNumber(maxBet, 0):
case helpers.handleInputNumber(timer, 0):
break;
default:
socket.sendCommandSync('bet_open_cmd', 'bet open "' + title.val() + '" "' + options.val() + '" ' +
minBet.val() + ' ' + maxBet.val() + ' ' + timer.val(), function () {
// Alert the user.
toastr.success('Successfully opened the bet!');
// Close the modal.
$('#betting-open').modal('toggle');
// Update the chart.
updateChart();
});
}
}).modal('toggle');
});
// Settings button.
$('#settings-betting').on('click', function () {
socket.getDBValues('get_bet_settings', {
tables: ['bettingSettings', 'bettingSettings', 'bettingSettings', 'bettingSettings'],
keys: ['gain', 'save', 'format', 'warningMessages']
}, true, function (e) {
helpers.getModal('betting-settings', 'Bet Settings', 'Save', $('<form/>', {
'role': 'form'
})
// Append a select option for the save option
.append(helpers.getDropdownGroup('save-bets', 'Save Bets', (e.save === 'true' ? 'Yes' : 'No'), ['Yes', 'No'],
'If past bets should be saved.'))
// Append a select option for the warning messages
.append(helpers.getDropdownGroup('warning-bets', 'Warning Messages', (e.warningMessages === 'true' ? 'Yes' : 'No'), ['Yes', 'No'],
'If warning messages should be said in chat when users bet.'))
// Save format
.append(helpers.getInputGroup('bet-format', 'text', 'Save Format', '', e.format,
'In which date format should bets be saved.'))
// Save format
.append(helpers.getInputGroup('bet-gain', 'text', 'Winning Gain (Percent)', '', e.gain,
'The percent of points the user gets from the entire amount of points betted on the winning option. The amount betted is always returned.')),
function () {
let saveBets = $('#save-bets').find(':selected').text() === 'Yes',
warningMessages = $('#warning-bets').find(':selected').text() === 'Yes',
gain = $('#bet-gain'),
format = $('#bet-format');
switch (false) {
case helpers.handleInputNumber(gain, 1, 100):
case helpers.handleInputString(format):
break;
default:
socket.updateDBValues('bet_settings_update', {
tables: ['bettingSettings', 'bettingSettings', 'bettingSettings', 'bettingSettings'],
keys: ['gain', 'save', 'format', 'warningMessages'],
values: [gain.val(), saveBets, format.val(), warningMessages]
}, function () {
socket.sendCommand('bet_settings_update_cmd', 'reloadbet', function () {
// Alert user.
toastr.success('Successfully updated bet settings!');
// Close modal.
$('#betting-settings').modal('toggle');
})
});
}
}).modal('toggle');
});
});
// Module toggle.
$('#bettingSystemModuleToggle').on('change', function () {
socket.sendCommandSync('betting_system_module_toggle_cmd',
'module ' + ($(this).is(':checked') ? 'enablesilent' : 'disablesilent') + ' ./systems/bettingSystem.js', run);
});
// Update the chart every 5 seconds.
helpers.setInterval(updateChart, 5e3);
});
// Handles the module toggle.
$(run = function () {
socket.getDBValue('betting_module_status', 'modules', './systems/bettingSystem.js', function (e) {
if (!helpers.handleModuleLoadUp('bettingSystemModule', e.modules)) {
// Remove the chat.
$('#twitch-chat-betting').find('iframe').remove();
return;
}
if (location.protocol.toLowerCase().startsWith('https') && !(location.port > 0 && location.port !== 443)) {
// Add Twitch chat.
$('#twitch-chat-betting').html($('<iframe/>', {
'frameborder': '0',
'scrolling': 'no',
'style': 'width: 100%; height: 561px; margin-bottom: -5px;',
'src': 'https://www.twitch.tv/embed/' + getChannelName() + '/chat' + (helpers.isDark ? '?darkpopout&' : '?') + 'parent=' + location.hostname
}));
} else {
$('#twitch-chat-betting').html('Due to changes by Twitch, the chat panel can no longer be displayed unless you enable SSL on the PhantomBot Panel and change the baseport to 443. This may not work without root privileges.<br /><br />Alternatively, you can login using the GitHub version of the panel at <a href="https://phantombot.github.io/PhantomBot/">PhantomBot - GitHub.io</a> which gets around this issue.<br /><br />For help setting up SSL, please see <a href="https://phantombot.github.io/PhantomBot/guides/#guide=content/integrations/twitchembeds">this guide</a>.');
$('#twitch-chat-betting').addClass('box-body');
}
});
});

View File

@@ -0,0 +1,85 @@
/*
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Function that querys all of the data we need.
$(run = function() {
// Check if the module is enabled.
socket.getDBValues('commercials_module', {
tables: ['modules', 'commercialSettings', 'commercialSettings', 'commercialSettings', 'commercialSettings'],
keys: ['./systems/commercialSystem.js', 'commercialtimer', 'length', 'interval', 'message']
}, true, function(e) {
if (!helpers.handleModuleLoadUp('commercialsModule', e['./systems/commercialSystem.js'], 'commercialsModuleToggle')) {
return;
}
if (e['commercialtimer'] === 'true') {
$('#commercials-autotimer-on').html($('<i/>', {
'class': 'fa fa-check'
})).append('&nbsp; Update Autotimer');
$('#commercials-autotimer-off').removeClass('hidden');
}
$('#commercial-interval').val(e['interval']);
$('#commercial-length').val(e['length']);
$('#commercial-message').val(e['message']);
});
});
// Function that handlers the loading of events.
$(function() {
const COMMERCIAL_SCRIPT = './systems/commercialSystem.js';
// Toggle for the module.
$('#commercialsModuleToggle').on('change', function() {
// Toggle the module
socket.sendCommandSync('commercial_module_toggle_cmd',
'module ' + ($(this).is(':checked') ? 'enablesilent' : 'disablesilent') + ' ./systems/commercialSystem.js', run);
});
// Set/Update autotimer button.
$('#commercials-autotimer-on').on('click', function() {
let cinterval = $('#commercial-interval'),
clength = $('#commercial-length').find(':selected').text(),
cmessage = $('#commercial-message');
switch (false) {
case helpers.handleInputNumber(cinterval, 8):
break;
default:
socket.wsEvent('commercials_setautotimer_ws', COMMERCIAL_SCRIPT, null, ['setautotimer', cinterval.val(), clength, cmessage.val()], function() {
toastr.success('Successfully set the autotimer!');
// Update the button.
$('#commercials-autotimer-on').html($('<i/>', {
'class': 'fa fa-check'
})).append('&nbsp; Update Autotimer');
$('#commercials-autotimer-off').removeClass('hidden');
});
}
});
// Disable autotimer button.
$('#commercials-autotimer-off').on('click', function() {
socket.wsEvent('commercials_autotimeroff_ws', COMMERCIAL_SCRIPT, null, ['autotimeroff'], function() {
toastr.success('Successfully turned off autotimer!');
// Update the button.
$('#commercials-autotimer-on').html($('<i/>', {
'class': 'fa fa-check'
})).append('&nbsp; Set Autotimer');
$('#commercials-autotimer-off').addClass('hidden');
});
});
});

View File

@@ -0,0 +1,186 @@
/*
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Function that querys all of the data we need.
$(run = function() {
// Check if the module is enabled.
socket.getDBValue('death_counter_module', 'modules', './commands/deathctrCommand.js', function(e) {
// If the module is off, don't load any data.
if (!helpers.handleModuleLoadUp('deathCounterModule', e.modules)) {
return;
}
// Get current game.
socket.getDBValue('get_current_stream_info', 'panelData', 'stream', function(e) {
socket.getDBValue('get_death_count', 'deaths', JSON.parse(e.panelData).game, function(e) {
$('#death-number').html(helpers.parseNumber(helpers.getDefaultIfNullOrUndefined(e.deaths, '0')));
});
});
});
});
// Function that handlers the loading of events.
$(function() {
var canUpdate = true;
// Toggle for the module.
$('#deathCounterModuleToggle').on('change', function() {
let toggle = $(this).is(':checked');
canUpdate = toggle;
// Enable the module then query the data.
socket.sendCommandSync('death_counter_module_toggle_cmd',
'module ' + (toggle ? 'enablesilent' : 'disablesilent') + ' ./commands/deathctrCommand.js', run);
});
// Increase death button.
$('#incr-deaths-button').on('click', function() {
// Don't update deaths until new value is set.
canUpdate = false;
// Get current game.
socket.getDBValue('get_current_stream_info', 'panelData', 'stream', function(e) {
// Increase the deaths.
socket.incrDBValue('incr_deaths_1', 'deaths', JSON.parse(e.panelData).game, '1', function() {
// Set the new number.
$('#death-number').html(helpers.parseNumber(parseInt($('#death-number').html().replace(/,/g, '')) + 1));
// New value is set so we can let the updates work.
canUpdate = true;
});
});
});
// Increase death button.
$('#decr-deaths-button').on('click', function() {
// Don't update deaths until new value is set.
canUpdate = false;
let deaths = parseInt($('#death-number').html().replace(/,/g, ''));
// Make sure we don't go into the negatives.
if (deaths < 1) {
return;
}
// Get current game.
socket.getDBValue('get_current_stream_info', 'panelData', 'stream', function(e) {
// Decrease the deaths.
socket.decrDBValue('decr_deaths_1', 'deaths', JSON.parse(e.panelData).game, '1', function() {
// Set the new number
$('#death-number').html(helpers.parseNumber(deaths - 1));
// New value is set so we can let the updates work.
canUpdate = true;
});
});
});
// Reset button.
$('#reset-deaths-button').on('click', function() {
// Don't update deaths until new value is set.
canUpdate = false;
// Get current game.
socket.getDBValue('get_current_stream_info', 'panelData', 'stream', function(e) {
// Delete deaths.
socket.removeDBValue('rm_deaths_game', 'deaths', JSON.parse(e.panelData).game, function() {
// Set the new number.
$('#death-number').html('0');
// New value is set so we can let the updates work.
canUpdate = true;
});
});
});
// Settings button.
$('#settings-deaths-button').on('click', function() {
// Create custom modal for this module.
helpers.getModal('death-settings', 'Death Counter Settings', 'Save', $('<form/>', {
'role': 'form'
})
// Main div for the browser source link.
.append($('<div/>', {
'class': 'form-group',
})
// Append the lable.
.append($('<label/>', {
'text': 'Browser Source Link'
}))
.append($('<div/>', {
'class': 'input-group'
})
// Add client widget URL.
.append($('<input/>', {
'type': 'text',
'class': 'form-control',
'id': 'death-url',
'readonly': 'readonly',
'value': window.location.protocol + '//' + window.location.host + '/addons/deathctr/deathctr.txt?refresh=true&webauth=' + getAuth(),
'style': 'color: transparent !important; text-shadow: 0 0 5px hsla(0, 0%, 100%, .5);',
'data-toggle': 'tooltip',
'title': 'Clicking this box will show the link. DO NOT share this link with anyone as it has sensitive information.',
'click': function() {
// Reset styles.
$(this).prop('style', '');
}
})).append($('<span/>', {
'class': 'input-group-btn',
'html': $('<button/>', {
'type': 'button',
'class': 'btn btn-primary btn-flat',
'html': 'Copy',
'click': function() {
// Select URL.
$('#death-url').select();
// Copy the URL.
document.execCommand('Copy');
}
})
}))))
// Append box with current deaths.
.append(helpers.getInputGroup('deaths-t', 'number', 'Death Total', '',
$('#death-number').html().replace(/,/g, ''), 'How many deaths to set on the counter.')),
function() { // callback.
let deaths = $('#deaths-t');
switch (false) {
case helpers.handleInputNumber(deaths, 0):
break;
default:
// Update the death number.
$('#death-number').html(helpers.parseNumber(deaths.val()));
// Get current game.
socket.getDBValue('get_current_stream_info', 'panelData', 'stream', function(e) {
// Delete deaths.
socket.updateDBValue('update_deaths_game', 'deaths', JSON.parse(e.panelData).game, deaths.val(), function() {
// Close the modal.
$('#death-settings').modal('toggle');
// Alert the user.
toastr.success('Successfully updated death counter settings!');
});
});
}
}).modal('toggle');
});
// Timer that updates deaths every 10 seconds.
helpers.setInterval(function() {
if (canUpdate) {
run();
}
}, 10e3);
});

View File

@@ -0,0 +1,126 @@
/*
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Function that querys all of the data we need.
$(run = function() {
// Check if the module is enabled.
socket.getDBValue('dual_stream_command_module', 'modules', './commands/dualstreamCommand.js', function(e) {
// If the module is off, don't load any data.
if (!helpers.handleModuleLoadUp('dualStreamModule', e.modules)) {
return;
}
// Get the URL.
socket.getDBValue('get_multi_link', 'dualStreamCommand', 'otherChannels', function(e) {
let channels = e.dualStreamCommand;
if (channels.indexOf('Channel-1') === -1) {
$('#multi-channels').val(channels.split(' ').join('/'));
}
$('#multi-main').html('https://multistre.am/' + getChannelName() + '/');
});
});
});
// Function that handlers the loading of events.
$(function() {
// Toggle for the module.
$('#dualStreamModuleToggle').on('change', function() {
// Enable the module then query the data.
socket.sendCommandSync('dual_stream_command_module_toggle_cmd',
'module ' + ($(this).is(':checked') ? 'enablesilent' : 'disablesilent') + ' ./commands/dualstreamCommand.js', run);
});
// Clip url update.
$('#multi-channels').on('focusout', function() {
let channels = $('#multi-channels').val();
// If the box is empty, set the default channels.
if (channels.length < 1) {
channels = 'Channel-1 Channel-2';
} else {
channels = channels.split('/').join(' ');
}
// Update the channels.
socket.updateDBValue('update_multi_channels', 'dualStreamCommand', 'otherChannels', channels, function() {
socket.sendCommand('update_multi_channels_cmd', 'reloadmulti', function() {
toastr.success('Successfully updated the multi channels!');
});
});
});
// Copy button.
$('#dualstream-copy-btn').on('click', function() {
let old = $('#multi-channels').val();
// Copy text.
$('#multi-channels').val('https://multistre.am/' + getChannelName() + '/' + old).select();
// Copy the text.
document.execCommand('Copy');
// Set back the old text.
$('#multi-channels').val(old);
});
// Settings button.
$('#dualstream-settings-button').on('click', function() {
socket.getDBValues('get_multi_settings', {
tables: ['dualStreamCommand', 'dualStreamCommand', 'dualStreamCommand'],
keys: ['timerToggle', 'timerInterval', 'reqMessages']
}, true, function(e) {
helpers.getModal('dualstream-settings', 'Dual Stream Settings', 'Save', $('<form/>', {
'role': 'form'
})
// Append a select option for the toggle.
.append(helpers.getDropdownGroup('multi-toggle', 'Enable Multi Timer',
(e.timerToggle === 'true' ? 'Yes' : 'No'), ['Yes', 'No']))
// Timer interval.
.append(helpers.getInputGroup('multi-interval', 'text', 'Timer Interval (Minutes)',
'', e.timerInterval, 'How often to post the multi link in the channel.'))
// Req messages.
.append(helpers.getInputGroup('multi-req', 'text', 'Required Messages',
'', e.reqMessages, 'How many messages along with the timer required to trigger the multi link.')),
function() { // Callback for when the user clicks save.
let timerToggle = $('#multi-toggle').find(':selected').text() === 'Yes',
timerInterval = $('#multi-interval'),
timerReq = $('#multi-req');
switch (false) {
case helpers.handleInputNumber(timerInterval, 1):
case helpers.handleInputNumber(timerReq, 1):
break;
default:
socket.updateDBValues('update_multi_settings', {
tables: ['dualStreamCommand', 'dualStreamCommand', 'dualStreamCommand'],
keys: ['timerToggle', 'timerInterval', 'reqMessages'],
values: [timerToggle, timerInterval.val(), timerReq.val()]
}, function() {
socket.sendCommand('update_multi_settings_cmd', 'reloadmulti', function() {
// Close the modal.
$('#dualstream-settings').modal('toggle');
// Alert the user.
toastr.success('Successfully updated multi settings!');
});
});
}
}).modal('toggle');
});
});
});

View File

@@ -0,0 +1,187 @@
/*
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Function that querys all of the data we need.
$(run = function() {
// Check if the module is enabled.
socket.getDBValue('highlight_command_module', 'modules', './commands/highlightCommand.js', function(e) {
// If the module is off, don't load any data.
if (!helpers.handleModuleLoadUp('highlightsModule', e.modules)) {
return;
}
// Get all highlights.
socket.getDBTableValues('get_highlights', 'highlights', function(results) {
let tableData = [];
for (let i = 0; i < results.length; i++) {
let date = new Date(helpers.getEpochFromDate(results[i].key.substring(0, results[i].key.indexOf(' ')), true)),
url = results[i].value.substring(0, results[i].value.indexOf(' :')),
comment = results[i].value.substring(results[i].value.indexOf(': ') + 2, results[i].value.length);
tableData.push([
date.toLocaleDateString(),
$('<a/>', {
'text': url,
'href': url,
'target': '_blank'
})[0].outerHTML,
comment,
$('<div/>', {
'class': 'btn-group'
}).append($('<button/>', {
'type': 'button',
'class': 'btn btn-xs btn-danger',
'style': 'float: right',
'data-key': results[i].key,
'html': $('<i/>', {
'class': 'fa fa-trash'
})
})).append($('<button/>', {
'type': 'button',
'class': 'btn btn-xs btn-warning',
'style': 'float: right',
'data-key': results[i].key,
'html': $('<i/>', {
'class': 'fa fa-edit'
})
})).html()
]);
}
// if the table exists, destroy it.
if ($.fn.DataTable.isDataTable('#highlightsTable')) {
$('#highlightsTable').DataTable().destroy();
// Remove all of the old events.
$('#highlightsTable').off();
}
// Create table.
let table = $('#highlightsTable').DataTable({
'searching': true,
'autoWidth': false,
'lengthChange': false,
'data': tableData,
'columnDefs': [
{ 'className': 'default-table', 'orderable': false, 'targets': 3 },
{ 'width': '7%', 'targets': 0 },
{ 'width': '25%', 'targets': 1 }
],
'columns': [
{ 'title': 'Date' },
{ 'title': 'URL' },
{ 'title': 'Comment' },
{ 'title': 'Actions' }
]
});
// On delete button.
table.on('click', '.btn-danger', function() {
let key = $(this).data('key'),
row = $(this).parents('tr');
// Ask the user if he wants to delete the highlight.
helpers.getConfirmDeleteModal('highlight_modal_remove', 'Are you sure you want to remove this highlight?', true,
'The highlight has been successfully removed!', function() { // Callback if the user clicks delete.
// Remove the highlight.
socket.removeDBValue('highlight_remove', 'highlights', key, function() {
// Remove the table row.
table.row(row).remove().draw(false);
});
});
});
// On edit button.
table.on('click', '.btn-warning', function() {
let key = $(this).data('key'),
t = $(this);
socket.getDBValue('get_highlight_edit', 'highlights', key, function(e) {
let spl = e.highlights.replace(/\s/, '').split(': ');
helpers.getModal('edit-highlight', 'Edit Highlight', 'Save', $('<form/>', {
'role': 'form'
})
// Append highlight text box.
.append(helpers.getTextAreaGroup('highlight-text', 'text', 'Highlight', '', spl[1],
'Comment to give to the current highlight.', false)),
function() {
let highlight = $('#highlight-text');
switch (false) {
case helpers.handleInputString(highlight):
break;
default:
spl[1] = highlight.val();
socket.updateDBValue('update_highlight', 'highlights', key, spl.join(' : '), function() {
// Update the table.
t.parents('tr').find('td:eq(2)').text(spl[1]);
// Close the modal.
$('#edit-highlight').modal('toggle');
// Alert the user.
toastr.success('Successfully edited the highlight.');
});
}
}).modal('toggle');
});
});
});
});
});
// Function that handlers the loading of events.
$(function() {
// Toggle for the module.
$('#highlightsModuleToggle').on('change', function() {
// Enable the module then query the data.
socket.sendCommandSync('highlight_module_toggle_cmd',
'module ' + ($(this).is(':checked') ? 'enablesilent' : 'disablesilent') + ' ./commands/highlightCommand.js', run);
});
// Delete all highlights button.
$('#delete-highlights-button').on('click', function() {
// Ask the user if he want to remove all highlights.
helpers.getConfirmDeleteModal('highlights_modal_remove', 'Are you sure you want to remove all highlights?', false,
'Successfully remove all highlights!', function() {
socket.sendCommandSync('rm_all_highlights_cmd', 'clearhighlightspanel', run);
});
});
// Add highlight.
$('#add-highlight-button').on('click', function() {
helpers.getModal('add-highlight', 'Add Highlight', 'Save', $('<form/>', {
'role': 'form'
})
// Append highlight text box.
.append(helpers.getTextAreaGroup('highlight-text', 'text', 'Highlight', 'PogChamp moment.', '',
'Comment to give to the current highlight. This only works while the stream is online.', false)),
function() { // Callback for when the user clicks save.
let highlight = $('#highlight-text');
switch (false) {
case helpers.handleInputString(highlight):
break;
default:
socket.sendCommandSync('add_highlight_cmd', 'highlight ' + highlight.val(), function() {
toastr.success('Successfully created a new highlight!');
});
$('#add-highlight').modal('toggle');
}
}).modal('toggle');
});
});

View File

@@ -0,0 +1,241 @@
/*
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Function that querys all of the data we need.
$(function () {
// Chart configs. This should not be changed.
let chartConfig = {"type": "pie", "data": {"datasets": [{"data": [], "backgroundColor": []}], "labels": []}, "options": {"responsive": false, "title": {"display": true}}},
chartContext = $('#poll-chart').get(0).getContext('2d'),
chart = new Chart(chartContext, chartConfig),
isActive = false;
/*
* @function Inits the chart.
*/
const initChart = function () {
socket.getDBValues('get_poll_options', {
tables: ['pollPanel', 'pollPanel'],
keys: ['options', 'title']
}, true, function (e) {
if (e.options !== null) {
socket.getDBTableValues('get_poll_votes', 'pollVotes', function (votes) {
// Set the chart title.
chartConfig.options.title.text = e.title;
// Set the labels.
chartConfig.data.labels = e.options.split(',');
// Get all the data.
let ops = e.options.split(',');
for (let i = 0; i < ops.length; i++) {
for (let j = 0; j < votes.length; j++) {
if (votes[j].key === ops[i]) {
chartConfig.data.datasets[0].data.push(parseInt(votes[j].value));
chartConfig.data.datasets[0].backgroundColor.push(helpers.getRandomRgbColor());
}
}
}
// Update the chart.
chart.update();
// Mark as active.
isActive = true;
});
}
});
};
// Init the chart here.
initChart();
/*
* @function Updates the chart during a poll.
*/
const updateChart = function () {
socket.getDBValue('get_poll_active_update', 'pollPanel', 'isActive', function (e) {
if (e.pollPanel === 'false' || e.pollPanel === null) {
isActive = false;
return;
} else if (chartConfig.data.datasets[0].backgroundColor.length !== 0 && isActive === false) {
resetChart();
}
// No current chart is done, start a new one.
if (chartConfig.data.datasets[0].backgroundColor.length === 0) {
initChart();
return;
}
socket.getDBValue('get_poll_options_update', 'pollPanel', 'options', function (e) {
socket.getDBTableValues('get_poll_votes_update', 'pollVotes', function (votes) {
// Get all the data.
let ops = e.pollPanel.split(',');
// Remove current data.
chartConfig.data.datasets[0].data = [];
for (let i = 0; i < ops.length; i++) {
for (let j = 0; j < votes.length; j++) {
if (votes[j].key === ops[i]) {
chartConfig.data.datasets[0].data.push(parseInt(votes[j].value));
}
}
}
// Update the chart.
chart.update();
});
});
});
};
/*
* @function Resets the poll.
*
* @param {Function} callback
*/
const resetPoll = function (callback) {
socket.removeDBValues('reset_poll_options', {
tables: ['pollPanel', 'pollPanel'],
keys: ['options', 'isActive']
}, function () {
// Reset the chart.
resetChart();
// Update the chart.
chart.update();
// Alert the user.
toastr.success('Successfully reset the poll.');
// Callback if possible.
if (typeof callback === 'function') {
callback();
}
});
};
/*
* @function Resets the chart.
*/
const resetChart = function () {
// Mark as not acive.
isActive = false;
// Reset the title.
chartConfig.options.title.text = '';
// Reset lables.
chartConfig.data.labels = [];
// Reset the data.
chartConfig.data.datasets[0].data = [];
// Reset the colors.
chartConfig.data.datasets[0].backgroundColor = [];
};
// Reset poll button.
$('#reset-poll').on('click', function () {
resetPoll();
if (isActive) {
socket.sendCommand('reset_end_poll_cmd', 'poll close', new Function());
isActive = false;
}
});
// Close poll button.
$('#close-poll').on('click', function () {
socket.sendCommand('end_poll_cmd', 'poll close', function () {
// Mark as not acive.
isActive = false;
// Alert the user.
toastr.success('Successfully ended the poll.');
});
});
// Open poll button.
$('#open-poll').on('click', function () {
helpers.getModal('poll-open', 'Open Poll', 'Open', $('<form/>', {
'role': 'form'
})
// Append poll title.
.append(helpers.getTextAreaGroup('poll-title', 'text', 'Title', 'What is your favorite color?', '', 'Title of the poll.'))
// Append options.
.append(helpers.getInputGroup('poll-options', 'text', 'Options', 'Red, Green, Blue', '',
'Options to be voted on. Each option should be seperated with a comma and space.'))
// Append timer.
.append(helpers.getInputGroup('poll-timer', 'number', 'Timer (Seconds)', '', '0',
'How long in seconds the poll will be opened for. Default is until closed.'))
// Append min votes.
.append(helpers.getInputGroup('poll-votes', 'number', 'Minimum Votes', '', '1',
'How many votes it takes to choose a winning option. Default is one.')),
function () { // callback function.
let title = $('#poll-title'),
options = $('#poll-options'),
timer = $('#poll-timer'),
votes = $('#poll-votes');
switch (false) {
case helpers.handleInputString(title):
case helpers.handleInputString(options):
case helpers.handleInputNumber(timer, 0):
case helpers.handleInputNumber(votes, 1):
break;
default:
// Reset the chart.
resetChart();
// Open the poll.
socket.sendCommand('open_poll_cmd',
'poll open "' + title.val() + '" "' + options.val() + '" ' + timer.val() + ' ' + votes.val(), function () {
// Close the modal.
$('#poll-open').modal('toggle');
// Alert the user.
toastr.success('Successfully opened the poll!');
});
}
}).modal('toggle');
});
// Module toggle.
$('#pollSystemModuleToggle').on('change', function () {
socket.sendCommandSync('poll_system_module_toggle_cmd',
'module ' + ($(this).is(':checked') ? 'enablesilent' : 'disablesilent') + ' ./systems/pollSystem.js', run);
});
// Update the chart every 5 seconds.
helpers.setInterval(updateChart, 5e3);
});
// Handles the module toggle.
$(run = function () {
socket.getDBValue('poll_module_status', 'modules', './systems/pollSystem.js', function (e) {
if (!helpers.handleModuleLoadUp('pollSystemModule', e.modules)) {
// Remove the chat.
$('#twitch-chat-poll').find('iframe').remove();
return;
}
if (location.protocol.toLowerCase().startsWith('https') && !(location.port > 0 && location.port !== 443)) {
// Add Twitch chat.
$('#twitch-chat-poll').html($('<iframe/>', {
'frameborder': '0',
'scrolling': 'no',
'style': 'width: 100%; height: 561px; margin-bottom: -5px;',
'src': 'https://www.twitch.tv/embed/' + getChannelName() + '/chat' + (helpers.isDark ? '?darkpopout&' : '?') + 'parent=' + location.hostname
}));
} else {
$('#twitch-chat-poll').html('Due to changes by Twitch, the chat panel can no longer be displayed unless you enable SSL on the PhantomBot Panel and change the baseport to 443. This may not work without root privileges.<br /><br />Alternatively, you can login using the GitHub version of the panel at <a href="https://phantombot.github.io/PhantomBot/">PhantomBot - GitHub.io</a> which gets around this issue.<br /><br />For help setting up SSL, please see <a href="https://phantombot.github.io/PhantomBot/guides/#guide=content/integrations/twitchembeds">this guide</a>.');
$('#twitch-chat-poll').addClass('box-body');
}
});
});

View File

@@ -0,0 +1,229 @@
/*
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Function that querys all of the data we need.
$(run = function () {
// Check if the module is enabled.
socket.getDBValues('queue_module', {
tables: ['modules', 'queueSettings'],
keys: ['./systems/queueSystem.js', 'isActive']
}, true, function (e) {
// If the module is off, don't load any data.
if (!helpers.handleModuleLoadUp(['queueModule', 'queueListModule'], e['./systems/queueSystem.js'], 'queueModuleToggle')) {
// Remove the chat.
$('#queue-chat').find('iframe').remove();
return;
} else {
if (location.protocol.toLowerCase().startsWith('https') && !(location.port > 0 && location.port !== 443)) {
// Add Twitch chat.
$('#queue-chat').html($('<iframe/>', {
'frameborder': '0',
'scrolling': 'no',
'style': 'width: 100%; height: 532px;',
'src': 'https://www.twitch.tv/embed/' + getChannelName() + '/chat' + (helpers.isDark ? '?darkpopout&' : '?') + 'parent=' + location.hostname
}));
} else {
$('#queue-chat').html('Due to changes by Twitch, the chat panel can no longer be displayed unless you enable SSL on the PhantomBot Panel and change the baseport to 443. This may not work without root privileges.<br /><br />Alternatively, you can login using the GitHub version of the panel at <a href="https://phantombot.github.io/PhantomBot/">PhantomBot - GitHub.io</a> which gets around this issue.<br /><br />For help setting up SSL, please see <a href="https://phantombot.github.io/PhantomBot/guides/#guide=content/integrations/twitchembeds">this guide</a>.');
$('#queue-chat').addClass('box-body');
}
}
// Update the open button to close if the queue is active.
if (e['isActive'] === 'true') {
$('#open-or-close-queue').html($('<i/>', {
'class': 'fa fa-lock'
})).append('&nbsp; Close').removeClass('btn-success').addClass('btn-warning');
}
// Function that updates the queue list.
helpers.temp.updateQueueList = function () {
// Get queue list.
socket.getDBTableValues('get_queue_list', 'queue', function (results) {
const table = $('#queue-table');
const trim = function (username) {
if (username.length > 15) {
return username.substr(0, 15) + '...';
} else {
return username;
}
};
// Sort.
results.sort(function (a, b) {
return parseInt(JSON.parse(a.value).position) - parseInt(JSON.parse(b.value).position);
});
// Remove current data content.
table.find('tr:gt(0)').remove();
for (let i = 0; i < results.length; i++) {
const json = JSON.parse(results[i].value),
tr = $('<tr/>');
// Add position.
tr.append($('<td/>', {
'html': json.position
}));
// Add name.
tr.append($('<td/>', {
'html': trim(json.username),
'data-toggle': 'tooltip',
'title': json.username
}));
// Add gamer tag.
tr.append($('<td/>', {
'html': (json.tag.length === 0 ? 'None' : trim(json.tag)),
'data-toggle': 'tooltip',
'title': (json.tag.length === 0 ? 'None' : json.tag)
}));
// Add the del button.
tr.append($('<td/>', {
'html': $('<button/>', {
'type': 'button',
'class': 'btn btn-xs btn-danger',
'style': 'float: right',
'html': $('<i/>', {
'class': 'fa fa-trash'
}),
'click': function () {
socket.wsEvent('rm_queue_user', './systems/queueSystem.js', null,
['remove', results[i].key], helpers.temp.updateQueueList);
}
})
}));
// Add to the table.
table.append(tr);
}
});
};
helpers.temp.updateQueueList();
});
});
// Function that handlers the loading of events.
$(function () {
const QUEUE_SCRIPT = './systems/queueSystem.js';
let canUpdate = true;
/*
* @function Clears the input boxes of the queue.
*/
const clearQueueInput = function () {
$('#queue-title').val('');
$('#queue-cost, #queue-size').val('0');
$('#queue-permission').val('Viewers');
};
// Toggle for the module.
$('#queueModuleToggle').on('change', function () {
// Enable the module then query the data.
socket.sendCommandSync('queue_module_toggle_cmd',
'module ' + ($(this).is(':checked') ? 'enablesilent' : 'disablesilent') + ' ./systems/queueSystem.js', run);
});
// Queue open/close button.
$('#open-or-close-queue').on('click', function () {
if ($(this)[0].innerText.trim() === 'Open') {
let title = $('#queue-title'),
cost = $('#queue-cost'),
size = $('#queue-size'),
permission = $('#queue-permission').find(':selected').text();
switch (false) {
case helpers.handleInputString(title):
case helpers.handleInputNumber(cost, 0):
case helpers.handleInputNumber(size, 0):
break;
default:
socket.sendCommand('queue_permisison_update', 'permcomsilent joinqueue ' + helpers.getGroupIdByName(permission, true), function () {
socket.updateDBValue('queue_command_cost', 'pricecom', 'joinqueue', cost.val(), function () {
socket.wsEvent('queue_open_ws', QUEUE_SCRIPT, null, ['open', size.val(), title.val()], function () {
toastr.success('Successfully opened the queue!');
// Update the button.
$('#open-or-close-queue').html($('<i/>', {
'class': 'fa fa-lock'
})).append('&nbsp; Close').removeClass('btn-success').addClass('btn-warning');
});
});
});
}
} else {
socket.wsEvent('close_queue_ws', QUEUE_SCRIPT, null, ['close'], function () {
toastr.success('Successfully closed the queue!');
clearQueueInput();
// Update the button.
$('#open-or-close-queue').html($('<i/>', {
'class': 'fa fa-unlock-alt'
})).append('&nbsp; Open').removeClass('btn-warning').addClass('btn-success');
});
}
});
// Clear queue command.
$('#reset-queue').on('click', function () {
socket.wsEvent('clear_queue_ws', QUEUE_SCRIPT, null, ['clear'], function () {
toastr.success('Successfully cleared the queue!');
clearQueueInput();
helpers.temp.updateQueueList();
});
});
// Draw users command.
$('#draw-queue').on('click', function () {
helpers.getModal('queue-draw-users', 'Draw Users', 'Draw', $('<form/>', {
'role': 'form'
})
// Append amount to draw
.append(helpers.getInputGroup('draw-amount', 'number', 'Number of Users to Pick', '', '1', 'The amount of users to be drawn from the queue.')),
// Callback.
function () {
let amount = $('#draw-amount');
switch (false) {
case helpers.handleInputNumber(amount, 1, 5):
break;
default:
socket.wsEvent('draw_queue_users', QUEUE_SCRIPT, null, ['pick', amount.val()], function () {
// Alert the user.
toastr.success('Drew ' + amount.val() + ' users from the queue!');
// Update the list.
helpers.temp.updateQueueList();
// Close the modal.
$('#queue-draw-users').modal('toggle');
});
}
}).modal('toggle');
});
// Handle mouse over on queue list.
$('#queueTable').on('mouseenter mouseleave', function (event) {
canUpdate = event.type === 'mouseleave';
});
// Update every 5 seconds.
helpers.setInterval(function () {
if (canUpdate) {
helpers.temp.updateQueueList();
}
}, 5e3);
});