| View previous topic :: View next topic |
| Author |
Message |
hakim Voice
Joined: 23 Apr 2006 Posts: 19
|
Posted: Sat May 20, 2006 10:53 am Post subject: [No]greet |
|
|
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:
| Code: | #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
} |
|
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Sat May 20, 2006 7:12 pm Post subject: |
|
|
| hakim wrote: | | but there is something wrong with the script |
Not very informative! Post the results of (via Command Console):
Also post any other relevant information (errors in logs &c). _________________ Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM |
|
| Back to top |
|
 |
hakim Voice
Joined: 23 Apr 2006 Posts: 19
|
Posted: Sun May 21, 2006 10:10 am Post subject: |
|
|
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):
| Code: | 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
} |
Error message executing nogreet:
| Code: | 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"
|
nogreet proc:
| Code: | bind msg * !nogreet nogreet
proc nogreet { nick host hand text } {
set dbfs [open host.db r]
set tmpfs [open host.tmp w]
while {![eof $dbfs]} {
if {![gets $dbfs line]} {
puts $tmpfs "$line"
} elseif {[[lindex $line 0] == $host]} {
putserv "NOTICE Owner :Nogreet is on. Type !greet to greet again."
} else {
puts $tmpfs "$host"
putserv "NOTICE Owner :turned on nogreet."
}
}
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
} |
|
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sun May 21, 2006 5:07 pm Post subject: |
|
|
| Code: | | elseif {[[lindex $line 0] == $host]} |
Look closely into the comparison, is it correct in your opinion? Are the extra brackets needed? It's usually done like this:
| Code: | | if {$bla == $blo} { |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
hakim Voice
Joined: 23 Apr 2006 Posts: 19
|
Posted: Mon May 22, 2006 10:26 am Post subject: |
|
|
Tahnks, Sir_Fz. Well, we live and learn
So, here is the completely working script:
| Code: | 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  |
|
| Back to top |
|
 |
|