diff --git a/menu/bot/bot.js b/menu/bot/bot.js index 3ffdd56..45e5d48 100644 --- a/menu/bot/bot.js +++ b/menu/bot/bot.js @@ -1,17 +1,31 @@ -//--------------------------------------------Modules--------------------------------------------// +//---------------------------------------------------------------------// +// Modules +// +// This is where you put the NPM Modules to use in this file. +//---------------------------------------------------------------------// + var path = require('path'); var fse = require('fs-extra'); -const { exec } = require('child_process'); - +var {exec} = require('child_process'); var $ = jQuery = require('jquery'); -//-----------------------------------------------------------------------------------------------// - +//---------------------------------------------------------------------// +// JSON OBJ +// +// Use these JSON objects that contain the App Data. +// obj -> data.json +// obj_bot -> bot_data.json +//---------------------------------------------------------------------// var obj = JSON.parse(fse.readFileSync(dataDataPath, 'utf8')); var obj_bot = JSON.parse(fse.readFileSync(BotDataPath, 'utf8')); -// Load values +//---------------------------------------------------------------------// +// Load Values +// +// Loads values from JSON files. +//---------------------------------------------------------------------// + $('#BotBackupSelect').val(obj_bot.Backup_Timer_Type); $('#BotBackupAmount').val(obj_bot.Backup_Timer_Value); @@ -19,62 +33,102 @@ if($('#BotBackupSelect').val() == 1) { $('#BotBackupAmount').prop('disabled', true); } -function BotStartClick() { - // Check if Bot Path exists and is valid +//---------------------------------------------------------------------// +// function BotConsoleLog(text) +// +// This function sends text to Bot Console Log. +//---------------------------------------------------------------------// + +function BotConsoleLog(text) { + $('#BotConsoleLog').append(text); + if(!$('#BotConsoleLog').is(':visible')) { + $('#BotConsoleLogNumber').html(parseInt($('#BotConsoleLogNumber').text(),10) + 1 || 1) + } +} + +//---------------------------------------------------------------------// +// function CheckIfDBMPathExists() +// +// This function checks if DBM Path exists and is valid. +//---------------------------------------------------------------------// + +function CheckIfDBMPathExists() { + if(obj.DBM_Path == "") { + BotConsoleLog(`${new Date().toTimeString().slice(0,8)} - ERROR: DBM Path isn't set in Settings\n`); + return; + } + + if(!fse.existsSync(obj.DBM_Path)) { + BotConsoleLog(`${new Date().toTimeString().slice(0,8)} - ERROR: DBM Path isn't valid\n`); + return; + } +} + +//---------------------------------------------------------------------// +// function CheckIfBotPathExists() +// +// This function checks if Bot Path exists and is valid. +//---------------------------------------------------------------------// + +function CheckIfBotPathExists() { if(obj.Bot_Path == "") { - $('#BotConsoleLog').append(`${new Date().toTimeString().slice(0,8)} - ERROR: Bot Path isn't set in Settings\n`); + BotConsoleLog(`${new Date().toTimeString().slice(0,8)} - ERROR: Bot Path isn't set in Settings\n`); return; } if(!fse.existsSync(obj.Bot_Path)) { - $('#BotConsoleLog').append(`${new Date().toTimeString().slice(0,8)} - ERROR: Bot Path isn't valid\n`); + BotConsoleLog(`${new Date().toTimeString().slice(0,8)} - ERROR: Bot Path isn't valid\n`); return; } +} + +//---------------------------------------------------------------------// +// function BotStartClick() +// +// This is the function that starts your bot when you +// press the Start button on Bot tab. +//---------------------------------------------------------------------// + +function BotStartClick() { + //-----------------------------Check if Bot Path exists and is valid-----------------------------// + CheckIfBotPathExists(); //-----------------------------------------------------------------------------------------------// + const grep = process.platform === "win32" ? exec(`start cmd.exe /k "cd "${obj.Bot_Path}" && node bot.js"`) : exec(`gnome-terminal --command="bash -c 'cd ${(obj.Bot_Path).replace(/\ /g, "\\ ")}; node bot.js; ls; $SHELL'"`); - $('#BotConsoleLog').append(`${new Date().toTimeString().slice(0,8)} - Bot Started\n`); + BotConsoleLog(`${new Date().toTimeString().slice(0,8)} - Bot Started\n`); if(process.platform === "win32") { // Linux doesn't detect this... grep.on('close', (code, signal) => { - $('#BotConsoleLog').append(`${new Date().toTimeString().slice(0,8)} - Bot Stopped\n`); + BotConsoleLog(`${new Date().toTimeString().slice(0,8)} - Bot Stopped\n`); }); } grep.on('error', (err) => { - $('#BotConsoleLog').append(`${new Date().toTimeString().slice(0,8)} - ERROR: ${err}\n`); + BotConsoleLog(`${new Date().toTimeString().slice(0,8)} - ERROR: ${err}\n`); }); } +//---------------------------------------------------------------------// +// function BotCopyActionsClick() +// +// This is the function that copies and pastes your actions folder +// on your bot folder when you press the Copy DBM Actions Folder +// button on Bot tab. +//---------------------------------------------------------------------// + function BotCopyActionsClick() { const start = new Date(); var processB1 = 0; - $('#BotConsoleLog').append(`${new Date().toTimeString().slice(0,8)} - Copying and pasting DBM Actions Folder...\n`); + BotConsoleLog(`${new Date().toTimeString().slice(0,8)} - Copying and pasting DBM Actions Folder...\n`); - // Check if DBM Path exists and is valid - if(obj.DBM_Path == "") { - $('#BotConsoleLog').append(`${new Date().toTimeString().slice(0,8)} - ERROR: DBM Path isn't set in Settings\n`); - return; - } - if(!fse.existsSync(obj.DBM_Path)) { - $('#BotConsoleLog').append(`${new Date().toTimeString().slice(0,8)} - ERROR: DBM Path isn't valid\n`); - return; - } + //------------------------Check if DBM Path and Bot Path exists and is valid---------------------// + CheckIfDBMPathExists(); + CheckIfBotPathExists(); //-----------------------------------------------------------------------------------------------// - // Check if Bot Path exists and is valid - if(obj.Bot_Path == "") { - $('#BotConsoleLog').append(`${new Date().toTimeString().slice(0,8)} - ERROR: Bot Path isn't set in Settings\n`); - return; - } - - if(!fse.existsSync(obj.Bot_Path)) { - $('#BotConsoleLog').append(`${new Date().toTimeString().slice(0,8)} - ERROR: Bot Path isn't valid\n`); - return; - } - //-----------------------------------------------------------------------------------------------// fse.readdirSync(path.join(obj.DBM_Path, "actions")).forEach(function(file, index, arr) { if(file.match(/^.+\.js$/i)) { @@ -83,12 +137,20 @@ function BotCopyActionsClick() { } processB1++; if(processB1 === arr.length) { - $('#BotConsoleLog').append(`${new Date().toTimeString().slice(0,8)} - DBM Actions Folder copied and pasted in your Bot successfully! (${((new Date() - start)*10**-3).toFixed(3)}s)\n`); + BotConsoleLog(`${new Date().toTimeString().slice(0,8)} - DBM Actions Folder copied and pasted in your Bot successfully! (${((new Date() - start)*10**-3).toFixed(3)}s)\n`); } }); } -BotBackupSelectOnChange(); +//---------------------------------------------------------------------// +// function BotBackupSelectOnChange() +// +// This is the function that makes the backup data folder system +// work. +//---------------------------------------------------------------------// + +BotBackupSelectOnChange(); //Executes the function BotBackupSelectOnChange() on start of the app + function BotBackupSelectOnChange() { const BackupSelectValue = $("#BotBackupSelect").val(); let timesetBackup = null; @@ -112,16 +174,8 @@ function BotBackupSelectOnChange() { if (!isNaN(BackupSelectValue) && timesetBackup != null) { this.currentInterval = setInterval(function() { - // Check if Bot Path exists and is valid - if(obj.Bot_Path == "") { - $('#BotConsoleLog').append(`${new Date().toTimeString().slice(0,8)} - ERROR: Bot Path isn't set in Settings\n`); - return; - } - - if(!fse.existsSync(obj.Bot_Path)) { - $('#BotConsoleLog').append(`${new Date().toTimeString().slice(0,8)} - ERROR: Bot Path isn't valid\n`); - return; - } + //-----------------------------Check if Bot Path exists and is valid-----------------------------// + CheckIfBotPathExists(); //-----------------------------------------------------------------------------------------------// const d = new Date(); @@ -129,12 +183,13 @@ function BotBackupSelectOnChange() { fse.ensureDirSync(path.join(BackupsPath, fname)); fse.copySync(path.join(obj.Bot_Path, "data"), path.join(BackupsPath, fname)); - $('#BotConsoleLog').append(`${d.toTimeString().slice(0,8)} - New backup folder created: ${fname}\n`); + BotConsoleLog(`${d.toTimeString().slice(0,8)} - New backup folder created: ${fname}\n`); }, timesetBackup); }; -// Store value in Data +//------------------------------------Store value in Data----------------------------------------// obj_bot.Backup_Timer_Value = $("#BotBackupAmount").val(); obj_bot.Backup_Timer_Type = BackupSelectValue; fse.writeFileSync(BotDataPath, JSON.stringify(obj_bot)); +//-----------------------------------------------------------------------------------------------// } \ No newline at end of file diff --git a/menu/menu/menu.ejs b/menu/menu/menu.ejs index fbd9856..e523bbe 100644 --- a/menu/menu/menu.ejs +++ b/menu/menu/menu.ejs @@ -6,7 +6,7 @@ <% include ../../menu/sidebar/sidebar %> -
+

DBM Network Client

-
+

Mods

-
+

Bot

-
+

Settings

-
+

Changelog

© DBM Network

diff --git a/menu/sidebar/sidebar.js b/menu/sidebar/sidebar.js index 02f28fd..5770a50 100644 --- a/menu/sidebar/sidebar.js +++ b/menu/sidebar/sidebar.js @@ -1,74 +1,49 @@ -//--------------------------------------------Modules--------------------------------------------// -var electron = require('electron'); -const {ipcRenderer} = electron; +//---------------------------------------------------------------------// +// Modules +// +// This is where you put the NPM Modules to use in this file. +//---------------------------------------------------------------------// +var electron = require('electron'); +var {ipcRenderer} = electron; var $ = jQuery = require('jquery'); -//-----------------------------------------------------------------------------------------------// - +//---------------------------------------------------------------------// +// Transition Between Tabs +// +// This is the system that make transition between tabs when you +// click in a new tab button. +//---------------------------------------------------------------------// -var blockerClick = false; +var blockerClick = false; // Anti-abuse system for when you click quickly on sidebar buttons -function ModsTabClick() { - if(blockerClick === false) { +function ButtonTabClick(Window, TabName) { + if(blockerClick === false && !$(Window).is(":visible")) { blockerClick = true; - $('#BotWindow').fadeOut(200); - $('#SettingsWindow').fadeOut(200); - $('#ChangelogWindow').fadeOut(200); - setTimeout(() => { - $('#ModsWindow').fadeIn(200); - ipcRenderer.send('mode:changed', 'Mods'); - blockerClick = false; - }, 200); - } -} -function BotTabClick() { - if(blockerClick === false) { - blockerClick = true; - $('#ModsWindow').fadeOut(200); - $('#SettingsWindow').fadeOut(200); - $('#ChangelogWindow').fadeOut(200); - setTimeout(() => { - $('#BotWindow').fadeIn(200); - ipcRenderer.send('mode:changed', 'Bot'); + $('#MenuAllWindows > div').fadeOut(200).promise().done(function() { + $(Window).fadeIn(200) + ipcRenderer.send('mode:changed', TabName); blockerClick = false; - }, 200); + }); } } -function SettingsTabClick() { - if(blockerClick === false) { - blockerClick = true; - $('#ModsWindow').fadeOut(200); - $('#BotWindow').fadeOut(200); - $('#ChangelogWindow').fadeOut(200); - setTimeout(() => { - $('#SettingsWindow').fadeIn(200); - ipcRenderer.send('mode:changed', 'Settings'); - blockerClick = false; - }, 200); - } -} - -function ChangelogTabClick() { - if(blockerClick === false) { - blockerClick = true; - $('#ModsWindow').fadeOut(200); - $('#BotWindow').fadeOut(200); - $('#SettingsWindow').fadeOut(200); - setTimeout(() => { - $('#ChangelogWindow').fadeIn(200); - ipcRenderer.send('mode:changed', 'Changelog'); - blockerClick = false; - }, 200); - } -} +//---------------------------------------------------------------------// +// Show Current App Version +// +// This shows the current version of the app in the bottom corner. +//---------------------------------------------------------------------// $('#SlidebarAppVersion').html(require('electron').remote.app.getVersion()); -//------------Electron Updater Stuff------------ +//---------------------------------------------------------------------// +// Electron Auto Updater Status +// +// This shows the status of auto-updater in the bottom corner. +// The system is in main.js file. +//---------------------------------------------------------------------// + ipcRenderer.on('ElectronUpdaterMES', function(event, text) { $('#SlidebarElectronUPStatus').html("- " + text); -}); -//---------------------------------------------- \ No newline at end of file +}); \ No newline at end of file