From 95fbc3cea412f27d0e22757c10e75b2f34553e72 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Mon, 16 Jan 2023 15:21:30 +0100 Subject: [PATCH] first message command test --- js/commands.js | 22 ++++++++++++++++++++++ js/main.js | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/js/commands.js b/js/commands.js index 683b151..1ee509d 100644 --- a/js/commands.js +++ b/js/commands.js @@ -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; } \ No newline at end of file diff --git a/js/main.js b/js/main.js index f408755..376dec4 100644 --- a/js/main.js +++ b/js/main.js @@ -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;