npm-package-nodejs-utils-lda
Version:
Este projeto tem como fins de criar e abstrair módulos basicos e utilidades para o node js
31 lines (22 loc) • 900 B
JavaScript
const {sendTo} = require("./wsUtils.cjs");
function onCommandSendTo(cliente, msg, clientes) {
const withoutCommand = msg.slice(4).trim();
const commaIndex = withoutCommand.indexOf(",");
if (commaIndex === -1) {
cliente.send("[SERVER] Invalid /to command. Use: /to username, message");
return false;
}
const destino = withoutCommand.slice(0, commaIndex).trim();
const mensagem = withoutCommand.slice(commaIndex + 1).trim();
if (!destino || !mensagem) {
cliente.send("[SERVER] Invalid format. Usage: /to username, message");
return false;
}
const fullMessage = `[DM from ${cliente.name} to ${destino}]: ${mensagem}`;
const sent = sendTo(clientes, destino, fullMessage); // ✅ CORRIGIDO
if (!sent) {
cliente.send(`[SERVER] Could not deliver message to ${destino}.`);
}
return sent;
}
module.exports = onCommandSendTo;