From 50455f0a80f4fc5ae240a65855068640077e56d8 Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Sun, 9 May 2021 22:02:04 -0400 Subject: [PATCH] stuff not finished --- src/Database.js | 11 +++++------ src/Message.js | 10 ++++------ src/User.js | 10 +++++++++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Database.js b/src/Database.js index 84f12a1..638063f 100644 --- a/src/Database.js +++ b/src/Database.js @@ -70,12 +70,11 @@ class Database { static async updateUser(_id, data) { let user = await UserModel.findOne({_id: _id}).exec(); - UserModel.updateOne({_id: _id}, { - name: data.name, - color: data.color, - _id: data._id, - flags: data.flags - }); + + user.name = data.name; + user._id = data._id; + user.flags = data.flags; + user.color = data.color; await user.save(); } diff --git a/src/Message.js b/src/Message.js index a06d657..c5f32b3 100644 --- a/src/Message.js +++ b/src/Message.js @@ -43,6 +43,8 @@ module.exports = (cl) => { if (msg._id.length > 512) return; if (!cl.staticQuotas.room.attempt()) return; + cl.user.checkFlags(); + cl.setChannel(msg._id, msg.set); let param; @@ -55,11 +57,9 @@ module.exports = (cl) => { param = Quota.N_PARAMS_RIDICULOUS; } } - param.m = "nq"; setTimeout(() => { - cl.user.checkFlags(); cl.sendArray([param]); }, 1000); } @@ -222,7 +222,7 @@ module.exports = (cl) => { }); cl.on("bye", msg => { - clearInterval(cl.user.rainbow); + cl.user.stopFlagEvents(); cl.destroy(); }); @@ -288,7 +288,6 @@ module.exports = (cl) => { cl.on('user_flag', (msg, admin) => { if (!admin) return; if (!msg.hasOwnProperty('_id') || !msg.hasOwnProperty('key') || !msg.hasOwnProperty('value')) return; - console.log("stuff"); cl.server.connections.forEach((usr) => { if ((usr.channel && usr.participantId && usr.user) && (usr.user._id == msg._id || (usr.participantId == msg.id))) { @@ -299,11 +298,10 @@ module.exports = (cl) => { return; } usr.user.flags[msg.key] = msg.value; + Database.updateUser(usr.user._id, usr.user); usr.user.checkFlags(); } }); - - console.log(`set user flag: ${msg.key} - ${msg.value}`); }); cl.on('clear_chat', (msg, admin) => { diff --git a/src/User.js b/src/User.js index 2be8e24..83c1852 100644 --- a/src/User.js +++ b/src/User.js @@ -32,9 +32,12 @@ class User { } checkFlags() { - if (typeof(this.cl.server.specialIntervals[this._id]) == 'undefined') this.cl.server.specialIntervals[this._id] = {}; + 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; @@ -65,10 +68,15 @@ class User { }, 1000/15); } } else if (this.hasFlag('rainbow', false)) { + console.log('rainbow off triggered'); clearInterval(this.cl.server.specialIntervals[this._id].rainbow); } } + stopFlagEvents() { + clearInterval(this.cl.server.specialIntervals[this._id].rainbow); + } + hasFlag(flag, val) { if (!val) return this.flags.hasOwnProperty(flag); return this.flags.hasOwnProperty(flag) && this.flags[flag] == val;