smnmpp-server/protocol/v.js

16 lines
993 B
JavaScript

module.exports.run = async (ws,user,db,msg,fun,users,connections) => {
if (!user.connected) return;
if (!user.channel) return;
if (users[user._id].rank < 1) return
if (typeof msg.vanish !== "boolean") return
if (users[user._id].p.vanished === msg.vanish) return;
users[user._id].p.vanished = msg.vanish
db.users.put(user._id, JSON.stringify(users[user._id]))
Object.values(channels).forEach(a => {if (a.ppl.map(a => a._id).includes(user._id)) a.ppl[a.ppl.indexOf(a.ppl.find(a => a._id === user._id))] = users[user._id].p })
connections.filter(a => channels[a.user.channel].ppl.map(a => a._id).includes(user._id) && users[a.user._id].rank < 1).forEach(a => {var channel = channels[a.user.channel]; channel.p = a.user._id; a.sendData(fun.vanish(channel, users[a.user._id].rank))})
connections.filter(a => a.user.connected && channels[a.user.channel].ppl.map(p => p._id).includes(user._id) && users[a.user._id].rank >= 1).forEach(a => a.sendData(users[user._id].p))
}
module.exports.name = "v"