Created
February 10, 2023 08:14
-
-
Save andrioid/bf74be0479b6ac5bf01fb5361268de8d to your computer and use it in GitHub Desktop.
Old Eggdrop script I made for handling a busy Icelandic IRC channel
This file contains 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
# nosense.tcl by Andri Oskarsson | |
# - merlin@scrolls.org | |
# - Merlin@IRCnet | |
# | |
# designed to detect lines that are not classified as an actual conversation | |
# - It currently detects: caps, repeat, colors, bold, reverse, disturbance and more | |
# To mark channels for nosense detection do like (.chanset #channel +nosense) | |
# Lets make it so | |
setudef flag nosense | |
# Points - How many points for violations | |
set ns_points(caps) 10 ;# f.e. "MOMMY LOVES DADDY!!!" | |
set ns_points(colors) 3 ;# any lines with colored text | |
set ns_points(chanads) 9 ;# words with the # sign | |
set ns_points(bold) 0 ;# any lines with bold text | |
set ns_points(reverse) 3 ;# any lines with reverse text | |
set ns_points(disturb) 3 ;# f.e. "!!!!!!!" or "???????" or "........" | |
set ns_points(slap) 4 ;# f.e. "/me slaps Isgate around with a large trout | |
set ns_points(repeat) 10 ;# Repeats the same text line after line | |
set ns_points(largewords) 5 ;# Abnormally long words without spaces | |
set ns_points(hugewords) 16 ;# Abnormally long words without spaces 2 | |
set ns_points(chanadsmax) 16 ;# f.e. "#channel #channel #channel" | |
# Other settings | |
set ns_settings(kick_on) 10 | |
set ns_settings(ban_on) 16 | |
set ns_settings(kickmsg) "Spark fyrir reglubrot" | |
set ns_settings(banmsg) "Bann fyrir reglubrot" | |
set ns_settings(forget_time) 5 ;#Forget time in minutes | |
set ns_settings(forget_count) 5 ;# How many points to forget | |
set ns_settings(largewords_max) 30 ;# Abnormaly long words (mini) | |
set ns_settings(hugewords_max) 45 ;# Abnormaly long words (maxy) | |
set ns_settings(maxcaps) 80 ;# Percentage of caps (or higher) characters to punish | |
set ns_settings(ccminline) 5 ;# If charachers do not exceed 5 characters charcheck will return 0 | |
# Strip sings - Letters or text that should be stripped for repeat detection | |
# - So "yo momah!" and "yo momah!!" would be treated as the same text | |
set ns_striptags(1) "!" | |
set ns_striptags(2) "?" | |
set ns_striptags(3) "\." | |
set ns_striptags(4) "," | |
set ns_striptags(5) "#" | |
set ns_striptags(6) "<" | |
set ns_striptags(7) ">" | |
set ns_striptags(8) "/" | |
set ns_striptags(9) "-" | |
set ns_striptags(10) "_" | |
# And now for the script - Do not edit anything below this line or the script might stop functioning | |
# Lets start with the binds | |
bind PUBM - * nosense:parse_text | |
bind CTCP - ACTION nosense:pubact | |
bind DCC o nslist nosense:nslist | |
# This line lets us check /me lines as well for any nosense :) | |
proc nosense:pubact {nick uhost hand dest key arg} { | |
nosense:parse_text $nick $uhost $hand $dest $arg | |
} | |
# Now for the checking | |
proc nosense:parse_text {nick uhost handle channel text} { | |
global ns_points ns_settings ns_striptags badpoints badviolations violated badrepeat | |
if {![nosense:active $channel]} { return 0 } | |
set points 0 | |
set violated 0 | |
set lowertext [string tolower $text] | |
set uppertext [string toupper $text] | |
set nick [string tolower $nick] | |
set uhost [string tolower $uhost] | |
set channel [string tolower $channel] | |
set split_text [split $text] | |
# For repeat detection.. strips tags | |
set realtext "[nosense:realstring $text]" | |
# We cant do anything if the bot isnt opped so we just leave it there | |
if {![botisop $channel]} { return 0 } | |
# NOTE! for caps detection.. minlength of a string # FOR LATER # | |
# Chanads detection | |
if {[regexp -nocase {\#([a-z0-9A-Z����������������])} $text match]} { | |
nosense:pointstorage $uhost $channel "chanads" | |
} | |
# Repeat detection | |
if {![info exists badrepeat($nick%$uhost%$channel)]} { | |
set badrepeat($nick%$uhost%$channel) $realtext | |
} else { | |
if {$badrepeat($nick%$uhost%$channel) == $realtext} { | |
nosense:pointstorage $uhost $channel "repeat" | |
} else { | |
set badrepeat($nick%$uhost%$channel) $realtext | |
} | |
} | |
# Character check (caps) | |
if {[nosense:charcheck $text] == 1} { | |
nosense:pointstorage $uhost $channel "caps" | |
} | |
# Slap detection | |
if {[regexp -nocase {slaps.*around.*} $text match]} { | |
nosense:pointstorage $uhost $channel "slap" | |
} | |
# Disturbance detection | |
if {[regexp -nocase {(\?\?\?\?\?\?|\!\!\!\!\!|\.\.\.\.\.\.\.\.\.)} $text match]} { | |
nosense:pointstorage $uhost $channel "disturb" | |
} | |
# Color detection | |
if {[string match -nocase *\003* $text]} { | |
nosense:pointstorage $uhost $channel "colors" | |
} | |
# Bold detection (will still match (b):(b)) | |
if {[string match -nocase *\x02* $text]} { | |
nosense:pointstorage $uhost $channel "bold" | |
} | |
# Reverse detection | |
if {[string match -nocase *\x16* $text]} { | |
nosense:pointstorage $uhost $channel "reverse" | |
} | |
# chanads max (#CHANNEL #CHANNEL $CHANNEL) will be instantly banned | |
if {[regexp -nocase {\#([0-9]|[A-Z])* \#([0-9A-Z])} $text match]} { | |
nosense:pointstorage $uhost $channel "chanadsmax" | |
} | |
# Large/Huge words detection | |
if {[string length [lindex $split_text 0]] > $ns_settings(hugewords_max) && ![string match *http://* $text] && ![string match *www.* $text]} { | |
nosense:pointstorage $uhost $channel "hugewords" | |
} elseif {[string length [lindex $split_text 0]] > $ns_settings(largewords_max) && ![string match *http://* $text] && ![string match *www.* $text]} { | |
nosense:pointstorage $uhost $channel "largewords" | |
} | |
# Now we should check if the luser should be kicked. | |
if {$violated > 0} { nosense:executor $nick $uhost $channel } | |
} | |
# Stores the points and violations | |
proc nosense:pointstorage {uhost channel violation} { | |
global badpoints badviolations ns_points violated | |
if {$ns_points($violation) == 0} { return 0 } | |
set violated 1 | |
if {![info exists badpoints($uhost%$channel)]} { | |
set badpoints($uhost%$channel) $ns_points($violation) | |
} else { | |
set badpoints($uhost%$channel) [expr $badpoints($uhost%$channel) + $ns_points($violation)] | |
} | |
if {![info exists badviolations($uhost%$channel)]} { | |
set badviolations($uhost%$channel) $violation | |
} else { | |
set badviolations($uhost%$channel) "$badviolations($uhost%$channel) $violation" | |
} | |
#puthelp "privmsg $channel :$uhost er me� $badpoints($uhost%$channel) stig" | |
#puthelp "privmsg $channel :$uhost hefur broti� $badviolations($uhost%$channel)" | |
} | |
proc nosense:executor {nick uhost channel} { | |
global badpoints badviolations ns_settings | |
# If the little weasel is opped on the channel we wont do anything | |
if {[isop $nick $channel]} { return 0 } | |
# Lets trim the violations a little | |
set newviolations [nosense:trim_violations $badviolations($uhost%$channel)] | |
#puthelp "privmsg $channel :$nick hefur gerst brotlegur og honum ver�ur refsa�!" | |
if {$badpoints($uhost%$channel) >= $ns_settings(ban_on)} { | |
set banmask [maskhost [getchanhost $nick $channel]] | |
set banmask [format "*!*%s" [string range $banmask 2 [string length $banmask]]] | |
putquick "mode $channel +b $banmask" | |
putserv "kick $channel $nick :$ns_settings(banmsg) ($newviolations)" | |
putloglev 7 $channel "Banned $nick from $channel ($newviolations)" | |
} elseif {$badpoints($uhost%$channel) >= $ns_settings(kick_on)} { | |
putserv "kick $channel $nick :$ns_settings(kickmsg) ($newviolations)" | |
putloglev 7 $channel "Kicked $nick from $channel ($newviolations)" | |
} | |
} | |
proc nosense:realstring {text} { | |
global ns_nosigns | |
set text [string tolower $text] | |
foreach {svei} [array names ns_nosigns] { | |
set text [string trim $text $ns_nosigns($svei)] | |
} | |
return $text | |
} | |
proc nosense:trim_violations {text} { | |
set total 0 | |
foreach {tempkey} $text { | |
set total [expr $total + 1] | |
if {![info exists tempv($tempkey)]} { | |
set tempv($tempkey) 1 | |
} else { | |
set tempv($tempkey) [expr $tempv($tempkey) + 1] | |
} | |
} | |
foreach {temp} [array names tempv] { | |
set tempnumber $tempv($temp) | |
if {![info exists tempstring]} { | |
set tempstring $temp:$tempnumber | |
} else { | |
set tempstring "$tempstring $temp:$tempnumber" | |
} | |
} | |
set tempstring "$tempstring total:$total" | |
return $tempstring | |
} | |
proc nosense:forget {} { | |
global badpoints ns_settings badrepeat badviolations | |
foreach {akey} [array names badpoints] { | |
set split_akey [split $akey %] | |
set auhost [lindex $split_akey 0] | |
set achannel [lindex $split_akey 1] | |
set newpoints [expr $badpoints($akey) - $ns_settings(forget_count)] | |
if {$newpoints <= 0} { | |
unset badpoints($akey) | |
unset badviolations($akey) | |
foreach {rkey} [array names badrepeat] { | |
set split_rkey [split $rkey %] | |
set rnick [lindex $split_rkey 0] | |
set ruhost [lindex $split_rkey 1] | |
set rchannel [lindex $split_rkey 2] | |
if {$ruhost == $auhost && $achannel == $rchannel} { | |
#putlog "Erasing nick: $rnick uhost: $ruhost and channel $rchannel from repeat log" | |
unset badrepeat($rkey) | |
} elseif {![onchan $rnick $rchannel]} { | |
unset badrepeat($rkey) | |
} | |
} | |
} else { set badpoints($akey) $newpoints } | |
} | |
if {![string match *nosense:forget* [timers]]} { timer $ns_settings(forget_time) nosense:forget } | |
} | |
proc nosense:nslist {handle idx text} { | |
global badpoints badviolations ns_settings | |
putidx $idx ">> NoSense TCL << kick on: $ns_settings(kick_on) ban on: $ns_settings(ban_on) >>" | |
foreach {akey} [array names badpoints] { | |
if {![info exists badviolations($akey)]} { set badviolations($akey) "" } | |
putidx $idx " $akey = $badpoints($akey) ([nosense:trim_violations $badviolations($akey)])" | |
} | |
} | |
proc nosense:charcheck {text} { | |
global ns_settings | |
# return 0 - do nothing | |
# return 1 - caps | |
# return 2 - ascii | |
set splitt [split $text {}] | |
set lastchar "" | |
set noalpha 0.0 | |
set totalchars 0.0 | |
set caps 0.0 | |
set null 0.0 | |
foreach {thingy} $splitt { | |
set thingy [string trim $thingy] | |
set totalchars [expr $totalchars + 1] | |
if {$thingy == ""} { set null [expr $null + 1] } | |
if {![regexp {([a-z0-9A-Z����������������])} $thingy match] && $thingy != ""} { | |
if {$thingy == ""} { echo "bah! $thingy" } | |
#echo "$thingy matcha noalpha" | |
set noalpha [expr $noalpha + 1] | |
} | |
if {![regexp {([a-z0-9��������])} $thingy match] && $thingy != ""} { | |
#echo "$thingy matcha caps" | |
set caps [expr $caps + 1] | |
} | |
#echo "!$thingy!" | |
if {$thingy == $lastchar} { #echo "$thingy er sama og $lastchar" } | |
set lastchar $thingy | |
} | |
set totalchars [expr $totalchars - $null] | |
set noalpha_prosenta [expr int($noalpha / $totalchars * 100)] | |
set caps_prosenta [expr int($caps / $totalchars * 100)] | |
#putlog "Caps prosenta: $caps_prosenta" | |
if {$caps_prosenta >= $ns_settings(maxcaps) && $totalchars > $ns_settings(ccminline)} { return 1 } | |
} | |
proc nosense:active {channel} { | |
foreach setting [channel info $channel] { | |
if {[regexp -- {^[\+-]} $setting]} { | |
if {$setting == "+nosense"} { return 1 } | |
} | |
} | |
return 0 | |
} | |
if {![string match *nosense:forget* [timers]]} { timer $ns_settings(forget_time) nosense:forget } | |
putlog "nosense.tcl v2.01 by Merlin@IRCnet loaded" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment