forked from Hri7566/mpp-server-dev2
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 ftc = require('fancy-text-converter');
|
||||||
const Notification = require('./Notification');
|
const Notification = require('./Notification');
|
||||||
|
|
||||||
class Room extends EventEmitter {
|
class Channel extends EventEmitter {
|
||||||
constructor(server, _id, settings) {
|
constructor(server, _id, settings) {
|
||||||
super();
|
super();
|
||||||
this.logger = new Logger(`Room - ${ftc.normalise(_id)}`);
|
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
|
join(cl, set) { //this stuff is complicated
|
||||||
let otheruser = this.connections.find((a) => a.user._id == cl.user._id)
|
let otheruser = this.connections.find((a) => a.user._id == cl.user._id)
|
||||||
if (!otheruser) {
|
if (!otheruser) {
|
||||||
|
@ -336,8 +345,8 @@ class Room extends EventEmitter {
|
||||||
let message = {};
|
let message = {};
|
||||||
message.m = "a";
|
message.m = "a";
|
||||||
message.a = msg.message;
|
message.a = msg.message;
|
||||||
if (prsn.user.hasFlag('vowels')) {
|
if (prsn.user.hasFlag('chat_curse_1')) {
|
||||||
if (prsn.user.flags.vowels != false) message.a = message.a.split(/[aeiou]/).join('o').split(/[AEIOU]/).join('O');
|
if (prsn.user.flags['chat_curse_1'] != false) message.a = message.a.split(/[aeiou]/).join('o').split(/[AEIOU]/).join('O');
|
||||||
}
|
}
|
||||||
message.p = {
|
message.p = {
|
||||||
color: p.user.color,
|
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 Quota = require ("./Quota.js");
|
||||||
const quotas = require('../Quotas');
|
const quotas = require('../Quotas');
|
||||||
const RateLimit = require('./Ratelimit.js').RateLimit;
|
const RateLimit = require('./Ratelimit.js').RateLimit;
|
||||||
|
@ -75,13 +75,14 @@ class Client extends EventEmitter {
|
||||||
this.channel.join(this);
|
this.channel.join(this);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let room = new Room(this.server, _id, settings);
|
let room = new Channel(this.server, _id, settings);
|
||||||
this.server.rooms.set(_id, room);
|
this.server.rooms.set(_id, room);
|
||||||
if (this.channel) this.channel.emit("bye", this);
|
if (this.channel) this.channel.emit("bye", this);
|
||||||
this.channel = this.server.rooms.get(_id);
|
this.channel = this.server.rooms.get(_id);
|
||||||
this.channel.join(this, settings);
|
this.channel.join(this, settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendArray(arr) {
|
sendArray(arr) {
|
||||||
if (this.isConnected()) {
|
if (this.isConnected()) {
|
||||||
//console.log(`SEND: `, JSON.colorStringify(arr));
|
//console.log(`SEND: `, JSON.colorStringify(arr));
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const Quota = require('./Quota');
|
const Quota = require('./Quota');
|
||||||
const User = require("./User.js");
|
const User = require("./User.js");
|
||||||
const Room = require("./Room.js");
|
const Channel = require("./Channel.js");
|
||||||
const RoomSettings = require('./RoomSettings');
|
const RoomSettings = require('./RoomSettings');
|
||||||
const Database = require('./Database');
|
const Database = require('./Database');
|
||||||
|
|
||||||
|
@ -319,9 +319,7 @@ module.exports = (cl) => {
|
||||||
|
|
||||||
cl.on('clear_chat', (msg, admin) => {
|
cl.on('clear_chat', (msg, admin) => {
|
||||||
if (!admin) return;
|
if (!admin) return;
|
||||||
cl.channel.connections.forEach(cl => {
|
cl.channel.setChatArray([]);
|
||||||
cl.sendArray([{m:"c", c:[]}]);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cl.on('sudo', (msg, admin) => {
|
cl.on('sudo', (msg, admin) => {
|
||||||
|
|
Loading…
Reference in New Issue