init commit
This commit is contained in:
192
libs/phantombot/web/panel/js/pages/commands/aliases.js
Normal file
192
libs/phantombot/web/panel/js/pages/commands/aliases.js
Normal file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* 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('alias_command_module', 'modules', './commands/customCommands.js', function(e) {
|
||||
// If the module is off, don't load any data.
|
||||
if (!helpers.handleModuleLoadUp('aliasesModule', e.modules)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Query aliases.
|
||||
socket.getDBTableValues('commands_get_aliases', 'aliases', function(results) {
|
||||
let tableData = [];
|
||||
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
tableData.push([
|
||||
'!' + results[i].key,
|
||||
'!' + results[i].value,
|
||||
$('<div/>', {
|
||||
'class': 'btn-group'
|
||||
}).append($('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-xs btn-danger',
|
||||
'style': 'float: right',
|
||||
'data-alias': results[i].key,
|
||||
'html': $('<i/>', {
|
||||
'class': 'fa fa-trash'
|
||||
})
|
||||
})).append($('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-xs btn-warning',
|
||||
'style': 'float: right',
|
||||
'data-alias': results[i].key,
|
||||
'html': $('<i/>', {
|
||||
'class': 'fa fa-edit'
|
||||
})
|
||||
})).html()
|
||||
]);
|
||||
}
|
||||
|
||||
// if the table exists, destroy it.
|
||||
if ($.fn.DataTable.isDataTable('#aliasesTable')) {
|
||||
$('#aliasesTable').DataTable().destroy();
|
||||
// Remove all of the old events.
|
||||
$('#aliasesTable').off();
|
||||
}
|
||||
|
||||
// Create table.
|
||||
let table = $('#aliasesTable').DataTable({
|
||||
'searching': true,
|
||||
'autoWidth': false,
|
||||
'lengthChange': false,
|
||||
'data': tableData,
|
||||
'columnDefs': [
|
||||
{ 'className': 'default-table', 'orderable': false, 'targets': 2 },
|
||||
{ 'width': '45%', 'targets': 0 }
|
||||
],
|
||||
'columns': [
|
||||
{ 'title': 'Alias' },
|
||||
{ 'title': 'Command' },
|
||||
{ 'title': 'Actions' }
|
||||
]
|
||||
});
|
||||
|
||||
// On delete button.
|
||||
table.on('click', '.btn-danger', function() {
|
||||
let alias = $(this).data('alias'),
|
||||
row = $(this).parents('tr');
|
||||
|
||||
// Ask the user if he wants to delete the alias.
|
||||
helpers.getConfirmDeleteModal('custom_alias_modal_remove', 'Are you sure you want to remove the alias !' + alias + '?', true,
|
||||
'The alias !' + alias + ' has been successfully removed!', function() { // Callback if the user clicks delete.
|
||||
// Delete all information about the alias.
|
||||
socket.removeDBValue('alias_remove', 'aliases', alias, function() {
|
||||
socket.sendCommand('alias_remove_cmd', 'reloadcommand ' + alias, function() {
|
||||
// Remove the table row.
|
||||
table.row(row).remove().draw(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// On edit button.
|
||||
table.on('click', '.btn-warning', function() {
|
||||
let alias = $(this).data('alias'),
|
||||
t = $(this);
|
||||
|
||||
socket.getDBValue('alias_name_get', 'aliases', alias, function(e) {
|
||||
helpers.getModal('edit-alias', 'Edit Alias', 'Save', $('<form/>', {
|
||||
'role': 'form'
|
||||
})
|
||||
// Append alias name.
|
||||
.append(helpers.getInputGroup('alias-name', 'text', 'Alias', '', '!' + alias, 'Name of the alias. This cannot be edited.', true))
|
||||
// Append alias.
|
||||
.append(helpers.getInputGroup('alias-cmd', 'text', 'Command', '', '!' + e.aliases, 'Command to be ran by the alias.')), function() {// Callback once we click the save button.
|
||||
let aliasCmd = $('#alias-cmd');
|
||||
|
||||
// Remove the ! and spaces.
|
||||
aliasCmd.val(aliasCmd.val().replace(/(\!|\s)/g, '').toLowerCase());
|
||||
|
||||
// Handle each input to make sure they have a value.
|
||||
switch (false) {
|
||||
case helpers.handleInputString(aliasCmd):
|
||||
break;
|
||||
default:
|
||||
// Update the alias.
|
||||
socket.updateDBValue('update_command_alias', 'aliases', alias, aliasCmd.val(), function() {
|
||||
// Update the table.
|
||||
t.parents('tr').find('td:eq(1)').text('!' + aliasCmd.val());
|
||||
// Close the modal.
|
||||
$('#edit-alias').modal('hide');
|
||||
// Alert the user.
|
||||
toastr.success('Successfully edited alias !' + alias);
|
||||
});
|
||||
}
|
||||
}).modal('toggle');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Function that handlers the loading of events.
|
||||
$(function() {
|
||||
// Toggle for the module.
|
||||
$('#aliasesModuleToggle').on('change', function() {
|
||||
// Enable the module then query the data.
|
||||
socket.sendCommandSync('aliases_commands_module_toggle_cmd', 'module ' + ($(this).is(':checked') ? 'enablesilent' : 'disablesilent') + ' ./commands/customCommands.js', run);
|
||||
});
|
||||
|
||||
// Add alias button.
|
||||
$('#aliascom-button').on('click', function() {
|
||||
helpers.getModal('add-alias', 'Add Alias', 'Save', $('<form/>', {
|
||||
'role': 'form'
|
||||
})
|
||||
// Append alias name.
|
||||
.append(helpers.getInputGroup('alias-name', 'text', 'Alias', '!cmds', '', 'Name of the alias.'))
|
||||
// Append alias.
|
||||
.append(helpers.getInputGroup('alias-cmd', 'text', 'Command', '!commands', '', 'Command to be ran by the alias.')), function() {// Callback once we click the save button.
|
||||
let aliasName = $('#alias-name'),
|
||||
aliasCmd = $('#alias-cmd');
|
||||
|
||||
// Remove the ! and spaces.
|
||||
aliasName.val(aliasName.val().replace(/(\!|\s)/g, '').toLowerCase());
|
||||
aliasCmd.val(aliasCmd.val().replace(/\!/g, '').toLowerCase());
|
||||
|
||||
// Handle each input to make sure they have a value.
|
||||
switch (false) {
|
||||
case helpers.handleInputString(aliasName):
|
||||
case helpers.handleInputString(aliasCmd):
|
||||
break;
|
||||
default:
|
||||
// Make sure the alias doesn't exit already.
|
||||
socket.getDBValue('alias_exists', 'aliases', aliasName.val(), function(e) {
|
||||
// If the command exists we stop here.
|
||||
if (e.aliases !== null) {
|
||||
toastr.error('Failed to add alias as it already exists.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the alias.
|
||||
socket.updateDBValue('add_command_alias', 'aliases', aliasName.val(), aliasCmd.val(), function() {
|
||||
socket.sendCommand('alias_add_cmd', 'reloadcommand', function() {
|
||||
// Reload the table.
|
||||
run();
|
||||
// Close the modal.
|
||||
$('#add-alias').modal('hide');
|
||||
// Alert the user.
|
||||
toastr.success('Successfully added alias !' + aliasName.val());
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}).modal('toggle');
|
||||
});
|
||||
});
|
||||
349
libs/phantombot/web/panel/js/pages/commands/custom.js
Normal file
349
libs/phantombot/web/panel/js/pages/commands/custom.js
Normal file
@@ -0,0 +1,349 @@
|
||||
/*
|
||||
* 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('custom_command_module', 'modules', './commands/customCommands.js', function(e) {
|
||||
// If the module is off, don't load any data.
|
||||
if (!helpers.handleModuleLoadUp('customCommandsModule', e.modules)) {
|
||||
return;
|
||||
}
|
||||
// Query custom commands.
|
||||
socket.getDBTableValues('commands_get_custom', 'command', function(results) {
|
||||
let tableData = [];
|
||||
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
tableData.push([
|
||||
'!' + results[i].key,
|
||||
results[i].value,
|
||||
$('<div/>', {
|
||||
'class': 'btn-group'
|
||||
}).append($('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-xs btn-danger',
|
||||
'style': 'float: right',
|
||||
'data-command': results[i].key,
|
||||
'html': $('<i/>', {
|
||||
'class': 'fa fa-trash'
|
||||
})
|
||||
})).append($('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-xs btn-warning',
|
||||
'style': 'float: right',
|
||||
'data-command': results[i].key,
|
||||
'html': $('<i/>', {
|
||||
'class': 'fa fa-edit'
|
||||
})
|
||||
})).html()
|
||||
]);
|
||||
}
|
||||
|
||||
// if the table exists, destroy it.
|
||||
if ($.fn.DataTable.isDataTable('#customCommandsTable')) {
|
||||
$('#customCommandsTable').DataTable().destroy();
|
||||
// Remove all of the old events.
|
||||
$('#customCommandsTable').off();
|
||||
}
|
||||
|
||||
// Create table.
|
||||
let table = $('#customCommandsTable').DataTable({
|
||||
'searching': true,
|
||||
'autoWidth': false,
|
||||
'lengthChange': false,
|
||||
'data': tableData,
|
||||
'columnDefs': [
|
||||
{ 'className': 'default-table', 'orderable': false, 'targets': 2 },
|
||||
{ 'width': '15%', 'targets': 0 }
|
||||
],
|
||||
'columns': [
|
||||
{ 'title': 'Command' },
|
||||
{ 'title': 'Response' },
|
||||
{ 'title': 'Actions' }
|
||||
]
|
||||
});
|
||||
|
||||
// On delete button.
|
||||
table.on('click', '.btn-danger', function() {
|
||||
let command = $(this).data('command'),
|
||||
row = $(this).parents('tr');
|
||||
|
||||
// Ask the user if he want to remove the command.
|
||||
helpers.getConfirmDeleteModal('custom_command_modal_remove', 'Are you sure you want to remove command !' + command + '?', true,
|
||||
'The command !' + command + ' has been successfully removed!', function() {
|
||||
// Delete all information about the command.
|
||||
socket.removeDBValues('custom_command_remove', {
|
||||
tables: ['command', 'permcom', 'cooldown', 'aliases', 'pricecom', 'paycom', 'commandtoken'],
|
||||
keys: [command, command, command, command, command, command, command]
|
||||
}, function() {
|
||||
socket.wsEvent('custom_command_remove_ws', './commands/customCommands.js', null, ['remove', String(command)], function() {
|
||||
// Remove the table row.
|
||||
table.row(row).remove().draw(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// On edit button.
|
||||
table.on('click', '.btn-warning', function() {
|
||||
let command = $(this).data('command'),
|
||||
t = $(this);
|
||||
|
||||
// Get all the info about the command.
|
||||
socket.getDBValues('custom_command_edit', {
|
||||
tables: ['command', 'permcom', 'cooldown', 'pricecom', 'paycom'],
|
||||
keys: [command, command, command, command, command]
|
||||
}, function(e) {
|
||||
let cooldownJson = (e.cooldown === null ? { isGlobal: 'true', seconds: 0 } : JSON.parse(e.cooldown));
|
||||
|
||||
let tokenButton = '';
|
||||
|
||||
if (e.command.match(/\(customapi/gi) !== null) {
|
||||
tokenButton = $('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn',
|
||||
'style': 'float: right; position: relative; bottom: 6px;',
|
||||
'data-command': command,
|
||||
'click': function() {
|
||||
tokenEditModal($(this).data('command'));
|
||||
},
|
||||
'text': 'Add/Edit Command Token'
|
||||
});
|
||||
}
|
||||
|
||||
// Get advance modal from our util functions in /utils/helpers.js
|
||||
helpers.getAdvanceModal('edit-command', 'Edit Command', 'Save', $('<form/>', {
|
||||
'role': 'form'
|
||||
})
|
||||
// Append input box for the command name. This one is disabled.
|
||||
.append(helpers.getInputGroup('command-name', 'text', 'Command', '', '!' + command, 'Name of the command. This cannot be edited.', true))
|
||||
// Append a text box for the command response.
|
||||
.append(helpers.getTextAreaGroup('command-response', 'text', 'Response', '', e.command, 'Response of the command. Use enter for multiple chat lines maximum is 5.'))
|
||||
.append(tokenButton)
|
||||
// Append a select option for the command permission.
|
||||
.append(helpers.getDropdownGroup('command-permission', 'User Level', helpers.getGroupNameById(e.permcom),
|
||||
['Caster', 'Administrators', 'Moderators', 'Subscribers', 'Donators', 'VIPs', 'Regulars', 'Viewers']))
|
||||
// Add an advance section that can be opened with a button toggle.
|
||||
.append($('<div/>', {
|
||||
'class': 'collapse',
|
||||
'id': 'advance-collapse',
|
||||
'html': $('<form/>', {
|
||||
'role': 'form'
|
||||
})
|
||||
// Append input box for the command cost.
|
||||
.append(helpers.getInputGroup('command-cost', 'number', 'Cost', '0', helpers.getDefaultIfNullOrUndefined(e.pricecom, '0'),
|
||||
'Cost in points that will be taken from the user when running the command.'))
|
||||
// Append input box for the command reward.
|
||||
.append(helpers.getInputGroup('command-reward', 'number', 'Reward', '0', helpers.getDefaultIfNullOrUndefined(e.paycom, '0'),
|
||||
'Reward in points the user will be given when running the command.'))
|
||||
// Append input box for the command cooldown.
|
||||
.append(helpers.getInputGroup('command-cooldown', 'number', 'Cooldown (Seconds)', '5', cooldownJson.seconds,
|
||||
'Cooldown of the command in seconds.')
|
||||
// Append checkbox for if the cooldown is global or per-user.
|
||||
.append(helpers.getCheckBox('command-cooldown-global', cooldownJson.isGlobal === 'true', 'Global',
|
||||
'If checked the cooldown will be applied to everyone in the channel. When not checked, the cooldown is applied per-user.')))
|
||||
// Callback function to be called once we hit the save button on the modal.
|
||||
})), function() {
|
||||
let commandName = $('#command-name'),
|
||||
commandResponse = $('#command-response'),
|
||||
commandPermission = $('#command-permission'),
|
||||
commandCost = $('#command-cost'),
|
||||
commandReward = $('#command-reward'),
|
||||
commandCooldown = $('#command-cooldown'),
|
||||
commandCooldownGlobal = $('#command-cooldown-global').is(':checked');
|
||||
|
||||
// Remove the ! and spaces.
|
||||
commandName.val(commandName.val().replace(/(\!|\s)/g, '').toLowerCase());
|
||||
|
||||
// Handle each input to make sure they have a value.
|
||||
switch (false) {
|
||||
case helpers.handleInputString(commandName):
|
||||
case helpers.handleInputString(commandResponse):
|
||||
case helpers.handleInputNumber(commandCost):
|
||||
case helpers.handleInputNumber(commandReward):
|
||||
case helpers.handleInputNumber(commandCooldown):
|
||||
break;
|
||||
default:
|
||||
|
||||
// Save command information here and close the modal.
|
||||
socket.updateDBValues('custom_command_edit', {
|
||||
tables: ['pricecom', 'permcom', 'paycom', 'command'],
|
||||
keys: [commandName.val(), commandName.val(), commandName.val(), commandName.val()],
|
||||
values: [commandCost.val(), helpers.getGroupIdByName(commandPermission.find(':selected').text(), true),
|
||||
commandReward.val(), commandResponse.val()]
|
||||
}, function() {
|
||||
// Register the custom command with the cache.
|
||||
socket.wsEvent('custom_command_edit_ws', './commands/customCommands.js', null, ['edit', String(commandName.val()),
|
||||
commandResponse.val()], function() {
|
||||
// Add the cooldown to the cache.
|
||||
socket.wsEvent('custom_command_edit_cooldown_ws', './core/commandCoolDown.js', null,
|
||||
['add', commandName.val(), commandCooldown.val(), String(commandCooldownGlobal)], function() {
|
||||
// Update command permission.
|
||||
socket.sendCommand('edit_command_permission_cmd', 'permcomsilent ' + commandName.val() + ' ' +
|
||||
helpers.getGroupIdByName(commandPermission.find(':selected').text(), true), function() {
|
||||
// Update the command response
|
||||
t.parents('tr').find('td:eq(1)').text(commandResponse.val());
|
||||
// Close the modal.
|
||||
$('#edit-command').modal('hide');
|
||||
// Tell the user the command was edited.
|
||||
toastr.success('Successfully edited command !' + commandName.val());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}).modal('toggle');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Function that handlers the loading of events.
|
||||
$(function() {
|
||||
// Toggle for the module.
|
||||
$('#customCommandsModuleToggle').on('change', function() {
|
||||
// Enable the module then query the data.
|
||||
socket.sendCommandSync('custom_commands_module_toggle_cmd', 'module ' + ($(this).is(':checked') ? 'enablesilent' : 'disablesilent') + ' ./commands/customCommands.js', run);
|
||||
});
|
||||
|
||||
// Add command button.
|
||||
$('#addcom-button').on('click', function() {
|
||||
// Get advance modal from our util functions in /utils/helpers.js
|
||||
helpers.getAdvanceModal('add-command', 'Add Command', 'Save', $('<form/>', {
|
||||
'role': 'form'
|
||||
})
|
||||
// Append input box for the command name.
|
||||
.append(helpers.getInputGroup('command-name', 'text', 'Command', '!example'))
|
||||
// Append a text box for the command response.
|
||||
.append(helpers.getTextAreaGroup('command-response', 'text', 'Response', 'Response example! Use enter for multiple chat lines maximum is 5.'))
|
||||
// Append a select option for the command permission.
|
||||
.append(helpers.getDropdownGroup('command-permission', 'User Level', 'Viewers',
|
||||
['Caster', 'Administrators', 'Moderators', 'Subscribers', 'Donators', 'VIPs', 'Regulars', 'Viewers']))
|
||||
// Add an advance section that can be opened with a button toggle.
|
||||
.append($('<div/>', {
|
||||
'class': 'collapse',
|
||||
'id': 'advance-collapse',
|
||||
'html': $('<form/>', {
|
||||
'role': 'form'
|
||||
})
|
||||
// Append input box for the command cost.
|
||||
.append(helpers.getInputGroup('command-cost', 'number', 'Cost', '0', '0',
|
||||
'Cost in points that will be taken from the user when running the command.'))
|
||||
// Append input box for the command reward.
|
||||
.append(helpers.getInputGroup('command-reward', 'number', 'Reward', '0', '0',
|
||||
'Reward in points the user will be given when running the command.'))
|
||||
// Append input box for the command cooldown.
|
||||
.append(helpers.getInputGroup('command-cooldown', 'number', 'Cooldown (Seconds)', '0', '5',
|
||||
'Cooldown of the command in seconds.')
|
||||
// Append checkbox for if the cooldown is global or per-user.
|
||||
.append(helpers.getCheckBox('command-cooldown-global', true, 'Global',
|
||||
'If checked the cooldown will be applied to everyone in the channel. When not checked, the cooldown is applied per-user.')))
|
||||
// Callback function to be called once we hit the save button on the modal.
|
||||
})), function() {
|
||||
let commandName = $('#command-name'),
|
||||
commandResponse = $('#command-response'),
|
||||
commandPermission = $('#command-permission'),
|
||||
commandCost = $('#command-cost'),
|
||||
commandReward = $('#command-reward'),
|
||||
commandCooldown = $('#command-cooldown'),
|
||||
commandCooldownGlobal = $('#command-cooldown-global').is(':checked');
|
||||
|
||||
// Remove the ! and spaces.
|
||||
commandName.val(commandName.val().replace(/(\!|\s)/g, '').toLowerCase());
|
||||
|
||||
// Handle each input to make sure they have a value.
|
||||
switch (false) {
|
||||
case helpers.handleInputString(commandName):
|
||||
case helpers.handleInputString(commandResponse):
|
||||
case helpers.handleInputNumber(commandCost):
|
||||
case helpers.handleInputNumber(commandReward):
|
||||
case helpers.handleInputNumber(commandCooldown):
|
||||
break;
|
||||
default:
|
||||
// Make sure the command doesn't exist already.
|
||||
socket.getDBValue('custom_command_exists', 'permcom', commandName.val(), function(e) {
|
||||
// If the command exists we stop here.
|
||||
if (e.permcom !== null) {
|
||||
toastr.error('Failed to add command as it already exists.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Save command information here and close the modal.
|
||||
socket.updateDBValues('custom_command_add', {
|
||||
tables: ['pricecom', 'permcom', 'paycom', 'command'],
|
||||
keys: [commandName.val(), commandName.val(), commandName.val(), commandName.val()],
|
||||
values: [commandCost.val(), helpers.getGroupIdByName(commandPermission.find(':selected').text(), true), commandReward.val(), commandResponse.val()]
|
||||
}, function() {
|
||||
// Register the custom command with the cache.
|
||||
socket.wsEvent('custom_command_add_ws', './commands/customCommands.js', null,
|
||||
['add', commandName.val(), commandResponse.val()], function() {
|
||||
// Add the cooldown to the cache.
|
||||
socket.wsEvent('custom_command_cooldown_ws', './core/commandCoolDown.js', null,
|
||||
['add', commandName.val(), commandCooldown.val(), String(commandCooldownGlobal)], function() {
|
||||
// Reload the table.
|
||||
run();
|
||||
// Close the modal.
|
||||
$('#add-command').modal('hide');
|
||||
// Tell the user the command was added.
|
||||
toastr.success('Successfully added command !' + commandName.val());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}).modal('toggle');
|
||||
});
|
||||
|
||||
// On token button.
|
||||
tokenEditModal = function(command) {
|
||||
// Get modal from our util functions in /utils/helpers.js
|
||||
helpers.getModal('token-command', 'Set Command Token', 'Save', $('<form/>', {
|
||||
'role': 'form'
|
||||
})
|
||||
.append('This dialog stores a user/pass or API key to be replaced into a (customapi) tag.\n\
|
||||
<br /> NOTE: This is only useful if you place a (token) subtag into the URL of a (customapi) or (customapijson) command tag.\n\
|
||||
<br /> Example (using the bot\s chat commands for demonstration purposes):\n\
|
||||
<br /> !addcom myapicommand (customapi http://(token)@example.com/myapi)\n\
|
||||
<br /> !tokencom myapicommand myuser:mypass\n\
|
||||
<br /> <i>The command now effectively calls http://myuser:mypass@example.com/myapi while reducing exposure of your user/pass</i>')
|
||||
// Append input box for the command name. This one is disabled.
|
||||
.append(helpers.getInputGroup('command-tname', 'text', 'Command', '', '!' + command, 'Name of the command. This cannot be edited.', true))
|
||||
// Append a text box for the command token.
|
||||
.append(helpers.getInputGroup('command-token', 'text', 'Token', '', 'The token value for the command.')), function() {
|
||||
let commandName = $('#command-tname'),
|
||||
commandToken = $('#command-token');
|
||||
|
||||
// Remove the ! and spaces.
|
||||
commandName.val(commandName.val().replace(/(\!|\s)/g, '').toLowerCase());
|
||||
|
||||
// Handle each input to make sure they have a value.
|
||||
switch (false) {
|
||||
case helpers.handleInputString(commandName):
|
||||
break;
|
||||
default:
|
||||
// Update command token.
|
||||
socket.sendCommand('command_settoken_cmd', 'tokencom silent@' + commandName.val() + ' ' + commandToken.val(), function() {
|
||||
// Close the modal.
|
||||
$('#token-command').modal('hide');
|
||||
// Tell the user the command was edited.
|
||||
toastr.success('Successfully changed token for command !' + commandName.val());
|
||||
});
|
||||
}
|
||||
}).modal('toggle');
|
||||
};
|
||||
});
|
||||
185
libs/phantombot/web/panel/js/pages/commands/default.js
Normal file
185
libs/phantombot/web/panel/js/pages/commands/default.js
Normal file
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* 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() {
|
||||
// Query all commands.
|
||||
socket.getDBTableValues('commands_get_all', 'permcom', function(results) {
|
||||
socket.getDBTableValues('custom_commands_get_all', 'command', function(customCommands) {
|
||||
let tableData = [],
|
||||
cmds = [];
|
||||
|
||||
for (let i = 0; i < customCommands.length; i++) {
|
||||
cmds.push(customCommands[i].key);
|
||||
}
|
||||
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
if (cmds.indexOf(results[i].key) !== -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tableData.push([
|
||||
'!' + results[i].key,
|
||||
helpers.getGroupNameById(results[i].value),
|
||||
$('<div/>', {
|
||||
'class': 'btn-group'
|
||||
}).append($('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-xs btn-danger',
|
||||
'style': 'float: right',
|
||||
'data-toggle': 'tooltip',
|
||||
'title': 'Deletes the command permission and resets it to default on startup. This does not remove the command unless it doesn\'t exist anymore.',
|
||||
'data-command': results[i].key,
|
||||
'html': $('<i/>', {
|
||||
'class': 'fa fa-refresh'
|
||||
})
|
||||
})).append($('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-xs btn-warning',
|
||||
'style': 'float: right',
|
||||
'data-command': results[i].key,
|
||||
'html': $('<i/>', {
|
||||
'class': 'fa fa-edit'
|
||||
})
|
||||
})).html()
|
||||
]);
|
||||
}
|
||||
|
||||
// if the table exists, destroy it.
|
||||
if ($.fn.DataTable.isDataTable('#defaultCommandsTable')) {
|
||||
$('#defaultCommandsTable').DataTable().destroy();
|
||||
// Remove all of the old events.
|
||||
$('#defaultCommandsTable').off();
|
||||
}
|
||||
|
||||
// Create table.
|
||||
let table = $('#defaultCommandsTable').DataTable({
|
||||
'searching': true,
|
||||
'autoWidth': false,
|
||||
'data': tableData,
|
||||
'columnDefs': [
|
||||
{ 'className': 'default-table-large', 'orderable': false, 'targets': 2 },
|
||||
{ 'width': '45%', 'targets': 0 }
|
||||
],
|
||||
'columns': [
|
||||
{ 'title': 'Command' },
|
||||
{ 'title': 'User Level' },
|
||||
{ 'title': 'Actions' }
|
||||
]
|
||||
});
|
||||
|
||||
// On delete button.
|
||||
table.on('click', '.btn-danger', function() {
|
||||
let command = $(this).data('command'),
|
||||
row = $(this).parents('tr'),
|
||||
t = $(this);
|
||||
|
||||
// Ask the user if he want to reset the command.
|
||||
helpers.getConfirmDeleteModal('default_command_modal_remove', 'Are you sure you want to reset the command\'s permission?', false,
|
||||
'The command\'s permission has been reset!', function() {
|
||||
socket.removeDBValue('permcom_temp_del', 'permcom', command, function(e) {
|
||||
// Hide tooltip.
|
||||
t.tooltip('hide');
|
||||
// Remove the table row.
|
||||
table.row(row).remove().draw(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// On edit button.
|
||||
table.on('click', '.btn-warning', function() {
|
||||
let command = $(this).data('command'),
|
||||
t = $(this);
|
||||
|
||||
// Get all the info about the command.
|
||||
socket.getDBValues('default_command_edit', {
|
||||
tables: ['permcom', 'cooldown', 'pricecom', 'paycom'],
|
||||
keys: [command, command, command, command]
|
||||
}, function(e) {
|
||||
let cooldownJson = (e.cooldown === null ? { isGlobal: 'true', seconds: 0 } : JSON.parse(e.cooldown));
|
||||
|
||||
// Get advance modal from our util functions in /utils/helpers.js
|
||||
helpers.getAdvanceModal('edit-command', 'Edit Command', 'Save', $('<form/>', {
|
||||
'role': 'form'
|
||||
})
|
||||
// Append input box for the command name. This one is disabled.
|
||||
.append(helpers.getInputGroup('command-name', 'text', 'Command', '', '!' + command, 'Name of the command. This cannot be edited.', true))
|
||||
// Append a select option for the command permission.
|
||||
.append(helpers.getDropdownGroup('command-permission', 'User Level', helpers.getGroupNameById(e.permcom),
|
||||
['Caster', 'Administrators', 'Moderators', 'Subscribers', 'Donators', 'VIPs', 'Regulars', 'Viewers']))
|
||||
// Add an advance section that can be opened with a button toggle.
|
||||
.append($('<div/>', {
|
||||
'class': 'collapse',
|
||||
'id': 'advance-collapse',
|
||||
'html': $('<form/>', {
|
||||
'role': 'form'
|
||||
})
|
||||
// Append input box for the command cost.
|
||||
.append(helpers.getInputGroup('command-cost', 'number', 'Cost', '0', helpers.getDefaultIfNullOrUndefined(e.pricecom, '0'),
|
||||
'Cost in points that will be taken from the user when running the command.'))
|
||||
// Append input box for the command reward.
|
||||
.append(helpers.getInputGroup('command-reward', 'number', 'Reward', '0', helpers.getDefaultIfNullOrUndefined(e.paycom, '0'),
|
||||
'Reward in points the user will be given when running the command.'))
|
||||
// Append input box for the command cooldown.
|
||||
.append(helpers.getInputGroup('command-cooldown', 'number', 'Cooldown (Seconds)', '5', cooldownJson.seconds,
|
||||
'Cooldown of the command in seconds.')
|
||||
// Append checkbox for if the cooldown is global or per-user.
|
||||
.append(helpers.getCheckBox('command-cooldown-global', cooldownJson.isGlobal === 'true', 'Global',
|
||||
'If checked the cooldown will be applied to everyone in the channel. When not checked, the cooldown is applied per-user.')))
|
||||
// Callback function to be called once we hit the save button on the modal.
|
||||
})), function() {
|
||||
let commandPermission = $('#command-permission'),
|
||||
commandCost = $('#command-cost'),
|
||||
commandReward = $('#command-reward'),
|
||||
commandCooldown = $('#command-cooldown'),
|
||||
commandCooldownGlobal = $('#command-cooldown-global').is(':checked');
|
||||
|
||||
// Handle each input to make sure they have a value.
|
||||
switch (false) {
|
||||
case helpers.handleInputNumber(commandCost):
|
||||
case helpers.handleInputNumber(commandReward):
|
||||
case helpers.handleInputNumber(commandCooldown):
|
||||
break;
|
||||
default:
|
||||
// Save command information here and close the modal.
|
||||
socket.updateDBValues('custom_command_edit', {
|
||||
tables: ['pricecom', 'paycom'],
|
||||
keys: [command, command],
|
||||
values: [commandCost.val(), commandReward.val()]
|
||||
}, function() {
|
||||
// Add the cooldown to the cache.
|
||||
socket.wsEvent('default_command_edit_cooldown_ws', './core/commandCoolDown.js', null,
|
||||
['add', command, commandCooldown.val(), String(commandCooldownGlobal)], function() {
|
||||
// Edit the command permission.
|
||||
socket.sendCommand('default_command_permisison_update', 'permcomsilent ' + command + ' ' +
|
||||
helpers.getGroupIdByName(commandPermission.find(':selected').text(), true), function() {
|
||||
// Update user level value.
|
||||
t.parents('tr').find('td:eq(1)').text(commandPermission.find(':selected').text());
|
||||
// Close the modal.
|
||||
$('#edit-command').modal('hide');
|
||||
// Tell the user the command was edited.
|
||||
toastr.success('Successfully edited command !' + command);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}).modal('toggle');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user