mpp-server-dev2/oldsrc/InternalBot/InternalBot.js

133 lines
4.7 KiB
JavaScript
Raw Normal View History

2023-03-31 16:43:24 +02:00
const { EventEmitter } = require("events");
const { Command } = require("./Command");
const Color = require("../Color");
2022-08-16 15:42:09 +02:00
class InternalBot {
static on = EventEmitter.prototype.on;
static off = EventEmitter.prototype.off;
static emit = EventEmitter.prototype.emit;
static once = EventEmitter.prototype.once;
2023-03-31 16:43:24 +02:00
static prefix = "!";
static commands = [];
2022-08-16 15:42:09 +02:00
static bindEventListeners() {
if (this.alreadyBound) return;
this.alreadyBound = true;
2023-03-31 16:43:24 +02:00
this.on("receive message", (msg, cl, ch) => {
2022-08-16 15:42:09 +02:00
/**
* msg.a - chat message
* msg.p - participant
* msg.t - timestamp
*/
let isAdmin = false;
2023-03-31 16:43:24 +02:00
if (cl.user.hasFlag("admin")) {
2022-08-16 15:42:09 +02:00
isAdmin = true;
}
2023-03-31 16:43:24 +02:00
let args = msg.a.split(" ");
2022-09-07 09:10:07 +02:00
let cmd = args[0].toLowerCase().substring(this.prefix.length);
2022-08-16 15:42:09 +02:00
let argcat = msg.a.substring(args[0].length).trim();
2022-09-07 09:10:07 +02:00
let p = cl;
if (!args[0].startsWith(this.prefix)) return;
2023-03-31 16:43:24 +02:00
let prefix = this.prefix;
Command.handleCommand(
cl,
ch,
cmd,
prefix,
args,
argcat,
p,
isAdmin
);
2023-01-15 01:48:04 +01:00
// switch (cmd) {
// case "ping":
// ch.adminChat('pong');
// break;
// case "setcolor":
// case "color":
// if (!isAdmin) {
// ch.adminChat("You do not have permission to use this command.");
// return;
// }
// let color = ch.verifyColor(args[1]);
// if (color) {
// let c = new Color(color);
// if (!args[2]) {
// p.emit("color", {
// color: c.toHexa(),
// _id: p.user._id
// }, true);
// ch.adminChat(`Your color is now ${c.getName().replace('A', 'a')} [${c.toHexa()}]`);
// } else {
// let winner = ch.server.getAllClientsByUserID(args[2])[0];
// if (winner) {
// p.emit("color", {
// color: c.toHexa(),
// _id: winner.user._id
// }, true);
// ch.adminChat(`Friend ${winner.user.name}'s color is now ${c.getName().replace('A', 'a')}.`);
// } else {
// ch.adminChat("The friend you are looking for (" + args[2] + ") is not around.");
// }
// }
// } else {
// ch.adminChat("Invalid color.");
// }
// ch.updateCh();
// break;
// case "users":
// ch.adminChat(`There are ${ch.server.connections.size} users online.`);
// break;
// case "chown":
// if (!isAdmin) return;
// let id = p.participantId;
// if (args[1]) {
// id = args[1];
// }
// if (ch.hasUser(id)) {
// ch.chown(id);
// }
// break;
// case "chlist":
// case "channellist":
// if (!isAdmin) return;
// ch.adminChat("Channels:");
2023-03-31 16:43:24 +02:00
// for (let [_id] of ch.server.channels) {
2023-01-15 01:48:04 +01:00
// ch.adminChat(`- ${_id}`);
// }
// break;
// case "restart":
// if (!isAdmin) return;
// cl.server.restart();
// break;
// case "eval":
// case "javascript":
// case "js":
// if (!isAdmin) return;
// cl.server.ev(argcat);
// break;
2023-03-31 16:43:24 +02:00
// case "inventory":
// case "inv":
// if (cl.user.inventory) {
// ch.adminChat(`Inventory: ${Object.values(cl.user.inventory).map(it => `${it.display_name} (x${it.count})`)}`);
// } else {
// ch.adminChat(`Inventory: (empty)`);
// }
// break;
2023-01-15 01:48:04 +01:00
// }
2022-08-16 15:42:09 +02:00
});
}
}
InternalBot.bindEventListeners();
module.exports = {
InternalBot
2023-03-31 16:43:24 +02:00
};