mirror of
https://github.com/hack-chat/main.git
synced 2024-03-22 13:20:33 +08:00
Merge pull request #16 from OpSimple/master
A new way to handle the spammers
This commit is contained in:
commit
71e940ddba
|
@ -34,6 +34,8 @@ hack.chat has three permission levels. When you access a command, hack.chat auto
|
|||
|`ban`|`nick`|Disconnects the target nickname in the same channel as the calling socket and adds it to the rate limiter.|
|
||||
|`kick`|`nick`|Silently forces target client(s) into another channel. `nick` may be `string` or `array` of `string`s.|
|
||||
|`unban`|`ip` or `hash`|Removes the target ip from the rate limiter.|
|
||||
|`dumb`|`nick`|Mutes a user's (spammer's) texts such that it is displayable to the user only.|
|
||||
|`speak`|`ip` or `hash`|Unmutes the user's (spammer's) texts and makes it displayable to everyone again.|
|
||||
|
||||
# `admin`
|
||||
|
||||
|
|
|
@ -48,7 +48,15 @@ exports.run = async (core, server, socket, data) => {
|
|||
payload.trip = socket.trip;
|
||||
}
|
||||
|
||||
server.broadcast( payload, { channel: socket.channel });
|
||||
if(core.muzzledHashes && core.muzzledHashes[socket.hash]){
|
||||
server.broadcast( payload, { channel: socket.channel, hash: socket.hash });
|
||||
if(core.muzzledHashes[socket.hash].allies){
|
||||
server.broadcast( payload, { channel: socket.channel, nick: core.muzzledHashes[socket.hash].allies });
|
||||
}
|
||||
} else {
|
||||
//else send it to everyone
|
||||
server.broadcast( payload, { channel: socket.channel});
|
||||
}
|
||||
|
||||
core.managers.stats.increment('messages-sent');
|
||||
};
|
||||
|
@ -59,4 +67,4 @@ exports.info = {
|
|||
name: 'chat',
|
||||
usage: 'chat {text}',
|
||||
description: 'Broadcasts passed `text` field to the calling users channel'
|
||||
};
|
||||
};
|
||||
|
|
|
@ -115,6 +115,7 @@ exports.run = async (core, server, socket, data) => {
|
|||
socket.uType = uType;
|
||||
socket.nick = nick;
|
||||
socket.channel = channel;
|
||||
socket.hash = server.getSocketHash(socket);
|
||||
if (trip !== null) socket.trip = trip;
|
||||
nicks.push(socket.nick);
|
||||
|
||||
|
@ -132,4 +133,4 @@ exports.info = {
|
|||
name: 'join',
|
||||
usage: 'join {channel} {nick}',
|
||||
description: 'Place calling socket into target channel with target nick & broadcast event to channel'
|
||||
};
|
||||
};
|
||||
|
|
63
server/src/commands/mod/dumb.js
Normal file
63
server/src/commands/mod/dumb.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Description: Make a user (spammer) dumb
|
||||
* Author: simple
|
||||
*/
|
||||
|
||||
exports.init = (core) => {
|
||||
core.muzzledHashes = {};
|
||||
}
|
||||
|
||||
exports.run = async (core, server, socket, data) => {
|
||||
if (socket.uType == 'user') {
|
||||
// ignore if not mod or admin
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof data.nick !== 'string') {
|
||||
return;
|
||||
}
|
||||
|
||||
let badClient = server.findSockets({ channel: socket.channel, nick: data.nick });
|
||||
|
||||
if (badClient.length === 0) {
|
||||
server.reply({
|
||||
cmd: 'warn',
|
||||
text: 'Could not find user in channel'
|
||||
}, socket);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
badClient = badClient[0];
|
||||
|
||||
if (badClient.uType !== 'user') {
|
||||
server.reply({
|
||||
cmd: 'warn',
|
||||
text: 'This trick wont work on mods and admin'
|
||||
}, socket);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let record = core.muzzledHashes[badClient.hash] = {
|
||||
dumb:true
|
||||
}
|
||||
|
||||
if(data.allies && Array.isArray(data.allies)){
|
||||
record.allies = data.allies;
|
||||
}
|
||||
|
||||
server.broadcast({
|
||||
cmd: 'info',
|
||||
text: `${socket.nick} muzzled ${data.nick} in ${socket.channel}, userhash: ${badClient.hash}`
|
||||
}, { uType: 'mod' });
|
||||
|
||||
}
|
||||
|
||||
exports.requiredData = ['nick'];
|
||||
|
||||
exports.info = {
|
||||
name: 'dumb',
|
||||
usage: 'dumb {nick} [allies...]',
|
||||
description: 'Cleanly disable a user messages and make him dumb'
|
||||
};
|
43
server/src/commands/mod/speak.js
Normal file
43
server/src/commands/mod/speak.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Description: Pardon a dumb user to be able to speak again
|
||||
* Author: simple
|
||||
*/
|
||||
|
||||
|
||||
exports.run = async (core, server, socket, data) => {
|
||||
if (socket.uType == 'user') {
|
||||
// ignore if not mod or admin
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof data.ip !== 'string' && typeof data.hash !== 'string') {
|
||||
server.reply({
|
||||
cmd: 'warn',
|
||||
text: "hash:'targethash' or ip:'1.2.3.4' is required"
|
||||
}, socket);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let target;
|
||||
|
||||
if (typeof data.ip === 'string') {
|
||||
target = getSocketHash(data.ip);
|
||||
} else {
|
||||
target = data.hash;
|
||||
}
|
||||
|
||||
delete core.muzzledHashes[target];
|
||||
|
||||
server.broadcast({
|
||||
cmd: 'info',
|
||||
text: `${socket.nick} unmuzzled : ${target}`
|
||||
}, { uType: 'mod' });
|
||||
|
||||
}
|
||||
|
||||
exports.info = {
|
||||
name: 'speak',
|
||||
usage: 'speak {[ip || hash]}',
|
||||
description: 'Pardon a dumb user to be able to speak again'
|
||||
};
|
Loading…
Reference in New Issue
Block a user