From e45582efea842e337654b76a462ae6bd8d8a92d7 Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Fri, 28 May 2021 17:15:00 -0400 Subject: [PATCH] i have no clue what i changed --- Quotas.js | 3 ++- package.json | 2 +- src/Client.js | 2 +- src/Message.js | 10 ++++++---- src/Notification.js | 40 +++++++++++++++++++++++++++++++++++++++ src/Room.js | 46 ++++++++++----------------------------------- src/User.js | 5 +++-- 7 files changed, 63 insertions(+), 45 deletions(-) create mode 100644 src/Notification.js diff --git a/Quotas.js b/Quotas.js index 929657a..77a1c7e 100644 --- a/Quotas.js +++ b/Quotas.js @@ -25,7 +25,8 @@ module.exports = Object.seal({ time: 500 }, cursor: { - time: 16 + time: 16, + amount: 10 }, kickban: { amount: 2, diff --git a/package.json b/package.json index 6f7c09d..3828508 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Attempt at making a MPP Server.", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "nodemon" }, "repository": { "type": "git", diff --git a/src/Client.js b/src/Client.js index 1727bb2..38674f4 100644 --- a/src/Client.js +++ b/src/Client.js @@ -97,7 +97,7 @@ class Client extends EventEmitter { normal: new RateLimitChain(quotas.chat.normal.amount, quotas.chat.normal.time), insane: new RateLimitChain(quotas.chat.insane.amount, quotas.chat.insane.time) }, - cursor: new RateLimit(quotas.cursor.time), + cursor: new RateLimitChain(quotas.cursor.amount, quotas.cursor.time), chown: new RateLimitChain(quotas.chown.amount, quotas.chown.time), userset: new RateLimitChain(quotas.userset.amount, quotas.userset.time), kickban: new RateLimitChain(quotas.kickban.amount, quotas.kickban.time), diff --git a/src/Message.js b/src/Message.js index c5f32b3..7c4b878 100644 --- a/src/Message.js +++ b/src/Message.js @@ -38,6 +38,7 @@ module.exports = (cl) => { cl.on("ch", msg => { if (typeof(msg.set) !== 'object') msg.set = {}; + console.log(msg); if (typeof(msg._id) == "string") { if (msg._id.length > 512) return; @@ -66,7 +67,8 @@ module.exports = (cl) => { }); cl.on("m", (msg, admin) => { - // if (!cl.quotas.cursor.attempt() && !admin) return; + if (!cl.hasOwnProperty('room')) return; + if (!cl.quotas.cursor.attempt() && !admin) return; if (!(cl.channel && cl.participantId)) return; if (!msg.hasOwnProperty("x")) msg.x = null; if (!msg.hasOwnProperty("y")) msg.y = null; @@ -137,12 +139,12 @@ module.exports = (cl) => { if (typeof(msg.message) !== 'string') return; if (cl.channel.settings.chat) { if (cl.channel.isLobby(cl.channel._id)) { - if (!cl.quotas.chat.lobby.attempt() && !admin && !cl.user.hasFlag('no rate chat limit', true)) return; + if (!cl.quotas.chat.lobby.attempt() && !admin && !cl.user.hasFlag('no chat rate limit', true)) return; } else { if (!(cl.user._id == cl.channel.crown.userId)) { - if (!cl.quotas.chat.normal.attempt() && !admin && !cl.user.hasFlag('no rate chat limit', true)) return; + if (!cl.quotas.chat.normal.attempt() && !admin && !cl.user.hasFlag('no chat rate limit', true)) return; } else { - if (!cl.quotas.chat.insane.attempt() && !admin && !cl.user.hasFlag('no rate chat limit', true)) return; + if (!cl.quotas.chat.insane.attempt() && !admin && !cl.user.hasFlag('no chat rate limit', true)) return; } } cl.channel.emit('a', cl, msg); diff --git a/src/Notification.js b/src/Notification.js new file mode 100644 index 0000000..a270c9f --- /dev/null +++ b/src/Notification.js @@ -0,0 +1,40 @@ +module.exports = class Notification { + constructor (data) { + this.id = data.id; + this.chat = data.chat; + this.refresh = data.refresh; + this.title = data.title; + this.text = data.text; + this.html = data.html; + this.target = data.target; + this.duration = data.duration; + this.class = data.class; + this.id = data.id; + } + + send(_id, room) { + let obj = {}; + Object.assign(obj, this); + obj.m = "notification"; + + switch (_id) { + case "all": { + for (let con of Array.from(room.server.connections.values())) { + con.sendArray([obj]); + } + break; + } + case "room": { + for (let con of room.connections) { + con.sendArray([obj]); + } + break; + } + default: { + Array.from(room.server.connections.values()).filter((usr) => typeof(usr.user) !== 'undefined' ? usr.user._id == _id : null).forEach((p) => { + p.sendArray([obj]); + }); + } + } + } +} diff --git a/src/Room.js b/src/Room.js index d0c4845..60aecbe 100644 --- a/src/Room.js +++ b/src/Room.js @@ -5,6 +5,7 @@ const Logger = require('./Logger.js'); const Quota = require("./Quota.js"); const RoomSettings = require('./RoomSettings.js'); const ftc = require('fancy-text-converter'); +const Notification = require('./Notification'); class Room extends EventEmitter { constructor(server, _id, settings) { @@ -306,7 +307,7 @@ class Room extends EventEmitter { if (msg.message.length > 512) return; let filter = ["AMIGHTYWIND", "CHECKLYHQ"]; let regexp = new RegExp("\\b(" + filter.join("|") + ")\\b", "i"); - if (regexp.test(msg.message)) return; + if (regexp.test(msg.message.split(' ').join(''))) return; if (p.participantId == 0) { let message = {}; message.m = "a"; @@ -330,7 +331,7 @@ class Room extends EventEmitter { message.m = "a"; message.a = msg.message; if (prsn.user.hasFlag('vowels')) { - if (prsn.user.flags.vowels != false) message.a = message.a.split(/[aeiouAEIOU]/).join(prsn.user.flags["vowels"]); + if (prsn.user.flags.vowels != false) message.a = message.a.split(/[aeiou]/).join('o').split(/[AEIOU]/).join('O'); } message.p = { color: p.user.color, @@ -414,44 +415,17 @@ class Room extends EventEmitter { } Notification(who, title, text, html, duration, target, klass, id) { - let obj = { - m: "notification", + new Notification({ + id: id, + chat: undefined, + refresh: undefined, title: title, text: text, html: html, - target: target, duration: duration, - class: klass, - id: id - }; - - if (!id) delete obj.id; - if (!title) delete obj.title; - if (!text) delete obj.text; - if (!html) delete obj.html; - if (!target) delete obj.target; - if (!duration) delete obj.duration; - if (!klass) delete obj.class; - - switch (who) { - case "all": { - for (let con of Array.from(this.server.connections.values())) { - con.sendArray([obj]); - } - break; - } - case "room": { - for (let con of this.connections) { - con.sendArray([obj]); - } - break; - } - default: { - Array.from(this.server.connections.values()).filter((usr) => typeof(usr.user) !== 'undefined' ? usr.user._id == who : null).forEach((p) => { - p.sendArray([obj]); - }); - } - } + target: target, + class: klass + }).send(who, this); } bindEventListeners() { diff --git a/src/User.js b/src/User.js index 83c1852..93917ac 100644 --- a/src/User.js +++ b/src/User.js @@ -19,7 +19,7 @@ class User { this.color = data.color; this.flags = typeof data.flags == "object" ? data.flags : { volume: 100, - "no chat rate limit": false, + "no chat rate limit": false } } @@ -32,12 +32,12 @@ class User { } checkFlags() { + /* if (typeof(this.cl.server.specialIntervals[this._id]) == 'undefined') { this.cl.server.specialIntervals[this._id] = {}; } if (this.hasFlag('rainbow', true)) { if (!this.cl.server.specialIntervals[this._id].hasOwnProperty('rainbow')) { - console.log('rainbow triggered'); let h = Math.floor(Math.random() * 360); let s = 50; let l = 50; @@ -71,6 +71,7 @@ class User { console.log('rainbow off triggered'); clearInterval(this.cl.server.specialIntervals[this._id].rainbow); } + */ } stopFlagEvents() {