smnmpp-server/protocol/custom.js

30 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-09-13 03:38:54 +02:00
module.exports.run = async (ws,user,db,msg,fun,users,connections) => {
if (!user.connected) return;
if (!user.channel) return;
if (!users[user._id].custombypass && (!user.quotas.custom.try() || JSON.stringify(msg.data).length > 2048)) return;
if (typeof msg.target !== "object") return;
//if (JSON.stringify(msg.data).length > 2048) return
var sendto = connections.filter(a => a.user.connected && a.user._id !== user._id)
if (msg.target.mode === "subscribed") {
var sendto = sendto.filter(a => a.user.sub.custom)
} else if (msg.target.mode === "ids") {
if (typeof msg.target.ids !== "array") return
if (msg.target.ids > 32) return
var sendto = sendto.filter(a => msg.target.ids.filter(b => typeof b === "string").includes(a.user._id))
} else if (msg.target.mode === "id") {
if (typeof msg.target.id !== "string") return
var sendto = sendto.filter(a => a.user._id === msg.target.id)
} else return;
if (!msg.target.global) {
var sendto = sendto.filter(a => a.user.channel === user.channel)
}
//console.log(sendto.map(a => `${a.user._id} in ${a.user.channel}`))
sendto.forEach(a => a.sendData({m: "custom", data: msg.data, p: user._id}))
user.quotas.custom.spend(1)
}
module.exports.name = "custom"