eekum bokum

This commit is contained in:
Hri7566 2022-06-15 02:21:50 -04:00
parent 2065df30bc
commit 56286050a0
6 changed files with 1955 additions and 11 deletions

View File

@ -2,21 +2,26 @@ module.exports = Object.seal({
port: 8443,
motd: "big th0nk",
_id_PrivateKey: process.env.SALT,
defaultUsername: "Anonymous",
// defaultRoomColor: "#3b5054",
defaultRoomColor: "#480505",
defaultLobbyColor: "#19b4b9",
// defaultLobbyColor: "#76b0db",
// defaultLobbyColor: "#19b4b9",
// defaultLobbyColor2: "#801014",
defaultLobbyColor: "#76b0db",
defaultLobbyColor2: "#276491",
// defaultLobbyColor: "#9900ff",
// defaultLobbyColor2: "#5900af",
defaultUsername: "Anonymous",
adminpass: process.env.ADMINPASS,
ssl: process.env.SSL,
defaultRoomSettings: {
color: "#3b5054",
color2: "#001014",
// color: "#3b5054",
// color2: "#001014",
color: "#480505",
crownsolo: false,
visible: true
}
},
hostDevFiles: false,
enableMPPCloneBot: true
});

View File

@ -34,3 +34,24 @@ let console = process.platform == 'win32' ? new AsyncConsole("", input => {
}
}) : {};
*/
// dev environment
if (config.hostDevFiles) {
const express = require('express');
const app = express();
const path = require('path');
app.listen(8075, () => {
});
app.use(express.static(path.join(__dirname, 'mpp.hri7566.info')));
}
if (config.enableMPPCloneBot) {
require('./mppclonebot');
}

231
mppclonebot.js Normal file
View File

@ -0,0 +1,231 @@
const Client = require('mppclone-client');
const Logger = require('./src/Logger');
const { EventEmitter } = require('events');
const token = process.env.MPPCLONE_TOKEN;
class Command {
static commands = {};
static getUsage(us, prefix) {
return us.split('%PREFIX%').join(prefix);
}
constructor(cmd, desc, usage, minargs, func, minrank, hidden) {
this.cmd = typeof cmd == 'object' ? cmd : [cmd];
this.desc = desc || "No description";
this.usage = usage || "No usage";
this.minargs = minargs || 0;
this.func = func;
this.minrank = minrank || 0;
this.hidden = hidden || false;
Command.commands[this.cmd[0]] = this;
}
}
class Rank {
static ranks = {};
static user_ranks = {};
static setRank(_id, rank) {
Rank.user_ranks[_id] = rank;
}
static getRank(_id) {
return Rank.user_ranks[_id];
}
constructor(name, desc, minrank) {
this.name = name;
this.desc = desc;
this.minrank = minrank;
Rank.ranks[name] = this;
}
}
new Rank("User", "Default rank", 0);
new Rank("Mod", "Moderator rank", 1);
new Rank("Admin", "Administrator rank", 2);
new Rank("Owner", "Owner rank", 3);
class Prefix {
static prefixes = {};
static hasAnyPrefix(str) {
for (let i in Prefix.prefixes) {
if (str.startsWith(Prefix.prefixes[i].prefix)) {
return true;
}
}
}
static getPrefixFromString(str) {
for (let i in Prefix.prefixes) {
if (str.startsWith(Prefix.prefixes[i].prefix)) {
return Prefix.prefixes[i];
}
}
}
constructor(id, prefix) {
this.id = id;
this.prefix = prefix;
Prefix.prefixes[id] = this;
}
}
class Bot extends EventEmitter {
constructor(cl) {
super();
this.logger = new Logger('MPPClone Bot');
this.client = cl;
this.bindEventListeners();
this.userset = {
name: 'mpp.hri7566.info [indev]', // TODO change this name
color: '#76b0db'
};
this.chatBuffer = [];
this.chatBufferCycleCounter = 0;
this.chatBufferCycle();
this.client.start();
this.client.setChannel('✧𝓓𝓔𝓥 𝓡𝓸𝓸𝓶✧');
}
bindEventListeners() {
this.client.on('a', msg => {
this.emit('receiveChat', msg);
});
this.client.on('ch', msg => {
this.emit('resetName', msg);
})
this.client.on('hi', msg => {
this.emit('online', msg);
});
this.client.on('t', msg => {
this.emit('resetName', msg);
});
this.on('resetName', () => {
if (this.client.getOwnParticipant().name !== this.userset.name || this.client.getOwnParticipant().color !== this.userset.color) {
this.client.sendArray([{
m: 'userset',
set: this.userset
}]);
}
});
this.on('receiveChat', msg => {
if (Prefix.hasAnyPrefix(msg.a)) {
msg.prefix = Prefix.getPrefixFromString(msg.a);
this.emit('runCommand', msg);
}
});
this.on('addToChatBuffer', msg => {
this.chatBuffer.push(msg);
});
this.on('runCommand', msg => {
if (!msg.prefix) return;
msg.args = msg.a.split(' ');
msg.cmd = msg.args[0].substring(msg.prefix.prefix.length).trim();
msg.argcat = msg.a.substring(msg.args[0].length).trim();
let rank = Rank.getRank(msg.p._id);
if (!rank) {
rank = Rank.ranks['User'];
Rank.setRank(msg.p._id, rank);
}
msg.rank = rank;
for (let cmd of Object.values(Command.commands)) {
if (!cmd.cmd.includes(msg.cmd)) continue;
console.log(msg.cmd, cmd.cmd);
if (msg.args.length < cmd.minargs) return;
if (msg.rank.id < cmd.minrank) return;
try {
let out = cmd.func(msg);
if (!out) return;
out = out.split('\n').join(' ').split('\t').join(' ').split('\r').join(' ');
if (out !== '') {
this.emit('addToChatBuffer', {
m: 'a',
message: out,
p: msg.p._id
});
}
} catch (e) {
this.emit('addToChatBuffer', {
m: 'a',
message: 'An error has occurred.',
p: msg.p._id
});
}
}
});
this.on('online', () => {
this.logger.log('Connected');
})
}
async chatBufferCycle() {
if (this.chatBuffer.length <= 0) {
setTimeout(() => {
this.chatBufferCycle();
});
return;
}
this.chatBufferCycleCounter++;
let time = 0;
if (this.chatBufferCycleCounter > 4) {
time += 1000;
}
setTimeout(() => {
let nextMessage = this.chatBuffer.shift();
this.client.sendArray([nextMessage]);
this.chatBufferCycle();
this.chatBufferCycleCounter--;
}, time);
}
}
new Prefix('hmpp!', 'hmpp!');
new Prefix('h!', 'h!');
new Command(['help', 'cmds', 'h'], 'List all commands', '%PREFIX%help', 0, (msg) => {
let cmds = 'Commands: ';
for (let cmd of Object.values(Command.commands)) {
if (cmd.hidden) continue;
cmds += `${cmd.cmd[0]}, `;
}
cmds = cmds.substring(0, cmds.length - 2).trim();
return cmds;
}, 0, false);
new Command(['users'], 'See how many users are online', `%PREFIX%users`, 0, (msg) => {
console.log(SERVER.connections.size);
return `There are ${SERVER.connections.size} users on HMPP.`;
}, 0, false);
let cl = new Client("wss://mppclone.com:8443", token);
let bot = new Bot(cl);

View File

@ -26,10 +26,12 @@
"chalk": "^4.1.1",
"dotenv": "^8.2.0",
"events": "^3.1.0",
"express": "^4.18.1",
"fancy-text-converter": "^1.0.9",
"keccak": "^2.1.0",
"level": "^7.0.0",
"mongoose": "^5.12.7",
"mppclone-client": "^1.0.0",
"node-json-color-stringify": "^1.1.0",
"nodemon": "^2.0.15",
"ws": "^7.2.3"

View File

@ -149,7 +149,7 @@ class Channel extends EventEmitter {
if (Array.from(this.ppl.values()).length <= 0) {
setTimeout(() => {
this.destroy();
}, 5000);
}, 1000);
}
this.connections.forEach((usr) => {
@ -326,26 +326,33 @@ class Channel extends EventEmitter {
chat(p, msg) {
if (msg.message.length > 512) return;
let filter = ["AMIGHTYWIND", "CHECKLYHQ"];
let regexp = new RegExp("\\b(" + filter.join("|") + ")\\b", "i");
if (regexp.test(msg.message.split(' ').join(''))) return;
if (p.participantId == 0) {
let message = {};
message.m = "a";
message.t = Date.now();
message.a = msg.message;
message.p = {
color: "#ffffff",
id: "0",
name: "mpp",
_id: "0"
};
message.t = Date.now();
this.sendArray([message]);
this.chatmsgs.push(message);
this.setData();
return;
}
let prsn = this.ppl.get(p.participantId);
if (!prsn) return;
let message = {};
@ -394,7 +401,7 @@ class Channel extends EventEmitter {
color: c.toHexa(),
_id: p.user._id
}, true);
this.adminChat(`Your color is now: ${c.getName()} [${c.toHexa()}]`);
this.adminChat(`Your color is now ${c.getName().replace('A', 'a')} [${c.toHexa()}]`);
} else {
let winner = this.server.getAllClientsByUserID(args[2])[0];
if (winner) {
@ -412,6 +419,19 @@ class Channel extends EventEmitter {
}
this.updateCh();
break;
case "!users":
this.adminChat(`There are ${this.server.connections.size} users online.`);
break;
case "!chown":
if (!isAdmin) return;
let id = p.participantId;
if (args[1]) {
id = args[1];
}
if (this.hasUser(id)) {
this.chown(id);
}
break;
}
}
@ -423,6 +443,10 @@ class Channel extends EventEmitter {
});
}
hasUser(id) {
return this.ppl.has(id);
}
playNote(cl, note) {
let vel = Math.round(cl.user.flags["volume"])/100 || undefined;
@ -521,6 +545,10 @@ class Channel extends EventEmitter {
this.on("a", (participant, msg) => {
this.chat(participant, msg);
})
this.on("update", (cl) => {
this.updateCh(cl);
});
}
verifySet(_id, msg) {

1657
yarn.lock Normal file

File diff suppressed because it is too large Load Diff