From a53af90d9793589e594c9591c14b9ee1221c9cbc Mon Sep 17 00:00:00 2001 From: Teh PeGaSuS Date: Tue, 3 Mar 2026 22:41:51 +0100 Subject: [PATCH] Add NickTracker/nicktracker.tcl --- NickTracker/nicktracker.tcl | 185 ++++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 NickTracker/nicktracker.tcl diff --git a/NickTracker/nicktracker.tcl b/NickTracker/nicktracker.tcl new file mode 100644 index 0000000..21941d6 --- /dev/null +++ b/NickTracker/nicktracker.tcl @@ -0,0 +1,185 @@ +##### +# Nickname/Uhost tracker script +# Egghelp version, donations to slennox are welcomed. :P +# Original version from speechles (?) +# Enchanced by PeGaSuS +##### + +##### +# We need at least TCL >=8.5 due to the -nocase in lsearch +# Thanks mezen for the reminder +##### +if {[catch {package require Tcl 8.5} err]} { + putlog "ERROR: Tcl 8.5 or newer is required — unloading script." + return +} + +########## +# should duplicate nicknames be allowed? +########## +# 0 = no, 1 and above = yes +########## +set dupes 0 + +########## +# How many nicks to show? +# To avoid messages being cut off, this is hard limited to 10 +########## +set list_length "10" + + +########## +# Send nicktracking information to the specified channel(s)/nickname(s). You can set several destinations +# Example +# set channelmap { +# "#channel1" "#channel2" +# "#otherchannel" "#channel3 #channel4 somenick" +# } +# +########## +set channelmap { + "#thelounge" "#thelounge-staff" +} + +########## +# Nicks to alert in case the channel doesn't have a backchan or there's no +# channel -> backchan mapping +########## +set alertnicks { + "NullPointer" +} + +########## +# Binds +########## +#bind nick - * nick_nickchange +bind join - * join_onjoin +########## +# End of binds +########## + +########## +# Channel flag +########## +setudef flag nicktrack + +########## +# Procs +########## + +########## +# check for nick changes +########## +proc nick_nickchange {nick uhost hand chan newnick} { + if {![channel get $chan "nicktrack"]} { + return 0 + } + + if {$nick eq "$::botnick"} { + return 0 + } + + join_onjoin $newnick $uhost $hand $chan + return 0 +} + +########## +# check for joins +########## +proc join_onjoin {nick uhost hand chan} { + global botnick dupes channelmap list_length alertnicks + if {![channel get $chan "nicktrack"]} { + return 0 + } + + if {$nick eq "$::botnick"} { + return 0 + } + + # keep everything lowercase for simplicity. + set ch [strlwr $chan] + set filename "[string trim $ch #]_nicklist.txt" + set uhost [strlwr $uhost] + + # read the file + if {![file exists $filename]} { + set file [open $filename "w"] + close $file + } + + set file [open $filename "r"] + set text [split [read $file] \n] + close $file + # locate a duplicate host + set found [lsearch -glob $text "*<$uhost"] + if {$found < 0} { + # host isn't found so let's append the nick and host to our file + set file [open $filename "a"] + puts $file "$nick<$uhost" + close $file + } else { + # the host exists, so set our list of nicks for that host + set nicks [lindex [split [lindex $text $found] "<"] 0] + # is the nick already known for that host? + set nlist [split $nicks ","] + if {[set pos [lsearch -nocase $nlist $nick]] != -1} { set nlist [lreplace $nlist $pos $pos] } + # calculate the list length, as we're going to use it later + if {$list_length > 10} { set list_length 10 } + set offset [expr {$list_length - 1}] + + # Send messages to the defined channels + if {$ch in [dict keys $channelmap]} { + set bkc [dict get $channelmap $ch] + foreach bkct [split $bkc] { + for {set i 0} {$i < [llength $nlist]} {incr i $list_length} { + if {[regexp {\+[^ ]*c} [getchanmode $bkct]]} { + putquick "PRIVMSG $bkct :\[$chan\] ${nick} also used: [join [lrange $nlist $i $i+$offset] { }]" + } else { + putquick "PRIVMSG $bkct :\[\00302$chan\003\] \00304${nick}\003 also used: \00304[join [lrange $nlist $i $i+$offset] { }]\003" + } + } + } + } else { + # Send a notice to channel operators if bot is chanop + if {[isop $botnick $ch]} { + for {set i 0} {$i < [llength $nlist]} {incr i $list_length} { + if {[regexp {\+[^ ]*c} [getchanmode $ch]]} { + putquick "NOTICE @$ch :${nick} also used: [join [lrange $nlist $i $i+$offset] { }]" + } else { + putquick "NOTICE @$ch :\00304${nick}\003 ha usato: \00304[join [lrange $nlist $i $i+$offset] { }]\003" + } + } + } else { + # Send a message to the nicks on the list if none of the conditions above is met + foreach n [split $alertnicks] { + for {set i 0} {$i < [llength $nlist]} {incr i $list_length} { + putquick "PRIVMSG $n :\[\00302$chan\003\] \00304${nick}\003 ha usato: \00304[join [lrange $nlist $i $i+$offset] { }]\003" + } + } + } + } + + # To make it output to partyline remove the # the begins the line below. + #if {[string length [join $nlist]]} { putloglev d * "*** $nick on $chan is also known as :[join $nlist ", "]." } + + set known [lsearch -exact -nocase [split $nicks ","] $nick] + if {($known != -1) && ($dupes < 1)} { + # if the nick is known return + return + } else { + # otherwise add the nick to the nicks for that host + set text [lreplace $text $found $found "$nick,$nicks<$uhost"] + } + # now lets write the new list to the file + set file [open $filename "w"] + foreach line $text { + if {[string length $line]} { + puts $file "$line" + } + } + close $file + } + return 0 +} + +putlog "Nickname/Uhost tracker enabled."