// Copyright (C) 2021
// Authors:
// Name / Email / Website
// Twitter / Twitch / Youtube / Github
// Authors:
// Alex Orid / inquiries@thecuriousnerd.com / TheCuriousNerd.com
// Twitter: @TheCuriousNerd / Twitch: TheCuriousNerd / Youtube: thecuriousnerd / Github: TheCuriousNerd
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero 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 Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
refresh = () => response = fetch('http://127.0.0.1:42055/')
.then((response) => {
return response.text();
})
ConnectionTest = async () => {
var a = await refresh();
console.log(a)
return a
}
async function BotStatus() {
var connectionStatus = await ConnectionTest();
document.getElementById("BotStatus").innerHTML = connectionStatus;
}
BotStatus();
async function setValue(request_type, command, isEnabled) {
let newCommandState = {
'request_type': request_type,
'command_name': command,
'is_enabled': isEnabled
}
let params = "?command_name="+encodeURIComponent(newCommandState.command_name)+"&"+"is_enabled="+encodeURIComponent(newCommandState.is_enabled);
let targetURL = "http://127.0.0.1:42055/api/v1/user_client/set"+params;
//console.log(targetURL)
let a = await fetch_GetList(targetURL);
//console.log("return: "+a);
}
fetch_GetList = (fetchURL) => response = fetch(fetchURL)
.then((response) => {
return response.text();
})
GetList = async (listType) => {
if (true) {
let ListRequestOBJ = {
'request_name': listType,
'request_type': "list"
}
let params = "?request_name="+encodeURIComponent(ListRequestOBJ.request_name)+"&"+"request_type="+encodeURIComponent(ListRequestOBJ.request_type);
let targetURL = "http://127.0.0.1:42055/api/v1/user_client/get"+params;
//console.log(targetURL)
let a = await fetch_GetList(targetURL);
//console.log("return: "+a);
return a
}
else {
return None
}
}
async function GetList_OBJ(ListName) {
let returnedList = await GetList(ListName);
let obj_main = JSON.parse(returnedList);
//console.log(returnedList);
//console.log(obj_main);
//console.log(typeof obj_main['message'])
//console.log(obj_main.message);
//var obj_temp = JSON.parse(obj_main.message['!lights']);
let data = atob(obj_main.message);
console.log(ListName, data);
let notDictionary = JSON.parse(data);
//let notDictionary = true
return notDictionary
}
async function updateCommandList() {
$("#CommandRowWrapper").empty();
let returnedCommands = await GetList_OBJ("Commands");
for (var x in returnedCommands){
//console.log(x)
var commandName = returnedCommands[x].command
var isCommandEnabled = ""
if (returnedCommands[x].isCommandEnabled == "true") {
isCommandEnabled = "checked"
}
var template = ""+
"
"+
// "
"+
// "
"+
// "
Message:"+ "eventData" +"
"+
// "
"+
// "refresh"+
// " "
// $("#EventHistoryWrapper").append(template);
// $("#EventHistoryWrapper").append(template);
// $("#EventHistoryWrapper").append(template);
// $("#EventHistoryWrapper").append(template);
// $("#EventHistoryWrapper").append(template);
// $("#EventHistoryWrapper").append(template);
console.log(returnedEvents)
try {
for (var x in returnedEvents){
console.log(x)
let eventName = returnedEvents[x].eventName
let eventTime = returnedEvents[x].eventTime
let eventType = returnedEvents[x].eventType
let eventSender = returnedEvents[x].eventSender
let eventData = returnedEvents[x].eventData
//console.log(eventName)
//console.log(eventTime)
//console.log(eventType)
//console.log(eventSender)
//let reRunEvent_Params = String("reRunEvent(\"" + eventName + "\", \"" + eventTime + "\", \"" + eventType + "\", \"" + eventSender + "\", \"" + eventData+"\")")
let reRunEvent_Params = `reRunEvent("${eventName}", "${eventTime}", "${eventType}", "${eventSender}", "${eventData}")`
//let reRunEvent_Params = `reRunEvent('${eventName}', '${eventTime}', '${eventType}', '${eventSender}', '${eventData}')`
console.log(reRunEvent_Params)
//let reRunEvent_Params = String("reRunEvent()")
let template = ""+
"