124 lines
3.9 KiB
JavaScript
124 lines
3.9 KiB
JavaScript
|
|
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);
|
|
updateCommandList();
|
|
}
|
|
|
|
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 GetListCommands() {
|
|
let returnedList = await GetList("Commands");
|
|
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(data);
|
|
let notDictionary = JSON.parse(data);
|
|
|
|
return notDictionary
|
|
}
|
|
|
|
async function updateCommandList() {
|
|
$("#CommandRowWrapper").empty();
|
|
let returnedCommands = await GetListCommands();
|
|
for (x in returnedCommands){
|
|
//console.log(x)
|
|
var commandName = returnedCommands[x].command
|
|
var isCommandEnabled = ""
|
|
if (returnedCommands[x].isCommandEnabled == "true") {
|
|
isCommandEnabled = "checked"
|
|
}
|
|
var commandTemplate = ""+
|
|
"<div class=\"rowsInMain row card\" style=\"margin-right: 20px;margin-left: 20px;margin-top: 30px;margin-bottom: 30px;\">" +
|
|
"<div class=\"col s12 switch\" style=\"top: -20px;position: relative;padding-left: 10px;\"><label>Enabled:<input "+ isCommandEnabled +" disabled type=\"checkbox\"><span class=\"lever\"></span></label></div>" +
|
|
"<div class=\"col s4\"><p>Command Name:</p>" +
|
|
"<div class=\"input-field inline\" style=\"width: 80%;\">" +
|
|
"<p style =\"color:grey;\">Command</p>" +
|
|
"<input disabled id=\"command_inline\" type=\"text\" value=\""+ commandName +"\" class=\"validate\">" +
|
|
"</div></div></div></div>"
|
|
$("#CommandRowWrapper").append(commandTemplate);
|
|
}
|
|
//var commandName = "!testerino"
|
|
//var isCommandEnabled = "" // if == "checked" will start off with the isEnabled bool enabled
|
|
|
|
}
|
|
|
|
updateCommandList();
|
|
|
|
|
|
|
|
async function GetListRewards() {
|
|
returnedList = await GetList("Rewards");
|
|
obj = JSON.parse(returnedList);
|
|
console.log(obj['message'])
|
|
return returnedList
|
|
}
|
|
|
|
async function GetListTimers() {
|
|
returnedList = await GetList("Timers");
|
|
obj = JSON.parse(returnedList);
|
|
console.log(obj['message'])
|
|
return returnedList
|
|
}
|
|
|
|
async function GetListTextSources() {
|
|
returnedList = await GetList("TextSources");
|
|
obj = JSON.parse(returnedList);
|
|
console.log(obj['message'])
|
|
return returnedList
|
|
} |