stuff not finished

This commit is contained in:
Hri7566 2021-05-09 22:02:04 -04:00
parent 1b6ea68613
commit 50455f0a80
3 changed files with 18 additions and 13 deletions

View File

@ -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();
}

View File

@ -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;
@ -56,10 +58,8 @@ module.exports = (cl) => {
}
}
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) => {

View File

@ -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;