From 2e99ff0120fb4145859497efdce240ff044da92f Mon Sep 17 00:00:00 2001 From: asanrom Date: Thu, 22 Sep 2016 22:02:28 +0200 Subject: [PATCH] Use JQuery request for refreshing the bot status --- src/server/handlers/bot.js | 59 +++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/src/server/handlers/bot.js b/src/server/handlers/bot.js index 03bd74e..c2326e8 100644 --- a/src/server/handlers/bot.js +++ b/src/server/handlers/bot.js @@ -25,6 +25,31 @@ App.server.setHandler('bot', (context, parts) => { return; } + if (context.get.getbotstatus) { + let data = {}; + if (App.bot.status.connected) { + data.con = 'CONNECTED'; + } else if (App.bot.connecting) { + data.con = 'CONNECTING...'; + } else { + data.con = 'NOT CONNECTED'; + } + data.nick = (App.bot.getBotNick() || "-"); + data.rooms = []; + for (let r in App.bot.rooms) { + if (App.bot.rooms[r].type === 'chat') { + data.rooms.push(App.bot.rooms[r].id); + } + } + data.battles = []; + for (let r in App.bot.rooms) { + if (App.bot.rooms[r].type === 'battle') { + data.battles.push(App.bot.rooms[r].id); + } + } + return context.endWithText(JSON.stringify(data)); + } + /* Actions */ let ok = null, error = null; if (context.post.restart) { @@ -80,6 +105,20 @@ App.server.setHandler('bot', (context, parts) => { /* Generate HTML */ let html = ''; + html += ''; html += ''; @@ -92,15 +131,15 @@ App.server.setHandler('bot', (context, parts) => { html += '
Bot Status
'; html += 'Connection'; if (App.bot.status.connected) { - html += 'CONNECTED'; + html += 'CONNECTED'; } else if (App.bot.connecting) { - html += 'CONNECTING...'; + html += 'CONNECTING...'; } else { - html += 'NOT CONNECTED'; + html += 'NOT CONNECTED'; } html += ''; - html += 'Nickname' + (App.bot.getBotNick() || "-") + ''; - html += 'Rooms'; + html += 'Nickname' + (App.bot.getBotNick() || "-") + ''; + html += 'Rooms'; let rooms = []; for (let r in App.bot.rooms) { if (App.bot.rooms[r].type === 'chat') { @@ -108,8 +147,8 @@ App.server.setHandler('bot', (context, parts) => { } } html += rooms.join(', '); - html += ''; - html += 'Battles'; + html += ''; + html += 'Battles'; let battles = []; for (let r in App.bot.rooms) { if (App.bot.rooms[r].type === 'battle') { @@ -117,10 +156,10 @@ App.server.setHandler('bot', (context, parts) => { } } html += battles.join(', '); - html += ''; + html += ''; html += ''; html += ''; - html += '

'; + html += '

  

'; html += '

 

'; if (App.status !== 'stopped') { html += '

 

'; @@ -152,5 +191,5 @@ App.server.setHandler('bot', (context, parts) => { html += '

' + ok + '

'; } - context.endWithWebPage(html, {title: "Bot Configuration - Showdown ChatBot"}); + context.endWithWebPage(html, {title: "Bot Configuration - Showdown ChatBot", scripts: ['/static/jquery-3.0.0.min.js']}); });