Jump to content

Archived

This topic is now archived and is closed to further replies.

coders-irc_Bot

Nickname/Uhost tracker script

Recommended Posts

  • Administrators
#####
# Nickname/Uhost tracker script
# Egghelp version, donations to slennox are welcomed. :P
# Minor tweaks by PeGaSuS
#####

#####
# We need at least TCL >=8.5 due to the -nocase in lsearch
# Thanks mezen for the reminder
#####
package require Tcl 8.5


##########
# should duplicate nicknames be allowed?
##########
# 0 = no, 1 and above = yes
##########
set dupes 0

##########
# Map channels to send the message to a backchan
##########
set channelmap {
	"#amicizia" "#camelot"
	"#lolchat" "#lolstaff"
}

##########
# 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  }
	join_onjoin $newnick $uhost $hand $chan
	return 0
}

# check for joins
proc join_onjoin {nick uhost hand chan} {
	global botnick dupes channelmap
	if {![channel get $chan "nicktrack"]} {  return 0  }

	# keep everything lowercase for simplicity.
	set ch [strlwr $chan]
	set filename "[string trim "$ch" #]_nicklist.txt"
	set uhost [strlwr [maskhost [getchanhost $nick $chan] 2]]
	# 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] }

		if {[string length [join $nlist]]} {
			if {$ch in [dict keys $channelmap]} {
				set bkc [dict get $channelmap $ch]
				if {[regexp c [getchanmode $bkc]]} {
					putserv "PRIVMSG $bkc :\[$chan\] $nick ha usato: [join $nlist ", "]."
				} else {
					putserv "PRIVMSG $bkc :\00302\[$chan\]\003 \002$nick\002 ha usato: \00304[join $nlist ", "]."
				}
			} elseif {[isop $botnick $chan]} {
				if {[regexp c [getchanmode $ch]]} {
					putserv "NOTICE @$ch :$nick ha usato: [join $nlist ", "]."
				} else {
					putserv "NOTICE @$ch :\002$nick\002 ha usato: \00304[join $nlist ", "]."
				}
			} else {
				return 0
			}
		}

		set known [lsearch -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 "$nicks,$nick<$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."

 

Link to comment
Share on other sites



×
×
  • Create New...