Create index.js
Browse files
index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const io = require("socket.io-client");
|
| 2 |
+
|
| 3 |
+
const socket = io("https://hugvps-chat.hf.space");
|
| 4 |
+
socket.on("connect", (msg) => {
|
| 5 |
+
console.log("Connected to server");
|
| 6 |
+
// Your other logic here
|
| 7 |
+
socket.emit("set username", "badbot")
|
| 8 |
+
socket.emit("chat message", "i connected. my prefix is /")
|
| 9 |
+
});
|
| 10 |
+
socket.on("chat message", (msg) => {
|
| 11 |
+
console.log(msg);
|
| 12 |
+
if (msg.message.startsWith("/help")) {
|
| 13 |
+
socket.emit("chat message", "commands: /help, /ping, /whoami")
|
| 14 |
+
};
|
| 15 |
+
if (msg.message.startsWith("/ping")) {
|
| 16 |
+
socket.emit("chat message", "pong")
|
| 17 |
+
};
|
| 18 |
+
if (msg.message.startsWith("/whoami")) {
|
| 19 |
+
socket.emit("chat message", "I am the best bot.")
|
| 20 |
+
};
|
| 21 |
+
});
|
| 22 |
+
socket.on("disconnect", () => {
|
| 23 |
+
console.log("Disconnected from server");
|
| 24 |
+
});
|
| 25 |
+
|
| 26 |
+
socket.on("error", (err) => {
|
| 27 |
+
console.error("Error connecting to server:", err);
|
| 28 |
+
});
|