stuff not finished

This commit is contained in:
Hri7566 2021-05-09 22:02:04 -04:00
parent b45f1d0d59
commit 54adc8a6db
3 changed files with 18 additions and 13 deletions

View File

@ -70,12 +70,11 @@ class Database {
static async updateUser(_id, data) { static async updateUser(_id, data) {
let user = await UserModel.findOne({_id: _id}).exec(); let user = await UserModel.findOne({_id: _id}).exec();
UserModel.updateOne({_id: _id}, {
name: data.name, user.name = data.name;
color: data.color, user._id = data._id;
_id: data._id, user.flags = data.flags;
flags: data.flags user.color = data.color;
});
await user.save(); await user.save();
} }

View File

@ -43,6 +43,8 @@ module.exports = (cl) => {
if (msg._id.length > 512) return; if (msg._id.length > 512) return;
if (!cl.staticQuotas.room.attempt()) return; if (!cl.staticQuotas.room.attempt()) return;
cl.user.checkFlags();
cl.setChannel(msg._id, msg.set); cl.setChannel(msg._id, msg.set);
let param; let param;
@ -55,11 +57,9 @@ module.exports = (cl) => {
param = Quota.N_PARAMS_RIDICULOUS; param = Quota.N_PARAMS_RIDICULOUS;
} }
} }
param.m = "nq"; param.m = "nq";
setTimeout(() => { setTimeout(() => {
cl.user.checkFlags();
cl.sendArray([param]); cl.sendArray([param]);
}, 1000); }, 1000);
} }
@ -222,7 +222,7 @@ module.exports = (cl) => {
}); });
cl.on("bye", msg => { cl.on("bye", msg => {
clearInterval(cl.user.rainbow); cl.user.stopFlagEvents();
cl.destroy(); cl.destroy();
}); });
@ -288,7 +288,6 @@ module.exports = (cl) => {
cl.on('user_flag', (msg, admin) => { cl.on('user_flag', (msg, admin) => {
if (!admin) return; if (!admin) return;
if (!msg.hasOwnProperty('_id') || !msg.hasOwnProperty('key') || !msg.hasOwnProperty('value')) return; if (!msg.hasOwnProperty('_id') || !msg.hasOwnProperty('key') || !msg.hasOwnProperty('value')) return;
console.log("stuff");
cl.server.connections.forEach((usr) => { cl.server.connections.forEach((usr) => {
if ((usr.channel && usr.participantId && usr.user) && (usr.user._id == msg._id || (usr.participantId == msg.id))) { if ((usr.channel && usr.participantId && usr.user) && (usr.user._id == msg._id || (usr.participantId == msg.id))) {
@ -299,11 +298,10 @@ module.exports = (cl) => {
return; return;
} }
usr.user.flags[msg.key] = msg.value; usr.user.flags[msg.key] = msg.value;
Database.updateUser(usr.user._id, usr.user);
usr.user.checkFlags(); usr.user.checkFlags();
} }
}); });
console.log(`set user flag: ${msg.key} - ${msg.value}`);
}); });
cl.on('clear_chat', (msg, admin) => { cl.on('clear_chat', (msg, admin) => {

View File

@ -32,9 +32,12 @@ class User {
} }
checkFlags() { 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.hasFlag('rainbow', true)) {
if (!this.cl.server.specialIntervals[this._id].hasOwnProperty('rainbow')) { if (!this.cl.server.specialIntervals[this._id].hasOwnProperty('rainbow')) {
console.log('rainbow triggered');
let h = Math.floor(Math.random() * 360); let h = Math.floor(Math.random() * 360);
let s = 50; let s = 50;
let l = 50; let l = 50;
@ -65,10 +68,15 @@ class User {
}, 1000/15); }, 1000/15);
} }
} else if (this.hasFlag('rainbow', false)) { } else if (this.hasFlag('rainbow', false)) {
console.log('rainbow off triggered');
clearInterval(this.cl.server.specialIntervals[this._id].rainbow); clearInterval(this.cl.server.specialIntervals[this._id].rainbow);
} }
} }
stopFlagEvents() {
clearInterval(this.cl.server.specialIntervals[this._id].rainbow);
}
hasFlag(flag, val) { hasFlag(flag, val) {
if (!val) return this.flags.hasOwnProperty(flag); if (!val) return this.flags.hasOwnProperty(flag);
return this.flags.hasOwnProperty(flag) && this.flags[flag] == val; return this.flags.hasOwnProperty(flag) && this.flags[flag] == val;