Created
September 12, 2017 16:45
-
-
Save xatlas/887ca4eaf543ab783ac900696b1641ea to your computer and use it in GitHub Desktop.
Dirty script anti repeats for Eggdrop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# by Tris, 17jul96 (v2) | |
# action added by fantomas 22Dec1997 | |
# Updated to v4 (17 November 1998) by slennox <[email protected]> | |
# Fixed version (1 December 1998) | |
# Updated to v4.1 (8 December 1998) | |
# Updated (25 November 2002) @/+ exempt | |
# Updated to v5 by Atlas (9 March 2012) | |
# Updated to v6 by Atlas (22 Sept 2014) [Prediction text] | |
# Updated to v6.2 by Atlas (05 Oct 2014) [Percent similar text] | |
# Number of repeats to trigger | |
set repeatkick 3 | |
set repeatban 4 | |
set repeatmaxwarn 2 | |
# In how many minutes (disabled) | |
set repeattime 300 | |
set repeatwarntime 300 | |
# Ban time | |
set repeatbantime 120 | |
# Messages (can NOT use variables as $nick or $chan) | |
set repeatwarnmsg "Por favor, no envies mensajes repetitivos al canal. Con una vez te leemos" | |
set repeatkickmsg "Repeticiones constantes" | |
# Minimal number of characters to check | |
set repeatminchars 18 | |
# Similarity of text | |
set repeat_percent 80 | |
# Channel | |
set repeatchans "#canal" | |
# End of config | |
############################################################################# | |
############################################################################# | |
############################################################################# | |
############################################################################# | |
############################################################################# | |
# Start script | |
bind pubm - * repeat_pubm | |
bind ctcp - ACTION repeat_action | |
bind nick - * repeat_nick | |
# proc repeat_timr {} { | |
# global repeat_last repeattime | |
# catch {unset repeat_last} | |
# catch {unset repeat_num} | |
# timer $repeattime repeat_timr | |
# } | |
# proc repeat_warntimr {} { | |
# global repeat_warn repeatwarntime | |
# catch {unset repeat_warn} | |
# timer $repeatwarntime repeat_warntimr | |
# } | |
# if ![regexp repeat_timr [timers]] {timer $repeattime repeat_timr} | |
# if ![regexp repeat_warntimr [timers]] {timer $repeatwarntime repeat_warntimr} | |
proc repeat_action {nick uhost hand dest keyword text} { | |
repeat_pubm $nick $uhost $hand $dest $text | |
} | |
proc repeat_pubm {nick uhost hand chan text} { | |
global repeatkick repeatban repeatwarnmsg repeatkickmsg repeatwarn repeatmaxwarn repeattime repeatbantime repeatwarntime | |
global repeat_last repeat_num repeatminchars repeatchans repeat_similar repeat_percent | |
if {[lsearch -exact [split [string tolower $repeatchans]] [string tolower $chan]] == -1} {return 0} | |
if {![botisop $chan]} {return} | |
if {[isop $nick $chan] || [isvoice $nick $chan]} {return 0} | |
set textlength [string length $text] | |
if {$textlength <= $repeatminchars} {return 0} | |
proc repeatantiflood {} {return 0} | |
if [info exists repeat_last([set n [string tolower [string range $uhost [string first "@" $uhost] end]]])] { | |
regsub -all {[^a-z]} [string tolower $repeat_last($n)] "" repeat_lastsub($n) | |
regsub -all {[^a-z]} [string tolower $text] "" textsub | |
set similar [Similar $repeat_lastsub($n) $textsub] | |
set percent [format %.2f [expr 100 - {(double($similar) / $textlength) * 100.0}]] | |
if {$percent > $repeat_percent} { | |
if {($percent < 99) && ([regexp -nocase {^http\S+youtu\.?be\S+[a-z0-9]{11}} $text text])} { | |
putlog "\[RePs\] Texto especial enviado por $nick ($uhost) \[$percent% / [expr $repeat_percent+15]\]" | |
return | |
} | |
putlog "\[\002RePs\002\] \002$nick\002 ($uhost) enviando \00312[expr $repeat_num($n)+1]\003 veces \"$text\" ($textsub - $percent%)" | |
set reps_banmask [repeat_ipv $nick $uhost] | |
if {[incr repeat_num($n)] < ${repeatkick}} { | |
incr repeatwarn($uhost) | |
if {[expr $repeatwarn($uhost)-1] >= $repeatmaxwarn} { | |
puthelp "KICK $chan $nick :$repeatkickmsg!" | |
putquick "MODE $chan +b $reps_banmask" | |
puthelp "NOTICE @$chan :Expulsado \002$nick\002 por haber repetido habiendo sido avisado [expr $repeatwarn($uhost)-1] veces" | |
putlog "\[RePs\] $nick ($uhost) expulsado por haber sido avisado \00312[expr $repeatwarn($uhost)-1]\003 veces" | |
unset repeatwarn($uhost) | |
timer $repeattime [list puthelp "MODE $chan -b $reps_banmask"] | |
return | |
} | |
puthelp "NOTICE @$chan :Avisando a \002$nick\002 por \037repeticiones\037 \[$percent%\]" | |
puthelp "NOTICE $nick :$repeatwarnmsg" | |
} elseif {$repeat_num($n) == ${repeatkick}} { | |
puthelp "KICK $chan $nick :$repeatkickmsg" | |
} elseif {$repeat_num($n) >= ${repeatban}} { | |
newignore $reps_banmask repeat.tcl Ignore-flood 1 | |
newchanban $chan $reps_banmask repeat.tcl $repeatkickmsg [expr 60 * 15] | |
puthelp "KICK $chan $nick :$repeatkickmsg" | |
putnow "MODE $chan +b $reps_banmask" | |
timer $repeattime [list puthelp "MODE $chan -b $reps_banmask"] | |
} | |
if {$repeat_num($n) >= ${repeatban}} { | |
unset repeat_last($n) | |
unset repeat_num($n) | |
} | |
return | |
} | |
} | |
set repeat_num($n) 1 | |
set repeat_last($n) $text | |
} | |
proc repeat_nick {nick uhost hand chan newnick} { | |
if {[matchattr $nick mo|mo $chan] || [isop $nick $chan] || [isvoice $nick $chan] || [matchattr $nick o|o $chan]} {return 0} | |
global repeat_last repeat_num | |
catch {set repeat_last([set nn [string tolower $newnick]]) \ | |
$repeat_last([set on [string tolower $nick]])} | |
catch {unset repeat_last($on)} | |
catch {set repeat_num($nn) $repeat_num($on)} | |
catch {unset repeat_num($on)} | |
} | |
proc Similar {s t} { | |
# Edge cases | |
#regsub -all {[^b-zB-Z]} $string "_" s | |
#regsub -all {[^b-zB-Z]} $text "_" t | |
#set s [string tolower $s] | |
#set t [string tolower $t] | |
if {![set n [string length $t]]} { | |
return [string length $s] | |
} elseif {![set m [string length $s]]} { | |
return $n | |
} | |
# Fastest way to initialize | |
for {set i 0} {$i <= $m} {incr i} { | |
lappend d 0 | |
lappend p $i | |
} | |
# Loop, computing the distance table (well, a moving section) | |
for {set j 0} {$j < $n} {} { | |
set tj [string index $t $j] | |
lset d 0 [incr j] | |
for {set i 0} {$i < $m} {} { | |
set a [expr {[lindex $d $i]+1}] | |
set b [expr {[lindex $p $i]+([string index $s $i] ne $tj)}] | |
set c [expr {[lindex $p [incr i]]+1}] | |
# Faster than min($a,$b,$c) | |
lset d $i [expr {$a<$b ? $c<$a ? $c : $a : $c<$b ? $c : $b}] | |
} | |
# Swap | |
set nd $p; set p $d; set d $nd | |
} | |
# The score is at the end of the last-computed row | |
return [lindex $p end] | |
} | |
proc repeat_ipv {n u} { | |
if {![regexp {[^@]+@[A-D][A-z0-9]{5}\.[A-D][A-z0-9]{5}\.v(irtual|6)} $u]} { | |
return "$n!*@*" | |
} else { | |
return "*!*[string range $u [string first "@" $u] end]" | |
} | |
} | |
putlog "Cargado script antirrepeticiones \[$repeat_percent%\]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment