This commit is contained in:
Hri7566 2022-05-24 15:40:09 -04:00
parent 6e632b1bb3
commit e60e1fa6c2
4 changed files with 1133 additions and 21 deletions

View File

@ -23,7 +23,7 @@ let Server = require("./src/Server.js");
let config = require('./config');
global.SERVER = new Server(config);
// below commented because it doesn't work with pm2
// doesn't work with pm2
/*
let console = process.platform == 'win32' ? new AsyncConsole("", input => {

View File

@ -6,6 +6,7 @@ const Quota = require("./Quota.js");
const RoomSettings = require('./RoomSettings.js');
const ftc = require('fancy-text-converter');
const Notification = require('./Notification');
const Color = require('./Color');
class Channel extends EventEmitter {
constructor(server, _id, settings) {
@ -346,7 +347,7 @@ class Channel extends EventEmitter {
return;
}
let prsn = this.ppl.get(p.participantId);
if (prsn) {
if (!prsn) return;
let message = {};
message.m = "a";
message.a = msg.message;
@ -366,7 +367,60 @@ class Channel extends EventEmitter {
this.sendArray([message]);
this.chatmsgs.push(message);
this.setData();
let isAdmin = false;
if (prsn.user.hasFlag('admin')) {
isAdmin = true;
}
let args = message.a.split(' ');
let cmd = args[0].toLowerCase();
let argcat = message.a.substring(args[0].length).trim();
switch (cmd) {
case "!ping":
this.adminChat("pong");
break;
case "!setcolor":
if (!isAdmin) {
this.adminChat("You do not have permission to use this command.");
return;
}
let color = this.verifyColor(args[1]);
if (color) {
let c = new Color(color);
if (!args[2]) {
p.emit("color", {
color: c.toHexa(),
_id: p.user._id
}, true);
this.adminChat(`Your color is now: ${c.getName()} [${c.toHexa()}]`);
} else {
let winner = this.server.getAllClientsByUserID(args[2])[0];
if (winner) {
p.emit("color", {
color: c.toHexa(),
_id: winner.user._id
}, true);
this.adminChat(`Friend ${winner.user.name}'s color is now ${c.getName().replace('A', 'a')}.`);
} else {
this.adminChat("The friend you are looking for (" + args[2] + ") is not around.");
}
}
} else {
this.adminChat("Invalid color.");
}
this.updateCh();
break;
}
}
adminChat(str) {
this.chat({
participantId: 0
}, {
message: str
});
}
playNote(cl, note) {

1046
src/Color.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -121,6 +121,18 @@ class Server extends EventEmitter {
}
console.log(out);
}
getClient(id) {
return this.connections.get(id);
}
getAllClientsByUserID(_id) {
let out = [];
for (let cl of Array.from(this.connections.values())) {
if (cl.user._id == _id) out.push(cl);
}
return out;
}
}
module.exports = Server;