Implemented custom per-channel !toke commands in back-end.

This commit is contained in:
rainbow napkin 2024-12-15 09:51:32 -05:00
parent 575244ac53
commit a1fbbea7b7
10 changed files with 159 additions and 29 deletions

View file

@ -28,10 +28,17 @@ class canopyUXUtils{
//Update this and popup class to use nodes
//and display multiple errors in one popup
displayResponseError(body){
const errors = body.errors;
errors.forEach((err)=>{
new canopyUXUtils.popup(`<h3>Server Error:</h3><p><br>${err.msg}</p>`);
});
try{
const errors = body.errors;
errors.forEach((err)=>{
new canopyUXUtils.popup(`<h3>Server Error:</h3><p><br>${err.msg}</p>`);
});
}catch(err){
console.error("Display Error Error:");
console.error(body);
console.error("Display Error Error:");
console.error(err);
}
}
@ -507,6 +514,53 @@ class canopyAjaxUtils{
utils.ux.displayResponseError(await response.json());
}
}
async getChanTokes(chanName){
var response = await fetch(`/api/channel/tokeCommand?chanName=${chanName}`,{
method: "GET",
headers: {
"Content-Type": "application/json"
}
});
if(response.status == 200){
return await response.json();
}else{
utils.ux.displayResponseError(await response.json());
}
}
async addChanToke(chanName, command){
var response = await fetch('/api/channel/tokeCommand',{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({chanName, command})
});
if(response.status == 200){
return await response.json();
}else{
utils.ux.displayResponseError(await response.json());
}
}
async deleteChanToke(chanName, command){
var response = await fetch('/api/channel/tokeCommand',{
method: "DELETE",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({chanName, command})
});
if(response.status == 200){
return await response.json();
}else{
utils.ux.displayResponseError(await response.json());
}
}
}
const utils = new canopyUtils()