Callback to Control panel


#1

Hello everyone,

I’m getting more and more into writing custom scripts for Phantombot and with a little help from TheRealAlixe I’ve been able to integrate these options for scripts into the control panel. (See The Challenge! Automated, Randomized Fighting Chat Game! for an example)

My simple question is this, is there a method to inform the user on the control panel that a desired change is invalid or successful without having to post it to console or chat?


#2

Yes. It’s just HTML and javascript that displays the control panel, so generally speaking, anything you can do with those languages, you can do in the control panel.

A few of the pages make use of replacing the input field with an error message, then blanking it to default.

Here’s an example, this is the code used to add a command via the web panel:

function addCustomCommand() {
    var command = $('#addCommandCommand').val();
    var commandText = $('#addCommandText').val();

    if (command.length == 0) {
        $('#addCommandCommand').val('[ERROR] Please enter a value.');
        $('#addCommandText').val('');
        setTimeout(function() { $('#addCommandCommand').val(''); }, TIMEOUT_WAIT_TIME * 10);
        return;
    } else if (commandText.length == 0) {
        $('#addCommandText').val('[ERROR] Please enter a value.');
        $('#addCommandCommand').val('');
        setTimeout(function() { $('#addCommandText').val(''); }, TIMEOUT_WAIT_TIME * 10);
        return;
    } else if (command.match(/\s+/)) {
        $('#addCommandCommand').val('[ERROR] Your command cannot contain a space.');
        $('#addCommandText').val('');
        setTimeout(function() { $('#addCommandCommand').val(''); }, TIMEOUT_WAIT_TIME * 10);
        return;
    } else if (botCommands.indexOf(command) !== -1) {
        $('#addCommandCommand').val('[ERROR] Command already exists.');
        $('#addCommandText').val('');
        setTimeout(function() { $('#addCommandCommand').val(''); }, TIMEOUT_WAIT_TIME * 10);
        return;
    }

    command = command.replace('!', '');

    $('#addCommandText').val('Command successfully added!'); 
    sendDBUpdate('addCustomCommand', 'command', command.toLowerCase(), commandText);
    sendWSEvent('commands', './commands/customCommands.js', null, ['add', command, commandText]);
    setTimeout(function() { 
        $('#addCommandText').val(''); 
        $('#addCommandCommand').val(''); 
        sendCommand('reloadcommand'); 
        doQuery(); 
    }, TIMEOUT_WAIT_TIME);
};

#3

Thanks a lot, this will definitely help improving user-friendliness