| View previous topic :: View next topic |
| Author |
Message |
Rapfnny Voice
Joined: 16 May 2009 Posts: 8 Location: irc.Bob-Omb.net
|
Posted: Thu May 21, 2009 2:02 pm Post subject: Trap Bot: delete word on file |
|
|
Never mind I decided to finish it. Here's what i need help on next:
I decided to make it go by nicks. I wan't the nick to be removed from nicklog.db if it is kicked from the channel heres my current code which isn't working.
| Code: |
bind kick - "#DontJoinItsATrap" unlog
proc unlog {nick uhost hand chan reason} {
set input [open nicklog.db]
set output [open nicklog.tmp w]
while {[gets $input line] >= 0} { if {[lsearch $line [string tolower $nick]] < 0} { puts $output $line } }
close $input
close $output
file rename -force nicklog.tmp nicklog.db
putserv "NOTICE $nick You have escaped ^_^"
} |
It doesnt do anything at all when i kick someone. _________________ Bob-Omb
Last edited by Rapfnny on Sat May 23, 2009 10:35 pm; edited 3 times in total |
|
| Back to top |
|
 |
tomekk Master

Joined: 28 Nov 2008 Posts: 255 Location: Oswiecim / Poland
|
Posted: Thu May 21, 2009 2:09 pm Post subject: Re: Trap Bot: error with # of args |
|
|
| Rapfnny wrote: | Here's my script:
| Quote: | [13:53] Tcl error [userip]: wrong # args: should be "userip nick uhost hand channel txt"
|
When its already there. >:\ What can I do to fix this? |
from tcl-commands.txt:
| Quote: | ( JOIN (stackable)
bind join <flags> <mask> <proc>
procname <nick> <user@host> <handle> <channel>
Description: triggered by someone joining the channel. The mask in
the bind is matched against "#channel nick!user@host" and can
contain wildcards.
Module: irc
|
change
| Code: | | proc userip { nick uhost hand channel txt } { |
to
| Code: | | proc userip { nick uhost hand channel } { |
 |
|
| Back to top |
|
 |
Rapfnny Voice
Joined: 16 May 2009 Posts: 8 Location: irc.Bob-Omb.net
|
Posted: Thu May 21, 2009 2:47 pm Post subject: Another Issue |
|
|
Thanks! I edited the script and it works fine now. Here's the next thing i need help with.
| Code: |
proc logip {ip} {
set file [open iplog.txt a+]
if {$ip != "0.0.0.0"} {
puts $file "$ip"
}
close $file
} |
But I would like to know how I can make it search if $ip exists in the file, and if it does, it doesnt write $ip to the file twice. _________________ Bob-Omb |
|
| Back to top |
|
 |
Papillon Owner

Joined: 15 Feb 2002 Posts: 724 Location: *.no
|
Posted: Thu May 21, 2009 5:19 pm Post subject: |
|
|
try something like this
| Code: | proc logip {ip} {
set file [open iplog.txt a+]
set info [split [read $file] \n]]
if {$ip != "0.0.0.0" && [string equal [lsearch -exact $info $ip] "-1"]} {
puts $file "$ip"
}
close $file
} |
_________________ Elen sila lúmenn' omentielvo |
|
| Back to top |
|
 |
tomekk Master

Joined: 28 Nov 2008 Posts: 255 Location: Oswiecim / Poland
|
Posted: Thu May 21, 2009 5:29 pm Post subject: |
|
|
try:
| Code: | proc logip {ip} {
if {$ip == "0.0.0.0"} {
return
}
set db_get [open iplog.txt r]
set all_ips [split [read $db_get] "\n"]
close $db_get
if {[lsearch $all_ips $ip] != -1} {
return
}
set file [open iplog.txt a+]
puts $file "$ip"
close $file
}
|
or, if want with "a+" without extra file reading:
| Code: | proc logip {ip} {
if {$ip == "0.0.0.0"} {
return
}
set file [open iplog.txt a+]
seek $file 0
set all_ips [split [read $file] "\n"]
if {[lsearch $all_ips $ip] != -1} {
close $file
return
}
seek $file 0 end
puts $file "$ip"
close $file
}
|
|
|
| Back to top |
|
 |
|