1
0
mirror of https://github.com/hack-chat/main.git synced 2024-03-22 13:20:33 +08:00

Make dumb use abstracted invite functions rather than duplicating code

This commit is contained in:
MinusGix 2020-03-06 17:13:03 -06:00
parent f2ad0e5611
commit 1d01376ba5

View File

@ -4,6 +4,7 @@
*/
import * as UAC from '../utility/UAC/_info';
import * as Invite from '../core/invite';
// module constructor
export function init(core) {
@ -117,19 +118,21 @@ export function chatCheck(core, server, socket, payload) {
// shadow-prevent all invites from muzzled users
export function inviteCheck(core, server, socket, payload) {
if (typeof payload.nick !== 'string') {
return false;
}
if (core.muzzledHashes[socket.hash]) {
const nickValid = Invite.checkNickname(payload.nick);
if (nickValid !== null) {
server.reply({
cmd: 'warn',
text: nickValid,
}, socket);
return false;
}
// generate common channel
const channel = Math.random().toString(36).substr(2, 8);
const channel = Invite.getChannel();
// send fake reply
server.reply({
cmd: 'info',
text: `You invited ${payload.nick} to ?${channel}`,
}, socket);
server.reply(Invite.createSuccessPayload(payload.nick, channel), socket);
return false;
}