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,76 @@
/*
* 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() {
// Get logging settings.
socket.getDBValues('get_logging_settings', {
tables: ['settings', 'settings', 'settings', 'settings', 'settings',
'settings', 'settings'],
keys: ['log.file', 'log.event', 'log.error', 'log_rotate_days',
'response_@chat', 'response_action', 'whisperMode']
}, true, function(e) {
// Update log event toggle.
$('#logging-events').val((e['log.event'] === 'true' ? 'Yes' : 'No'));
// Update log error toggle.
$('#logging-errors').val((e['log.error'] === 'true' ? 'Yes' : 'No'));
// Update log chat toggle.
$('#logging-chat').val((e['log.file'] === 'true' ? 'Yes' : 'No'));
// Update log keep days.
$('#log-days').val(e.log_rotate_days);
// Set mute mode.
$('#bot-mute-mode').val((e['response_@chat'] === 'true' ? 'No' : 'Yes'));
// Set action mode.
$('#bot-action-mode').val((e['response_action'] === 'true' ? 'Yes' : 'No'));
// Set whisper mode.
$('#bot-whisper-mode').val((e['whisperMode'] === 'true' ? 'Yes' : 'No'));
});
});
// Function that handles events.
$(function() {
// Save button
$('#bot-logging-save').on('click', function() {
let logEvents = $('#logging-events').find(':selected').text() === 'Yes',
logErrors = $('#logging-errors').find(':selected').text() === 'Yes',
logChat = $('#logging-chat').find(':selected').text() === 'Yes',
muteMode = $('#bot-mute-mode').find(':selected').text() !== 'Yes',
actionMode = $('#bot-action-mode').find(':selected').text() === 'Yes',
whisperMode = $('#bot-whisper-mode').find(':selected').text() === 'Yes',
logDays = $('#log-days');
switch (false) {
case helpers.handleInputNumber(logDays):
break;
default:
socket.updateDBValues('update_logging_settings', {
tables: ['settings', 'settings', 'settings', 'settings', 'settings',
'settings', 'settings'],
keys: ['log.file', 'log.event', 'log.error', 'log_rotate_days',
'response_@chat', 'response_action', 'whisperMode'],
values: [logChat, logEvents, logErrors, logDays.val(),
muteMode, actionMode, whisperMode]
}, function() {
socket.sendCommand('update_logging_settings_cmd', 'reloadlogs', function() {
socket.sendCommand('update_misc_settings_cmd', 'reloadmisc', function() {
toastr.success('Successfully updated log settings!');
});
});
});
}
});
});

View File

@@ -0,0 +1,71 @@
/*
* 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() {
// Get command settings.
socket.getDBValues('get_command_settings', {
tables: ['settings', 'settings', 'settings', 'settings', 'cooldownSettings',
'cooldownSettings'],
keys: ['permComMsgEnabled', 'priceComMsgEnabled', 'coolDownMsgEnabled',
'pricecomMods', 'modCooldown', 'defaultCooldownTime']
}, true, function(e) {
// Set cost message.
$('#cmd-cost-messages').val((e.priceComMsgEnabled === 'true' ? 'Yes' : 'No'));
// Set permission message.
$('#cmd-perm-messages').val((e.permComMsgEnabled === 'true' ? 'Yes' : 'No'));
// Set cooldown message.
$('#cmd-cooldown-messages').val((e.coolDownMsgEnabled === 'true' ? 'Yes' : 'No'));
// Set cost for mods.
$('#pricecom-mods').val((e.pricecomMods === 'true' ? 'No' : 'Yes'));
// Set cooldown for mods.
$('#cooldown-mods').val((e.modCooldown === 'true' ? 'No' : 'Yes'));
// Set global cooldown.
$('#global-cooldown').val(e.defaultCooldownTime);
});
});
// Function that handles events.
$(function() {
// Save button.
$('#cmd-save-btn').on('click', function() {
let cmdCostMessage = $('#cmd-cost-messages').find(':selected').text() === 'Yes',
cmdPermMessage = $('#cmd-perm-messages').find(':selected').text() === 'Yes',
cmdCooldownMessage = $('#cmd-cooldown-messages').find(':selected').text() === 'Yes',
priceComMods = $('#pricecom-mods').find(':selected').text() !== 'Yes',
cooldownMods = $('#cooldown-mods').find(':selected').text() !== 'Yes',
globalTime = $('#global-cooldown');
switch (false) {
case helpers.handleInputNumber(globalTime, 5):
break;
default:
socket.updateDBValues('update_cmd_settings', {
tables: ['settings', 'settings', 'settings', 'settings', 'cooldownSettings',
'cooldownSettings'],
keys: ['permComMsgEnabled', 'priceComMsgEnabled', 'coolDownMsgEnabled',
'pricecomMods', 'modCooldown', 'defaultCooldownTime'],
values: [cmdPermMessage, cmdCostMessage, cmdCooldownMessage,
priceComMods, cooldownMods, globalTime.val()]
}, function() {
socket.wsEvent('update_cmd_settings_ws', './core/commandCoolDown.js', null, ['update'], function() {
toastr.success('Successfully update command settings!');
});
});
}
});
});

View File

@@ -0,0 +1,284 @@
/*
* 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() {
var currentLang = '';
// Load file button
$('#load-file-button').on('click', function() {
$.ajax({
'url': '/get-lang?webauth=' + getAuth(),
'type': 'GET',
'success': function(data) {
helpers.getModal('edit-lang', 'Load Lang File', 'Edit', $('<form/>', {
'role': 'form'
})
// Add select box.
.append(helpers.getDropdownGroup('file-to-load', 'Lang file: ', 'Choose a File', data.split('\n'))), function() {
currentLang = $('#file-to-load').find(':selected').text();
$.ajax({
'url': '/lang?webauth=' + getAuth(),
'type': 'GET',
'headers': {
'lang-path': $('#file-to-load').find(':selected').text()
},
'success': function(data) {
// Load the file
loadLang(JSON.parse(data));
// Alert the user.
toastr.success('Successfully loaded the file!');
// Close the modal.
$('#edit-lang').modal('toggle');
// Enable the insert and save buttons.
$('#save-button').prop('disabled', false);
$('#add-line-button').prop('disabled', false);
}
})
}).modal('toggle');
}
});
});
// Add line button.
$('#add-line-button').on('click', function() {
helpers.getModal('add-lang', 'Add Lang Entry', 'Add', $('<form/>', {
'role': 'form'
})
// ID for the lang.
.append(helpers.getInputGroup('lang-id', 'text', 'Lang ID', 'module.name.id'))
// Resonse for the lang.
.append(helpers.getTextAreaGroup('lang-response', 'text', 'Response', 'Response example!')), function() {
const table = $('#langTable').DataTable(),
langId = $('#lang-id'),
langRes = $('#lang-response');
switch (false) {
case helpers.handleInputString(langId):
case helpers.handleInputString(langRes):
break;
default:
langId.val(langId.val().replace(/[^a-zA-Z0-9-\.]+/g, '-'));
table.row.add([
langId.val(),
langRes.val(),
$('<div/>', {
'class': 'btn-group'
}).append($('<button/>', {
'type': 'button',
'class': 'btn btn-xs btn-danger',
'style': 'float: right',
'data-id': langId.val(),
'data-response': langRes.val(),
'html': $('<i/>', {
'class': 'fa fa-trash'
})
})).append($('<button/>', {
'type': 'button',
'class': 'btn btn-xs btn-warning',
'style': 'float: right',
'data-id': langId.val(),
'data-response': langRes.val(),
'html': $('<i/>', {
'class': 'fa fa-edit'
})
})).html()
]).draw();
// Close the modal.
$('#add-lang').modal('toggle');
// Alert the user.
toastr.success('Successfully added the lang entry.');
}
}).modal('toggle');
});
// Save button
$('#save-button').on('click', function() {
const datas = $('#langTable').DataTable().rows().data(),
dataObj = [];
for (let i = 0; i < datas.length; i++) {
if (typeof datas[i] === 'object') {
dataObj.push({
'id': datas[i][0],
'response': datas[i][1]
});
} else {
// No longer data, break the loop.
break;
}
}
// Post the lang.
$.ajax({
'type': 'PUT',
'url': '/lang?webauth=' + getAuth(),
'contentType': 'application/json',
'headers': {
'lang-path': currentLang
},
'data': JSON.stringify(dataObj),
'success': function(data, text, xhr) {
if (xhr.status === 200) {
toastr.success('Successfully saved the lang!');
} else {
toastr.success('Faled to save the lang.');
}
}
});
});
// Load lang function
function loadLang(langArray) {
const tableData = [];
for (let i = 0; i < langArray.length; i++) {
langArray[i]['response'] = langArray[i]['response'].replace(/\\'/g, '\'');
tableData.push([
langArray[i]['id'],
langArray[i]['response'],
$('<div/>', {
'class': 'btn-group'
}).append($('<button/>', {
'type': 'button',
'class': 'btn btn-xs btn-danger',
'style': 'float: right',
'data-id': langArray[i]['id'],
'data-response': langArray[i]['response'],
'html': $('<i/>', {
'class': 'fa fa-trash'
})
})).append($('<button/>', {
'type': 'button',
'class': 'btn btn-xs btn-warning',
'style': 'float: right',
'data-id': langArray[i]['id'],
'data-response': langArray[i]['response'],
'html': $('<i/>', {
'class': 'fa fa-edit'
})
})).html()
])
}
// if the table exists, destroy it.
if ($.fn.DataTable.isDataTable('#langTable')) {
$('#langTable').DataTable().destroy();
// Remove all of the old events.
$('#langTable').off();
}
// Create table.
let table = $('#langTable').DataTable({
'searching': true,
'autoWidth': false,
'lengthChange': false,
'paging': false,
'data': tableData,
'columnDefs': [
{ 'className': 'default-table', 'orderable': false, 'targets': 2 },
{ 'width': '25%', 'targets': 0 }
],
'columns': [
{ 'title': 'Lang ID' },
{ 'title': 'Response' },
{ 'title': 'Actions' }
]
});
// On delete button.
table.on('click', '.btn-danger', function() {
const row = $(this).parents('tr'),
id = $(this).data('id');
// Ask the user if he wants to delete the lang.
helpers.getConfirmDeleteModal('lang_modal_remove', 'Are you sure you want to remove this lang entry?', true,
'The land entry has been successfully removed!', function() { // Callback if the user clicks delete.
// Remove the table row.
table.row(row).remove().draw(false);
});
});
// On edit button.
table.on('click', '.btn-warning', function() {
const t = $(this);
helpers.getModal('edit-lang', 'Edit Lang Entry', 'Edit', $('<form/>', {
'role': 'form'
})
// ID for the lang.
.append(helpers.getInputGroup('lang-id', 'text', 'Lang ID', '', t.data('id'), 'The ID of this lang.'))
// Resonse for the lang.
.append(helpers.getTextAreaGroup('lang-response', 'text', 'Response', '', t.data('response').replace(/\\'/g, '\''), 'The response of this lang.')), function() {
let id = $('#lang-id'),
response = $('#lang-response');
switch (false) {
case helpers.handleInputString(id):
case helpers.handleInputString(response):
break;
default:
// Update the special chars.
id = id.val().replace(/[^a-zA-Z0-9-\.]+/g, '-');
// Update the table.
$('#langTable').DataTable().row(t.parents('tr')).data([
id,
response.val(),
$('<div/>', {
'class': 'btn-group'
}).append($('<button/>', {
'type': 'button',
'class': 'btn btn-xs btn-danger',
'style': 'float: right',
'data-id': id,
'data-response': response.val(),
'html': $('<i/>', {
'class': 'fa fa-trash'
})
})).append($('<button/>', {
'type': 'button',
'class': 'btn btn-xs btn-warning',
'style': 'float: right',
'data-id': id,
'data-response': response.val(),
'html': $('<i/>', {
'class': 'fa fa-edit'
})
})).html()
]).draw(false);
// Alert the user.
toastr.success('Successfully updated the lang response!');
// Close the modal.
$('#edit-lang').modal('toggle');
}
}).modal('toggle');
});
}
function cleanLangID(obj) {
return obj.val(obj.val().replace(/[^a-zA-Z0-9-\.]+/g, '-'));
}
// Load the table for now.
loadLang([]);
});

View File

@@ -0,0 +1,231 @@
/*
* 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() {
// Get all modules.
socket.getDBTableValues('get_all_modules', 'modules', function(results) {
let twitchModules = [],
discordModules = [];
for (let i = 0; i < results.length; i++) {
if (results[i].key.indexOf('/lang/') === -1 && results[i].key.indexOf('/core/') === -1) {
if (results[i].key.indexOf('./discord') !== -1) {
discordModules.push({
module: results[i].key,
status: results[i].value === 'true'
});
} else {
twitchModules.push({
module: results[i].key,
status: results[i].value === 'true'
});
}
}
}
// Load Twitch table.
let twitchTable = [];
for (let i = 0; i < twitchModules.length; i++) {
twitchTable.push([
twitchModules[i].module,
$('<div/>', {
'class': 'btn-group'
}).append($('<button/>', {
'type': 'button',
'class': 'btn btn-xs btn-danger',
'data-toggle': 'tooltip',
'title': 'Delete the module if it no longer exists.',
'style': 'float: right',
'data-module': twitchModules[i].module,
'html': $('<i/>', {
'class': 'fa fa-trash'
})
})).append($('<button/>', {
'type': 'button',
'class': 'btn btn-xs btn-' + (twitchModules[i].status ? 'success' : 'warning'),
'data-toggle': 'tooltip',
'title': (twitchModules[i].status ? 'Click to disable the module.' : 'Click to enable the module.') ,
'style': 'float: right',
'data-module': twitchModules[i].module,
'data-mtoggle': twitchModules[i].status,
'html': $('<i/>', {
'class': 'fa fa-' + (twitchModules[i].status ? 'close' : 'check')
})
})).html()
]);
}
// if the table exists, destroy it.
if ($.fn.DataTable.isDataTable('#twitchModuleTable')) {
$('#twitchModuleTable').DataTable().destroy();
// Remove all of the old events.
$('#twitchModuleTable').off();
}
// Create table.
let table = $('#twitchModuleTable').DataTable({
'searching': true,
'autoWidth': false,
'lengthChange': true,
'data': twitchTable,
'columnDefs': [
{ 'className': 'default-table', 'orderable': false, 'targets': 1 },
],
'columns': [
{ 'title': 'Module' },
{ 'title': 'Actions' }
]
});
// On delete button.
table.on('click', '.btn-danger', function() {
let module = $(this).data('module'),
row = $(this).parents('tr');
// Ask the user if he want to remove the module.
helpers.getConfirmDeleteModal('rm_module_cmd_modal', 'Are you sure that you want to remove module "' + module + '"?', true,
'The module "' + module + '"" has been successfully removed!', function() {
socket.removeDBValue('rm_twitch_module', 'modules', module, function() {
// Remove the table row.
table.row(row).remove().draw(false);
});
});
});
// On toggle button.
table.on('click', '.btn-warning, .btn-success', function() {
let module = $(this).data('module'),
toggle = $(this).data('mtoggle'),
btn = $(this);
socket.sendCommand('module_toggle_cmd', 'module ' + (!toggle ? 'enablesilent ' : 'disablesilent ') + module, function() {
toastr.success('successfully ' + (!toggle ? 'enabled' : 'disabled') + ' the module.');
// Update the button.
if (toggle) {
btn.removeClass('btn-success').addClass('btn-warning').find('i').removeClass('fa-close').addClass('fa-check');
btn.prop('title', 'Click to enable the module.').tooltip('fixTitle').tooltip('show');
} else {
btn.removeClass('btn-warning').addClass('btn-success').find('i').removeClass('fa-check').addClass('fa-close');
btn.prop('title', 'Click to disable the module.').tooltip('fixTitle').tooltip('show');
}
btn.data('mtoggle', !toggle);
});
});
// Get the status of Discord.
// Only load the list if we are using it.
socket.getDBValue('get_discord_status', 'panelData', 'hasDiscord', function(e) {
// Disable the tab if we are not using Discord.
if (e.panelData !== 'true') {
$('#discord_modules_t').addClass('disabled').parent().addClass('disabled');
return;
}
// Load Discord table.
let discordTable = [];
for (let i = 0; i < discordModules.length; i++) {
discordTable.push([
discordModules[i].module,
$('<div/>', {
'class': 'btn-group'
}).append($('<button/>', {
'type': 'button',
'class': 'btn btn-xs btn-danger',
'data-toggle': 'tooltip',
'title': 'Delete the module if it no longer exists.',
'style': 'float: right',
'data-module': discordModules[i].module,
'html': $('<i/>', {
'class': 'fa fa-trash'
})
})).append($('<button/>', {
'type': 'button',
'class': 'btn btn-xs btn-' + (discordModules[i].status ? 'success' : 'warning'),
'data-toggle': 'tooltip',
'title': (discordModules[i].status ? 'Click to disable the module.' : 'Click to enable the module.') ,
'style': 'float: right',
'data-module': discordModules[i].module,
'data-mtoggle': discordModules[i].status,
'html': $('<i/>', {
'class': 'fa fa-' + (discordModules[i].status ? 'close' : 'check')
})
})).html()
]);
}
// if the table exists, destroy it.
if ($.fn.DataTable.isDataTable('#discordModuleTable')) {
$('#discordModuleTable').DataTable().destroy();
// Remove all of the old events.
$('#discordModuleTable').off();
}
// Create table.
let table = $('#discordModuleTable').DataTable({
'searching': true,
'autoWidth': false,
'lengthChange': true,
'data': discordTable,
'columnDefs': [
{ 'className': 'default-table', 'orderable': false, 'targets': 1 },
],
'columns': [
{ 'title': 'Module' },
{ 'title': 'Actions' }
]
});
// On delete button.
table.on('click', '.btn-danger', function() {
let module = $(this).data('module'),
row = $(this).parents('tr');
// Ask the user if he want to remove the module.
helpers.getConfirmDeleteModal('rm_module_cmd_modal', 'Are you sure that you want to remove module "' + module + '"?', true,
'The module "' + module + '"" has been successfully removed!', function() {
socket.removeDBValue('rm_discord_module', 'modules', module, function() {
// Remove the table row.
table.row(row).remove().draw(false);
});
});
});
// On toggle button.
table.on('click', '.btn-warning, .btn-success', function() {
let module = $(this).data('module'),
toggle = $(this).data('mtoggle'),
btn = $(this);
socket.sendCommand('module_toggle_cmd', 'module ' + (!toggle ? 'enablesilent ' : 'disablesilent ') + module, function() {
toastr.success('successfully ' + (!toggle ? 'enabled' : 'disabled') + ' the module.');
// Update the button.
if (toggle) {
btn.removeClass('btn-success').addClass('btn-warning').find('i').removeClass('fa-close').addClass('fa-check');
btn.prop('title', 'Click to enable the module.').tooltip('fixTitle').tooltip('show');
} else {
btn.removeClass('btn-warning').addClass('btn-success').find('i').removeClass('fa-check').addClass('fa-close');
btn.prop('title', 'Click to disable the module.').tooltip('fixTitle').tooltip('show');
}
btn.data('mtoggle', !toggle);
});
});
});
});
});