WIP
This commit is contained in:
		@@ -1,7 +1,5 @@
 | 
				
			|||||||
(function() {
 | 
					(function() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    function fetchSeed(id) {
 | 
					    function fetchSeed(id) {
 | 
				
			||||||
        var HttpRequest = Packages.com.gmt2001.HttpRequest,
 | 
					        var HttpRequest = Packages.com.gmt2001.HttpRequest,
 | 
				
			||||||
        HashMap = Packages.java.util.HashMap,
 | 
					        HashMap = Packages.java.util.HashMap,
 | 
				
			||||||
@@ -164,7 +162,6 @@
 | 
				
			|||||||
            }else if(action.equalsIgnoreCase('refresh')){
 | 
					            }else if(action.equalsIgnoreCase('refresh')){
 | 
				
			||||||
                var newseed = GameHelper.fetchSeed(args[1]);
 | 
					                var newseed = GameHelper.fetchSeed(args[1]);
 | 
				
			||||||
            }else if(action.equalsIgnoreCase('gg')){
 | 
					            }else if(action.equalsIgnoreCase('gg')){
 | 
				
			||||||
                console.log("GOT: GG")
 | 
					 | 
				
			||||||
                sendData('guesses',JSON.stringify(guesses));
 | 
					                sendData('guesses',JSON.stringify(guesses));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (C) 2016-2019 phantombot.tv
 | 
					 * Copyright (C) 2016-2021 phantombot.github.io/PhantomBot
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 * 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
 | 
					 * it under the terms of the GNU General Public License as published by
 | 
				
			||||||
@@ -15,53 +15,30 @@
 | 
				
			|||||||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
					 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//NOTE: this is straight copied from panel's index.js
 | 
					 | 
				
			||||||
// Main socket and functions.
 | 
					// Main socket and functions.
 | 
				
			||||||
$(function () {
 | 
					$(function () {
 | 
				
			||||||
 | 
					    if (!helpers.isLocalPanel()) {
 | 
				
			||||||
 | 
					        $.ajax(
 | 
				
			||||||
    var helpers = {};
 | 
					                {
 | 
				
			||||||
 | 
					                    type: 'GET',
 | 
				
			||||||
    helpers.DEBUG_STATES = {
 | 
					                    url: 'https://' + helpers.getBotHost() + '/sslcheck',
 | 
				
			||||||
        NONE: 0,
 | 
					                    crossDomain: true,
 | 
				
			||||||
        DEBUG: 1,
 | 
					                    dataType: 'text',
 | 
				
			||||||
        INFO: 2,
 | 
					                    async: false,
 | 
				
			||||||
        FORCE: 3
 | 
					                    success: function (data) {
 | 
				
			||||||
    };
 | 
					                        if (data === 'false') {
 | 
				
			||||||
    // Debug status. 0 = off | 1 = on.
 | 
					                            window.location = window.location.origin + window.location.pathname + 'login/#sslFail=true';
 | 
				
			||||||
    helpers.DEBUG_STATE = (localStorage.getItem('phantombot_debug_state') !== null ? parseInt(localStorage.getItem('phantombot_debug_state')) : helpers.DEBUG_STATES.NONE);
 | 
					 | 
				
			||||||
    // Debug types.
 | 
					 | 
				
			||||||
    helpers.LOG_TYPE = helpers.DEBUG_STATES;
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
     * @function Used to print debug messages in the console.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @param {String}  message
 | 
					 | 
				
			||||||
     * @param {Number} type
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    helpers.log = function(message, type) {
 | 
					 | 
				
			||||||
        if (helpers.DEBUG_STATE === helpers.DEBUG_STATES.DEBUG || type === helpers.DEBUG_STATE || type === helpers.LOG_TYPE.FORCE) {
 | 
					 | 
				
			||||||
            console.log('%c[PhantomBot Log]', 'color: #6441a5; font-weight: 900;', message);
 | 
					 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
    };
 | 
					                    },
 | 
				
			||||||
 | 
					                    error: function () {
 | 
				
			||||||
    /*
 | 
					                        window.location = window.location.origin + window.location.pathname + 'login/#sslFail=true';
 | 
				
			||||||
     * @function Used to print error messages in the console.
 | 
					                    }
 | 
				
			||||||
     *
 | 
					                }
 | 
				
			||||||
     * @param {String}  message
 | 
					        );
 | 
				
			||||||
     * @param {Number} type
 | 
					    }
 | 
				
			||||||
     */
 | 
					    var webSocket = new ReconnectingWebSocket((window.location.protocol === 'https:' ? 'wss://' : 'ws://') + helpers.getBotHost() + '/ws/panel?target=' + helpers.getBotHost(), null, {reconnectInterval: 500}),
 | 
				
			||||||
    helpers.logError = function(message, type) {
 | 
					 | 
				
			||||||
        console.log('%c[PhantomBot Error]', 'color: red; font-weight: 900;', message);
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    var webSocket = new ReconnectingWebSocket((getProtocol() === 'https://' || window.location.protocol === 'https:' ? 'wss://' : 'ws://') + 'twitchbot.helcel.net' + '/ws/panel', null, { reconnectInterval: 500 }),
 | 
					 | 
				
			||||||
            callbacks = [],
 | 
					            callbacks = [],
 | 
				
			||||||
            listeners = [],
 | 
					            listeners = [],
 | 
				
			||||||
        familyHandlers = {},
 | 
					 | 
				
			||||||
            socket = {};
 | 
					            socket = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
@@ -110,7 +87,7 @@ $(function() {
 | 
				
			|||||||
                        callback(e);
 | 
					                        callback(e);
 | 
				
			||||||
                    } catch (ex) {
 | 
					                    } catch (ex) {
 | 
				
			||||||
                        // Line number won't be accurate, function will by anonymous, but we get the stack so it should be fine.
 | 
					                        // Line number won't be accurate, function will by anonymous, but we get the stack so it should be fine.
 | 
				
			||||||
                        helpers.logError('Failed to run callback: ' + ex.stack, helpers.LOG_TYPE.FORCE);
 | 
					                        helpers.logError('Failed to run callback: (' + ex.name + ') ' + ex.message + ' >> ' + ex.stack, helpers.LOG_TYPE.FORCE);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                storeKey: storeKey,
 | 
					                storeKey: storeKey,
 | 
				
			||||||
@@ -127,13 +104,13 @@ $(function() {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    socket.addListener = function (listener_id, callback) {
 | 
					    socket.addListener = function (listener_id, callback) {
 | 
				
			||||||
        if (listeners[listener_id] === undefined) {
 | 
					        if (listeners[listener_id] === undefined) {
 | 
				
			||||||
            helpers.log('Adding listener with id ' + listener_id);
 | 
					            helpers.log('Added listener with id ' + listener_id);
 | 
				
			||||||
            listeners[listener_id] = function (e) {
 | 
					            listeners[listener_id] = function (e) {
 | 
				
			||||||
                try {
 | 
					                try {
 | 
				
			||||||
                    callback(e);
 | 
					                    callback(e);
 | 
				
			||||||
                } catch (ex) {
 | 
					                } catch (ex) {
 | 
				
			||||||
                    // Line number won't be accurate, function will by anonymous, but we get the stack so it should be fine.
 | 
					                    // Line number won't be accurate, function will by anonymous, but we get the stack so it should be fine.
 | 
				
			||||||
                    helpers.logError('Failed to run listener: ' + ex.stack, helpers.LOG_TYPE.FORCE);
 | 
					                    helpers.logError('Failed to run listener: (' + ex.name + ') ' + ex.message + ' >> ' + ex.stack, helpers.LOG_TYPE.FORCE);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -150,23 +127,6 @@ $(function() {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    socket.addFamilyHandler = function(familyName, callback) {
 | 
					 | 
				
			||||||
        familyHandlers[familyName] = function(e) {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                callback(e);
 | 
					 | 
				
			||||||
            } catch (ex) {
 | 
					 | 
				
			||||||
                // Line number won't be accurate, function will by anonymous, but we get the stack so it should be fine.
 | 
					 | 
				
			||||||
                helpers.logError('Failed to run family handler: ' + ex.stack, helpers.LOG_TYPE.FORCE);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    socket.removeFamilyHandler = function(familyName) {
 | 
					 | 
				
			||||||
        if (familyHandlers[familyName] !== undefined) {
 | 
					 | 
				
			||||||
            delete listeners[familyName];
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
     * @function Runs a bot commands as the bot in async, thus returning right away.
 | 
					     * @function Runs a bot commands as the bot in async, thus returning right away.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@@ -243,6 +203,16 @@ $(function() {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    socket.getDiscordChannelList = function (callback_id, callback) {
 | 
				
			||||||
 | 
					        // Genetate a callback.
 | 
				
			||||||
 | 
					        socket.addListener(callback_id, callback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Send event.
 | 
				
			||||||
 | 
					        sendToSocket({
 | 
				
			||||||
 | 
					            discordchannellist: callback_id
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
     * @function Updates a value in the database of the bot.
 | 
					     * @function Updates a value in the database of the bot.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@@ -373,7 +343,7 @@ $(function() {
 | 
				
			|||||||
        callback = (callback === undefined ? storeKey : callback);
 | 
					        callback = (callback === undefined ? storeKey : callback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Genetate a callback.
 | 
					        // Genetate a callback.
 | 
				
			||||||
        generateCallBack(callback_id, dataObj.tables, false, false, callback, (typeof storeKey === 'function' ? false : true));
 | 
					        generateCallBack(callback_id, dataObj.tables, false, false, callback, (typeof storeKey !== 'function'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Start sending the updates to the socket.
 | 
					        // Start sending the updates to the socket.
 | 
				
			||||||
        for (let i = 0; i < dataObj.tables.length; i++) {
 | 
					        for (let i = 0; i < dataObj.tables.length; i++) {
 | 
				
			||||||
@@ -497,15 +467,40 @@ $(function() {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // WebSocket events.
 | 
					    /*
 | 
				
			||||||
 | 
					     * @function Sends a remote panel query.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param {String}   query_id
 | 
				
			||||||
 | 
					     * @param {String}   query
 | 
				
			||||||
 | 
					     * @param {Object}   params
 | 
				
			||||||
 | 
					     * @param {Function} callback
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    socket.doRemote = function (query_id, query, params, callback) {
 | 
				
			||||||
 | 
					        generateCallBack(query_id, [], false, true, callback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    socket.getReadyState = function() {return webSocket.readyState;}
 | 
					        sendToSocket({
 | 
				
			||||||
 | 
					            remote: true,
 | 
				
			||||||
 | 
					            id: query_id,
 | 
				
			||||||
 | 
					            query: query,
 | 
				
			||||||
 | 
					            params: params
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    socket.close = function () {
 | 
				
			||||||
 | 
					        webSocket.close(1000);
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // WebSocket events.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
     * @function Called when the socket opens.
 | 
					     * @function Called when the socket opens.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    webSocket.onopen = function () {
 | 
					    webSocket.onopen = function () {
 | 
				
			||||||
        helpers.log('Connection established with the websocket.', helpers.LOG_TYPE.FORCE);
 | 
					        helpers.log('Connection established with the websocket.', helpers.LOG_TYPE.FORCE);
 | 
				
			||||||
 | 
					        // Restart Pace.
 | 
				
			||||||
 | 
					        Pace.restart();
 | 
				
			||||||
 | 
					        // Remove all alerts.
 | 
				
			||||||
 | 
					        toastr.remove();
 | 
				
			||||||
        // Auth with the socket.
 | 
					        // Auth with the socket.
 | 
				
			||||||
        sendToSocket({
 | 
					        sendToSocket({
 | 
				
			||||||
            authenticate: getAuth()
 | 
					            authenticate: getAuth()
 | 
				
			||||||
@@ -517,6 +512,8 @@ $(function() {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    webSocket.onclose = function () {
 | 
					    webSocket.onclose = function () {
 | 
				
			||||||
        helpers.logError('Connection lost with the websocket.', helpers.LOG_TYPE.FORCE);
 | 
					        helpers.logError('Connection lost with the websocket.', helpers.LOG_TYPE.FORCE);
 | 
				
			||||||
 | 
					        // Add error toast.
 | 
				
			||||||
 | 
					        toastr.error('Connection lost with the websocket.', '', {timeOut: 0});
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
@@ -537,6 +534,7 @@ $(function() {
 | 
				
			|||||||
            if (message.authresult !== undefined) {
 | 
					            if (message.authresult !== undefined) {
 | 
				
			||||||
                if (message.authresult === 'false') {
 | 
					                if (message.authresult === 'false') {
 | 
				
			||||||
                    helpers.logError('Failed to auth with the socket.', helpers.LOG_TYPE.FORCE);
 | 
					                    helpers.logError('Failed to auth with the socket.', helpers.LOG_TYPE.FORCE);
 | 
				
			||||||
 | 
					                    toastr.error('Failed to auth with the socket.', '', {timeOut: 0});
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    // This is to stop a reconnect loading the main page.
 | 
					                    // This is to stop a reconnect loading the main page.
 | 
				
			||||||
                    if (helpers.isAuth === true) {
 | 
					                    if (helpers.isAuth === true) {
 | 
				
			||||||
@@ -545,22 +543,31 @@ $(function() {
 | 
				
			|||||||
                        helpers.isAuth = true;
 | 
					                        helpers.isAuth = true;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    // XXX: revent loading main page
 | 
					                    sendToSocket({
 | 
				
			||||||
                    //$.loadPage('dashboard', 'dashboard.html');
 | 
					                        remote: true,
 | 
				
			||||||
 | 
					                        id: 'initLoad.panelSettings',
 | 
				
			||||||
 | 
					                        query: 'panelSettings'
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (message.id !== undefined) {
 | 
				
			||||||
 | 
					                if (message.id === 'initLoad.panelSettings') {
 | 
				
			||||||
 | 
					                    window.panelSettings.channelName = message.channelName;
 | 
				
			||||||
 | 
					                    window.panelSettings.displayName = message.displayName;
 | 
				
			||||||
 | 
					                    $.loadPage('dashboard', 'dashboard.html');
 | 
				
			||||||
 | 
					                    helpers.getUserLogo();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Make sure this isn't a version request.
 | 
					            // Make sure this isn't a version request.
 | 
				
			||||||
            if (message.versionresult !== undefined) {
 | 
					            if (message.versionresult !== undefined) {
 | 
				
			||||||
                // Call the callback.
 | 
					                // Call the callback.
 | 
				
			||||||
                callbacks[message.versionresult].func(message);
 | 
					                callbacks[message.versionresult].func(message);
 | 
				
			||||||
                // Delete the callback.
 | 
					                // Delete the callback.
 | 
				
			||||||
                delete callbacks[message.versionresult];
 | 
					                delete callbacks[message.versionresult];
 | 
				
			||||||
            } else if(message.query_id !== undefined) {
 | 
					            } else {
 | 
				
			||||||
 | 
					 | 
				
			||||||
                // console.log("base got websocket with data");
 | 
					 | 
				
			||||||
                // console.log(e);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // Handle callbacks.
 | 
					                // Handle callbacks.
 | 
				
			||||||
                let callback = callbacks[message.query_id],
 | 
					                let callback = callbacks[message.query_id],
 | 
				
			||||||
@@ -595,7 +602,7 @@ $(function() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                        if (message.query_id.indexOf('module_toggle') !== -1 || message.query_id.indexOf('module_status') !== -1
 | 
					                        if (message.query_id.indexOf('module_toggle') !== -1 || message.query_id.indexOf('module_status') !== -1
 | 
				
			||||||
                                || message.query_id.endsWith('module')) {
 | 
					                                || message.query_id.endsWith('module')) {
 | 
				
			||||||
                            if (message.results.value == 'false') {
 | 
					                            if (message.results !== undefined && message.results.value == 'false') {
 | 
				
			||||||
                                $('.load-ajax').remove();
 | 
					                                $('.load-ajax').remove();
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
@@ -606,11 +613,6 @@ $(function() {
 | 
				
			|||||||
                    // Call the listener.
 | 
					                    // Call the listener.
 | 
				
			||||||
                    listener(message.results);
 | 
					                    listener(message.results);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } else if(message.eventFamily !== undefined) {
 | 
					 | 
				
			||||||
                let handler = familyHandlers[message.eventFamily];
 | 
					 | 
				
			||||||
                if(handler !== undefined) {
 | 
					 | 
				
			||||||
                    handler(e)
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } catch (ex) {
 | 
					        } catch (ex) {
 | 
				
			||||||
            // Line number won't be accurate, function will by anonymous, but we get the stack so it should be fine.
 | 
					            // Line number won't be accurate, function will by anonymous, but we get the stack so it should be fine.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user