This repository has been archived by the owner on Aug 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
121 lines (101 loc) · 3.76 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
function h(){
evaluatedvalue = ws.readyState;
listofreadystates = ["Connecting...","Connected!","Disconnecting...","Disconnected."];
alert(listofreadystates[evaluatedvalue]);
}
function startws(){
function coding(obj){return Function(document.querySelector("#code").value)()}
coding(); // Starts code in textarea (without eval bc im good programer)
ws = new WebSocket("wss:\/\/server.meower.org");
console.log(ws);
ws.addEventListener("message", function (ev) {
prz = JSON.parse(ev.data);
console.log(prz);
if (prz.cmd == "ping") {
if (prz.val == "I:100 | OK") {
console.log("PINGBACK OK");
} else {
console.log("PINGBACK NOT OK");
}
}
if (prz.cmd == "direct") {
if (prz.val.isDeleted === false) {
console.log(`Post received from ${prz.val.u}: ${prz.val.p}`);
handlePost([prz.val.u, prz.val.p]);
}
}
if (prz.cmd == "ulist") {
document.querySelector("#ulist").innerText = `Online: ${prz.val.split(";").slice(0,prz.val.split(";").length-1).join(", ")}`;
}
if (prz.cmd == "statuscode") {
if (prz.val.startsWith("I:112")) {
auth(document.querySelector(".username").value, document.querySelector("#password").value);
} else {
if (prz.val.startsWith("I:011") | prz.val.startsWith("E:103")) {
if (document.querySelector("#password").value == "") {
alert("You haven't typed a password.");
} else {
alert("You have typed an invalid username or password.");
}
ws.close();
document.querySelector("#ulist").innerText = "Logged out of Meower!";
}
}
}
});
}
function auth(user,pass){
// Setup
ws.send('{"cmd": "direct", "val": {"cmd": "type", "val": "js"}}');
ws.send(`{"cmd": "direct", "val": {"cmd": "ip", "val": "${window.ipAdd}"}}`);
ws.send('{"cmd": "direct", "val": "meower"}');
ws.send('{"cmd": "direct", "val": {"cmd": "version_chk", "val": "scratch-beta-5-r7"}}');
// Auth
ws.send(`{"cmd": "direct", "val": {"cmd": "authpswd", "val": {"username": "${user}", "pswd": "${pass}"}}}`);
// Consistent pinging
setInterval(function(){if(ws.readyState==1){ws.send('{"cmd":"ping","val":""}')}},15000);
}
function post(content){
if (ws in window) {
ws.send(`{"cmd":"direct","val":{"cmd":"post_home","val":"${content}"}}`);
} else {
alert("Please login before posting a message.")
}
}
//code lifted from turbo_networking.js
async function fetchURL(url) {
const res = await fetch(url, {
method: "GET"
});
return await res.text();
};
async function checkstatus(){
try {
var apistatus = await fetchURL("https://api.meower.org/status");
} catch (error) {
meowerdown = true;
return true;
}
apistatus = JSON.parse(apistatus);
if (apistatus.isRepairMode === false & apistatus.scratchDeprecated === false & apistatus !== undefined) {
console.log("suces");
meowerdown = false;
} else {
console.log("bad :(");
meowerdown = true;
}
window.ipAdd = await fetchURL("https://api.meower.org/ip");
}
checkstatus();
document.querySelector("#code").value = `// Example Meower chatbot code
window.handlePost = function(bundle) {
if (bundle[0] == "Discord") {
bundle = bundle[1].split(": ")
}
// Bot code goes here
if (bundle[1].startsWith("!helloworld")) {
post(\`Hello \${bundle[0]}!\`);
}
}
// Posts are stored as an array in this format:
// ["user", "content"]`;