refactor channel, save clear chat
This commit is contained in:
parent
e00105a8cf
commit
b799c52e2c
|
@ -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;
|
|
@ -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));
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Reference in New Issue