Code: Select all
set nicklista "nicks.txt"
bind join - * join_onjoin
proc join_onjoin {nick uhost hand chan} {
global nicklista
set filename $nicklista
set txt [open $filename "a"]
puts $txt "$nick $uhost"
close $txt
}
Code: Select all
set nicklista "nicks.txt"
bind join - * join_onjoin
proc join_onjoin {nick uhost hand chan} {
global nicklista
set filename $nicklista
set txt [open $filename "a"]
puts $txt "$nick $uhost"
close $txt
}
Code: Select all
#read data from file
set fp [open $nicklista r]
set data [read -nonewline $fp]
close $fp
set datalist [split $data "\n"]
#if nick is already present in list, halt
foreach user $datalist {
if {[string equal -nocase "[lindex [split $user] 0]" $nick]} {
return 0
}
}
#check if uhost is present in list
foreach host $datalist {
if {[string equal -nocase "[lindex [split $host] 1]" $uhost]} {
set host:found 1; break
}
}
#if uhost present in list delete that line write the new nick and uhost to file
if {[info exists host:found]} {
set user "$nick $host"
set i [lsearch -exact [split [string tolower $datalist]] [split $user]]
set datalist [lsort -unique [lreplace $datalist $i $i]]
set fp [open $nicklista w]
puts $fp [join $nicklista "\n"]
close $fp
}
Code: Select all
#if uhost present in list delete that line write the new nick and uhost to file
if {[info exists host:found]} {
set user "$nick $host"
set i [lsearch -exact [split [string tolower $datalist]] [split $user]]
set datalist [lsort -unique [lreplace $datalist $i $i]]
set fp [open $nicklista w]
puts $fp [join $nicklista "\n"]
close $fp
}
Code: Select all
#if nick is already present in list, halt
foreach user $datalist {
if {[string equal -nocase "[lindex [split $user] 0]" $nick]} {
return 0
}
}
#check if uhost is present in list
foreach host $datalist {
if {[string equal -nocase "[lindex [split $host] 1]" $uhost]} {
set host:found 1; break
}
}
nick:$uhost
nick1,nick2:$uhost
nick1,nick2,nick3:$uhost
Code: Select all
#If suppose $data is the total data in the file then read the data as a list
#and you can get the nicks and uhosts by:
set nicklist [list]
foreach entry $data {
lappend nicklist [lindex [split $entry :] 0]
}
set uhostlist [list]
foreach entry $data {
lappend uhostlist [lindex [split $entry :] 1]
}
#Then you check if the nick is not already in the list
#if nick is already present in list, halt
foreach user $nicklist {
if {[string match -nocase "*$user*" $nick]} {
set nickfound 1; break
}
}
if {![info exists nickfound]} {
return 0
#find the entry in the nicklist and uhostlist
} else {
set findnick [lsearch -glob [split [string tolower $nicklist]] *$nick*]
set finduhost [lsearch -glob [split [string tolower $uhostlist]] *uhost*]
}
#if everything is ok, then proceed
if {$findnick == $finduhost} {
#
#then you can use lreplace to replace the entry however you want
#