2018-06-04 02:08:35 +08:00
|
|
|
/*
|
2018-09-30 14:44:36 +08:00
|
|
|
* Description: Make a user (spammer) dumb (mute)
|
2018-06-01 03:42:54 +08:00
|
|
|
* Author: simple
|
|
|
|
*/
|
|
|
|
|
2020-03-06 00:49:25 +08:00
|
|
|
import * as UAC from "../utility/UAC/info";
|
|
|
|
|
2018-09-30 14:44:36 +08:00
|
|
|
// module constructor
|
2019-11-07 15:35:23 +08:00
|
|
|
export function init(core) {
|
2018-09-30 14:44:36 +08:00
|
|
|
if (typeof core.muzzledHashes === 'undefined') {
|
2018-06-01 03:42:54 +08:00
|
|
|
core.muzzledHashes = {};
|
2018-09-30 14:44:36 +08:00
|
|
|
}
|
2019-11-07 15:35:23 +08:00
|
|
|
}
|
2018-06-01 03:42:54 +08:00
|
|
|
|
2018-09-30 14:44:36 +08:00
|
|
|
// module main
|
2019-11-07 15:35:23 +08:00
|
|
|
export async function run(core, server, socket, data) {
|
2018-06-04 15:07:24 +08:00
|
|
|
// increase rate limit chance and ignore if not admin or mod
|
2020-03-06 00:49:25 +08:00
|
|
|
if (!UAC.isModerator(socket.level)) {
|
2019-11-07 15:35:23 +08:00
|
|
|
return server.police.frisk(socket.address, 10);
|
2018-06-01 03:42:54 +08:00
|
|
|
}
|
|
|
|
|
2018-06-04 15:07:24 +08:00
|
|
|
// check user input
|
2018-06-01 03:42:54 +08:00
|
|
|
if (typeof data.nick !== 'string') {
|
2019-11-07 15:35:23 +08:00
|
|
|
return true;
|
2018-06-01 03:42:54 +08:00
|
|
|
}
|
2018-06-04 02:08:35 +08:00
|
|
|
|
2018-06-04 15:07:24 +08:00
|
|
|
// find target user
|
2018-06-01 21:35:15 +08:00
|
|
|
let badClient = server.findSockets({ channel: socket.channel, nick: data.nick });
|
2018-06-01 03:42:54 +08:00
|
|
|
|
|
|
|
if (badClient.length === 0) {
|
2018-09-30 14:44:36 +08:00
|
|
|
return server.reply({
|
2018-06-01 03:42:54 +08:00
|
|
|
cmd: 'warn',
|
2019-11-07 15:35:23 +08:00
|
|
|
text: 'Could not find user in channel',
|
2018-06-01 03:42:54 +08:00
|
|
|
}, socket);
|
|
|
|
}
|
|
|
|
|
2019-11-07 15:35:23 +08:00
|
|
|
[badClient] = badClient;
|
2018-06-01 03:42:54 +08:00
|
|
|
|
2018-06-04 15:07:24 +08:00
|
|
|
// likely dont need this, muting mods and admins is fine
|
2020-03-06 00:49:25 +08:00
|
|
|
if (badClient.level >= socket.level) {
|
2018-09-30 14:44:36 +08:00
|
|
|
return server.reply({
|
2018-06-01 03:42:54 +08:00
|
|
|
cmd: 'warn',
|
2019-11-07 15:35:23 +08:00
|
|
|
text: 'This trick wont work on mods and admin',
|
2018-06-01 03:42:54 +08:00
|
|
|
}, socket);
|
|
|
|
}
|
2018-06-04 02:08:35 +08:00
|
|
|
|
2018-06-04 15:07:24 +08:00
|
|
|
// store hash in mute list
|
2019-11-07 15:35:23 +08:00
|
|
|
const record = core.muzzledHashes[badClient.hash] = {
|
|
|
|
dumb: true,
|
|
|
|
};
|
2018-06-04 02:08:35 +08:00
|
|
|
|
2018-06-04 15:07:24 +08:00
|
|
|
// store allies if needed
|
2019-11-07 15:35:23 +08:00
|
|
|
if (data.allies && Array.isArray(data.allies)) {
|
|
|
|
record.allies = data.allies;
|
2018-06-01 06:09:12 +08:00
|
|
|
}
|
2018-06-04 02:08:35 +08:00
|
|
|
|
2018-06-04 15:07:24 +08:00
|
|
|
// notify mods
|
2018-06-01 03:42:54 +08:00
|
|
|
server.broadcast({
|
|
|
|
cmd: 'info',
|
2019-11-07 15:35:23 +08:00
|
|
|
text: `${socket.nick} muzzled ${data.nick} in ${socket.channel}, userhash: ${badClient.hash}`,
|
2020-03-06 00:49:25 +08:00
|
|
|
}, { level: UAC.isModerator });
|
2019-11-07 15:35:23 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-06-01 03:42:54 +08:00
|
|
|
|
2018-09-30 14:44:36 +08:00
|
|
|
// module hook functions
|
2019-11-07 15:35:23 +08:00
|
|
|
export function initHooks(server) {
|
2019-11-08 01:46:55 +08:00
|
|
|
server.registerHook('in', 'chat', this.chatCheck.bind(this), 25);
|
|
|
|
server.registerHook('in', 'invite', this.inviteCheck.bind(this), 25);
|
2018-09-30 14:44:36 +08:00
|
|
|
// TODO: add whisper hook, need hook priorities todo finished first
|
2019-11-07 15:35:23 +08:00
|
|
|
}
|
2018-09-30 14:44:36 +08:00
|
|
|
|
|
|
|
// hook incoming chat commands, shadow-prevent chat if they are muzzled
|
2019-11-07 15:35:23 +08:00
|
|
|
export function chatCheck(core, server, socket, payload) {
|
2018-09-30 14:44:36 +08:00
|
|
|
if (typeof payload.text !== 'string') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-07 15:35:23 +08:00
|
|
|
if (core.muzzledHashes[socket.hash]) {
|
2018-09-30 14:44:36 +08:00
|
|
|
// build fake chat payload
|
2019-11-07 15:35:23 +08:00
|
|
|
const mutedPayload = {
|
2018-09-30 14:44:36 +08:00
|
|
|
cmd: 'chat',
|
|
|
|
nick: socket.nick,
|
2019-11-07 15:35:23 +08:00
|
|
|
text: payload.text,
|
2018-09-30 14:44:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
if (socket.trip) {
|
|
|
|
mutedPayload.trip = socket.trip;
|
|
|
|
}
|
|
|
|
|
|
|
|
// broadcast to any duplicate connections in channel
|
2019-11-07 15:35:23 +08:00
|
|
|
server.broadcast(mutedPayload, { channel: socket.channel, hash: socket.hash });
|
2018-06-01 03:42:54 +08:00
|
|
|
|
2018-09-30 14:44:36 +08:00
|
|
|
// broadcast to allies, if any
|
2019-11-07 15:35:23 +08:00
|
|
|
if (core.muzzledHashes[socket.hash].allies) {
|
|
|
|
server.broadcast(
|
|
|
|
mutedPayload,
|
|
|
|
{
|
|
|
|
channel: socket.channel,
|
|
|
|
nick: core.muzzledHashes[socket.hash].allies,
|
|
|
|
},
|
|
|
|
);
|
2018-09-30 14:44:36 +08:00
|
|
|
}
|
|
|
|
|
2019-11-07 15:35:23 +08:00
|
|
|
/**
|
|
|
|
* Blanket "spam" protection.
|
|
|
|
* May expose the ratelimiting lines from `chat` and use that
|
|
|
|
* @todo one day #lazydev
|
|
|
|
*/
|
|
|
|
server.police.frisk(socket.address, 9);
|
2018-09-30 14:44:36 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return payload;
|
2019-11-07 15:35:23 +08:00
|
|
|
}
|
2018-09-30 14:44:36 +08:00
|
|
|
|
|
|
|
// shadow-prevent all invites from muzzled users
|
2019-11-07 15:35:23 +08:00
|
|
|
export function inviteCheck(core, server, socket, payload) {
|
2018-09-30 14:44:36 +08:00
|
|
|
if (typeof payload.nick !== 'string') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-07 15:35:23 +08:00
|
|
|
if (core.muzzledHashes[socket.hash]) {
|
2018-09-30 14:44:36 +08:00
|
|
|
// generate common channel
|
2019-11-07 15:35:23 +08:00
|
|
|
const channel = Math.random().toString(36).substr(2, 8);
|
2018-09-30 14:44:36 +08:00
|
|
|
|
|
|
|
// send fake reply
|
|
|
|
server.reply({
|
|
|
|
cmd: 'info',
|
2019-11-07 15:35:23 +08:00
|
|
|
text: `You invited ${payload.nick} to ?${channel}`,
|
2018-09-30 14:44:36 +08:00
|
|
|
}, socket);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return payload;
|
2019-11-07 15:35:23 +08:00
|
|
|
}
|
2018-09-30 14:44:36 +08:00
|
|
|
|
2019-11-07 15:35:23 +08:00
|
|
|
export const requiredData = ['nick'];
|
|
|
|
export const info = {
|
2018-06-01 03:42:54 +08:00
|
|
|
name: 'dumb',
|
2018-09-30 14:44:36 +08:00
|
|
|
description: 'Globally shadow mute a connection. Optional allies array will see muted messages.',
|
|
|
|
usage: `
|
2019-11-07 15:35:23 +08:00
|
|
|
API: { cmd: 'dumb', nick: '<target nick>', allies: ['<optional nick array>', ...] }`,
|
2018-06-01 03:42:54 +08:00
|
|
|
};
|
2019-11-07 15:35:23 +08:00
|
|
|
info.aliases = ['muzzle', 'mute'];
|