The script should send notice "greet" to the owner if his hostname is not in the host.db, send "no greet" if it's there, add the hostname to the db, when user msgs "!nogreet" to the bot and remove it from there if he msgs "!greet", but there is something wrong with the script Any help appreciated.
So here is the script:
#setting channels which will be effected
set channel(one) "#channel"
#sends "greet/nogreet" to owner when he joins the channel
bind join n *!*@* greetuser
proc greetuser {nick uhost hand chan arg } {
#only if in effected channel
if {$chan==$channel(one)} {
#creates host.db if it doesn't exist
if {![file exists host.db]} {
set fs [open host.db w]
puts $fs ""
close $fs
}
set dbfs [open host.db r]
set tmpfs [open host.tmp w]
set match 0
#creates variable userhost, which will be the user host
set userhost [getchanhost $nick $chan]
global userhost
#searches the file for userhost
while {![eof $dbfs]} {
if {![gets $dbfs line]} {
puts $tmpfs "$line"
} elseif {[lindex $line 0] == $userhost} {
set match 1
}
}
#if there is no entry, sends "greet"
if {![match==1]} {
puthelp "NOTICE Owner :greet"
#otherwise nogreet
} elseif {[match==1]} {
puthelp "NOTICE Owner :nogreet"
}
}
return 0
}
#adds userhost to host.db if user msgs "!nogreet" to bot
bind msg * !nogreet nogreet
proc nogreet { nick uhost hand text arg } {
#looks if it's not there already
while {![eof $dbfs]} {
if {![gets $dbfs line]} {
puts $tmpfs "$line"
} elseif {[[lindex $line 0] == $userhost]} {
}
else {
puts $tmpfs "$userhost"
}
}
#writes to host.db
close $dbfs
close $tmpfs
set fs [open host.db.tmp r]
set hostsdb "[read $fs]"
close $fs
set fs [open host.db w]
puts $fs "$hostsdb"
close $fs
return 0
}
#removes hostname from db, if user msgs "!greet" to bot
bind msg * !greet greet
proc greet { nick uhost hand text arg } {
set dbfs [open host.db r]
set tmpfs [open host.db.tmp w]
#finds and removes entry from db
while {![eof $dbfs]} {
if {![gets $dbfs line]} {
puts $tmpfs "$line"
} elseif {[lindex $line 0] == $userhost} {
puts $tmpfs ""
puthelp "NOTICE Owner :greeting again!"
}
}
close $dbfs
close $tmpfs
set fs [open host.db.tmp r]
set hostsdb "[read $fs]"
close $fs
set fs [open host.db w]
puts $fs "$hostsdb"
close $fs
return 0
}
The script is very buggy
I think I corrected greetuser proc, but I still can't figure out what's wrong with nogreet proc
Corrected greet user (also changed userhost with host. wich is acquired automatically):
set channel(one) "#channel"
bind join n|- *!*@* greetuser
proc greetuser { nick host hand chan } {
global channel
if {$chan==$channel(one)} {
if {![file exists host.db]} {
set fs [open host.db w]
puts $fs ""
close $fs
}
set dbfs [open host.db r]
set tmpfs [open host.tmp w]
global match
set match 0
while {![eof $dbfs]} {
if {![gets $dbfs line]} {
puts $tmpfs "$line"
} elseif {[lindex $line 0] == $host} {
set match 1
}
}
if {!$match} {
puthelp "NOTICE Owner :greet"
} elseif {[match==1]} {
puthelp "NOTICE Owner :nogreet"
}
}
close $dbfs
close $tmpfs
return 0
}
Tcl error [nogreet]: invalid command name ""
invalid command name ""
while executing
"[lindex $line 0] == $host"
(procedure "nogreet" line 9)
invoked from within
"nogreet $_msg1 $_msg2 $_msg3 $_msg4"
set channel(one) "#channel_name"
if {![file exists host.db]} {
set fs [open host.db w]
puts $fs ""
close $fs
}
bind join n|- *!*@* greetuser
proc greetuser { nick host hand chan } {
global channel
if {$chan==$channel(one)} {
set dbfs [open host.db r]
global match
set match 0
while {![eof $dbfs]} {
gets $dbfs line
if {[lindex $line 0] == $host} {
set match 1
}
}
if {!$match} {
puthelp "NOTICE owners_nick :greet"
} elseif {$match} {
puthelp "NOTICE owners_nick :nogreet"
}
}
close $dbfs
return 0
}
bind msg * !nogreet nogreet
proc nogreet { nick host hand text } {
set dbfs [open host.db r]
set tmpfs [open host.db.tmp w]
while {![eof $dbfs]} {
if {![gets $dbfs line]} {
puts $tmpfs "$line"
} elseif {[lindex $line 0] == $host} {
puthelp "NOTICE owners_nick :Nogreet is on. Type !greet to greet again."
} else {
puts $tmpfs "$host"
}
}
close $dbfs
close $tmpfs
set fs [open host.db.tmp r]
set hostsdb "[read $fs]"
close $fs
set fs [open host.db w]
puts $fs "$hostsdb"
close $fs
return 0
}
bind msg * !greet greet
proc greet { nick host hand text } {
set dbfs [open host.db r]
set tmpfs [open host.db.tmp w]
while {![eof $dbfs]} {
if {![gets $dbfs line]} {
puts $tmpfs "$line"
} elseif {[lindex $line 0] == $host} {
puts $tmpfs ""
puthelp "NOTICE Owners_nick :greeting again!"
}
}
close $dbfs
close $tmpfs
set fs [open host.db.tmp r]
set hostsdb "[read $fs]"
close $fs
set fs [open host.db w]
puts $fs "$hostsdb"
close $fs
return 0
}
Bind for greet_user proc can be changed to "bind join - *!*@* greetuser", "Owners_nick" to "$nick", "channel_name" to prefered channel and should work just fine for everyone