Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit 6883309

Browse files
author
Zirak
committed
added a message length filter to spam detection (#52)
1 parent 211b0f4 commit 6883309

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

master.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5591,12 +5591,13 @@ IO.register( 'rawinput', function spamDetection ( msgObj ) {
55915591
return;
55925592
}
55935593

5594-
var usrid = msgObj.user_id;
5594+
var usrid = msgObj.user_id,
5595+
message = IO.decodehtmlEntities( msgObj.content );
5596+
55955597
//there is a heavy assumption that all users who post a message here have
55965598
// been registered by the bot
55975599
var user = bot.users[ usrid ];
5598-
//since it's still in testing, it's rigged to respond to me (Zirak, 617762)
5599-
if ( usrid !== 617762 && (bot.isOwner(usrid) || user.reputation > 1000) ) {
5600+
if ( legitMessage() ) {
56005601
return;
56015602
}
56025603

@@ -5605,23 +5606,35 @@ IO.register( 'rawinput', function spamDetection ( msgObj ) {
56055606
var query = '#chat .monologue.user-{0} .content'.supplant( usrid ),
56065607
userMessages = document.querySelectorAll( query );
56075608

5608-
var exactMatches = Array.filter( userMessages, function ( content ) {
5609-
var msgid = ( /\d+/ ).exec( content.parentNode.id )[ 0 ];
5610-
return msgid < msgObj.message_id &&
5611-
content.innerHTML === msgObj.content;
5612-
});
5609+
var exactMatches = Array.filter( userMessages, filterMessage );
56135610

56145611
if ( !exactMatches.length ) {
56155612
return;
56165613
}
5617-
bot.log( exactMatches, msgObj.content, 'spam detection matches' );
5614+
bot.log( exactMatches, message, 'spam detection matches' );
56185615

56195616
var reply = 'Please don\'t post the same thing more than once in a short ' +
56205617
'period of time. If it\'s a question, try again in a few hours.';
56215618

56225619
bot.adapter.out.add(
56235620
bot.adapter.reply(msgObj.user_name) + " " + reply,
56245621
msgObj.room_id );
5622+
5623+
function filterMessage ( content ) {
5624+
var msgid = ( /\d+/ ).exec( content.parentNode.id )[ 0 ];
5625+
return msgid < msgObj.message_id &&
5626+
content.innerHTML === message;
5627+
}
5628+
function legitMessage () {
5629+
//since it's still in testing, it should respond to me (Zirak, 617762)
5630+
if ( usrid === 617762 ) {
5631+
return false;
5632+
}
5633+
//these are the actual filters
5634+
return message.length < 50 &&
5635+
bot.isOwner(usrid) ||
5636+
user.reputation > 1000
5637+
}
56255638
});
56265639

56275640
;

0 commit comments

Comments
 (0)