first message command test

This commit is contained in:
Baipyrus 2023-01-16 15:21:30 +01:00
parent 2bbd9dde65
commit 95fbc3cea4
2 changed files with 24 additions and 1 deletions

View File

@ -61,4 +61,26 @@ function cmd_echo(input) {
if (input === undefined)
return " ";
return input.join(' ');
}
async function cmd_msg(input) {
if (input === undefined)
return "No message given!";
const data = {
id: user.id,
message: input.join(' ')
};
const res = await fetch('/message', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
if (res.status === 200) {
const resData = await res.json();
return resData.message;
} else
return "Server returned status " + res.status;
}

View File

@ -1,4 +1,5 @@
const pretext = "root@baipyr.us:~# ";
const user = { id: crypto.randomUUID(), name: "", history: [] };
let pretext = "root@baipyr.us:~# ";
// Initiating variables
const length = pretext.length+1;