dvdbot-old/server.js

127 lines
3.1 KiB
JavaScript
Raw Normal View History

2024-07-29 08:44:29 +02:00
import { Client } from "mpp-client-net/src/index";
import { configDotenv } from "dotenv";
import fs from "fs";
console.log(Client);
configDotenv();
const client = new Client("wss://mppclone.com:8443", process.env.MPPNET_TOKEN);
client.start();
client.on("hi", () => {
2024-07-29 08:44:29 +02:00
setTimeout(function () {
client.sendArray([
{ m: "userset", set: { name: "hri's dvdbot [dvd!help]" } },
]);
});
client.setChannel("test/awkward");
2018-03-13 21:25:39 +01:00
});
function chat(string) {
2024-07-29 08:44:29 +02:00
client.sendArray([{ m: "a", message: string }]);
}
var ctoggle = true;
var cursormode = "dvd";
client.on("a", (msg) => {
2024-07-29 08:44:29 +02:00
let args = msg.a.split(" ");
let cmd = args[0].toLowerCase();
let argcat = msg.a.substring(cmd.length).trim();
2024-07-29 08:44:29 +02:00
switch (cmd) {
case "dvd!help":
chat("cmds: dvd!help // dvd!cursor // dvd!stats // dvd!about");
break;
case "dvd!cursor":
if (!argcat || argcat == "") {
chat("Modes: on // off");
} else {
switch (argcat) {
case "on":
ctoggle = true;
2024-07-29 08:44:29 +02:00
pos = { x: Math.random() * 100 - 50, y: Math.random() * 100 - 50 };
vel = { x: 2 / 5, y: 2 / 7 };
cursormode = "dvd";
break;
case "off":
ctoggle = false;
cursormode = "none";
2024-07-29 08:44:29 +02:00
pos = { x: -500, y: -500 };
break;
default:
chat("invalid :P");
break;
}
}
break;
case "dvd!stats":
2024-07-29 08:44:29 +02:00
chat(
"Edge hits: " + stats.edgehits + " | Corner hits: " + stats.cornerhits,
);
break;
case "dvd!about":
2024-07-29 08:44:29 +02:00
chat("this bot is ancient dude");
break;
}
2020-02-19 23:18:49 +01:00
});
2024-07-29 08:44:29 +02:00
var pos = { x: Math.random() * 100 - 50, y: Math.random() * 100 - 50 };
var vel = { x: 2 / 5, y: 2 / 7 };
var statsraw = fs.readFileSync("stats.json");
var stats = JSON.parse(statsraw);
console.log(stats);
2024-07-29 08:44:29 +02:00
var cursor = setInterval(function () {
client.sendArray([
{
m: "m",
x: (client.getOwnParticipant().x = pos.x + 50),
y: (client.getOwnParticipant().y = pos.y + 50),
},
]);
}, 1000 / 20);
2024-07-29 08:44:29 +02:00
var cursorupdate = setInterval(function () {
switch (cursormode) {
case "dvd":
pos.x += vel.x;
pos.y += vel.y;
if (pos.x >= 50) {
2024-07-29 08:44:29 +02:00
vel.x = -vel.x;
}
if (pos.y >= 50) {
2024-07-29 08:44:29 +02:00
vel.y = -vel.y;
}
if (pos.x <= -50) {
2024-07-29 08:44:29 +02:00
vel.x = -vel.x;
}
if (pos.y <= -50) {
2024-07-29 08:44:29 +02:00
vel.y = -vel.y;
}
2024-07-29 08:44:29 +02:00
if (pos.x >= 50 && pos.y >= 50) {
stats.cornerhits += 1;
2024-07-29 08:44:29 +02:00
} else if (pos.x >= 50 && pos.y <= -50) {
stats.cornerhits += 1;
2024-07-29 08:44:29 +02:00
} else if (pos.x <= -50 && pos.y <= -50) {
stats.cornerhits += 1;
2024-07-29 08:44:29 +02:00
} else if (pos.x <= -50 && pos.y >= 50) {
stats.cornerhits += 1;
2024-07-29 08:44:29 +02:00
} else if (pos.x >= 50 || pos.y >= 50 || pos.y <= -50 || pos.x <= -50) {
stats.edgehits += 1;
}
let statsjson = JSON.stringify(stats);
2024-07-29 08:44:29 +02:00
fs.writeFile("stats.json", statsjson, "utf8", function (err) {
if (err) {
console.log("stats.json couldn't be saved!");
return console.log(err);
}
});
break;
}
2024-07-29 08:44:29 +02:00
}, 1000 / 30);