From b799c52e2c9e19e1ed0fc6c66aeba464bfa0d8e7 Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Tue, 29 Mar 2022 06:41:30 +0200 Subject: [PATCH] refactor channel, save clear chat --- src/{Room.js => Channel.js} | 17 +++++++++++++---- src/Client.js | 5 +++-- src/Message.js | 6 ++---- 3 files changed, 18 insertions(+), 10 deletions(-) rename src/{Room.js => Channel.js} (97%) diff --git a/src/Room.js b/src/Channel.js similarity index 97% rename from src/Room.js rename to src/Channel.js index 63fa2aa..061c412 100644 --- a/src/Room.js +++ b/src/Channel.js @@ -7,7 +7,7 @@ const RoomSettings = require('./RoomSettings.js'); const ftc = require('fancy-text-converter'); const Notification = require('./Notification'); -class Room extends EventEmitter { +class Channel extends EventEmitter { constructor(server, _id, settings) { super(); this.logger = new Logger(`Room - ${ftc.normalise(_id)}`); @@ -41,6 +41,15 @@ class Room extends EventEmitter { }); } + setChatArray(arr) { + this.chatmsgs = arr || []; + this.sendArray([{ + m: 'c', + c: this.chatmsgs.slice(-1 * 32) + }]); + this.setData(); + } + join(cl, set) { //this stuff is complicated let otheruser = this.connections.find((a) => a.user._id == cl.user._id) if (!otheruser) { @@ -336,8 +345,8 @@ class Room extends EventEmitter { let message = {}; message.m = "a"; message.a = msg.message; - if (prsn.user.hasFlag('vowels')) { - if (prsn.user.flags.vowels != false) message.a = message.a.split(/[aeiou]/).join('o').split(/[AEIOU]/).join('O'); + if (prsn.user.hasFlag('chat_curse_1')) { + if (prsn.user.flags['chat_curse_1'] != false) message.a = message.a.split(/[aeiou]/).join('o').split(/[AEIOU]/).join('O'); } message.p = { color: p.user.color, @@ -484,4 +493,4 @@ class Room extends EventEmitter { } } -module.exports = Room; +module.exports = Channel; diff --git a/src/Client.js b/src/Client.js index 38674f4..c4fac69 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1,4 +1,4 @@ -const Room = require("./Room.js"); +const Channel = require("./Channel.js"); const Quota = require ("./Quota.js"); const quotas = require('../Quotas'); const RateLimit = require('./Ratelimit.js').RateLimit; @@ -75,13 +75,14 @@ class Client extends EventEmitter { this.channel.join(this); } } else { - let room = new Room(this.server, _id, settings); + let room = new Channel(this.server, _id, settings); this.server.rooms.set(_id, room); if (this.channel) this.channel.emit("bye", this); this.channel = this.server.rooms.get(_id); this.channel.join(this, settings); } } + sendArray(arr) { if (this.isConnected()) { //console.log(`SEND: `, JSON.colorStringify(arr)); diff --git a/src/Message.js b/src/Message.js index 47aab4f..4a7e375 100644 --- a/src/Message.js +++ b/src/Message.js @@ -1,6 +1,6 @@ const Quota = require('./Quota'); const User = require("./User.js"); -const Room = require("./Room.js"); +const Channel = require("./Channel.js"); const RoomSettings = require('./RoomSettings'); const Database = require('./Database'); @@ -319,9 +319,7 @@ module.exports = (cl) => { cl.on('clear_chat', (msg, admin) => { if (!admin) return; - cl.channel.connections.forEach(cl => { - cl.sendArray([{m:"c", c:[]}]); - }); + cl.channel.setChatArray([]); }); cl.on('sudo', (msg, admin) => {