egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Trap Bot: delete word on file

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Rapfnny
Voice


Joined: 16 May 2009
Posts: 8
Location: irc.Bob-Omb.net

PostPosted: Thu May 21, 2009 2:02 pm    Post subject: Trap Bot: delete word on file Reply with quote

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
View user's profile Send private message Visit poster's website
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Thu May 21, 2009 2:09 pm    Post subject: Re: Trap Bot: error with # of args Reply with quote

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. >:\ Shocked What can I do to fix this?


from tcl-commands.txt:
Quote:
(Cool 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 } {


Wink
Back to top
View user's profile Send private message Visit poster's website
Rapfnny
Voice


Joined: 16 May 2009
Posts: 8
Location: irc.Bob-Omb.net

PostPosted: Thu May 21, 2009 2:47 pm    Post subject: Another Issue Reply with quote

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
View user's profile Send private message Visit poster's website
Papillon
Owner


Joined: 15 Feb 2002
Posts: 724
Location: *.no

PostPosted: Thu May 21, 2009 5:19 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Thu May 21, 2009 5:29 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber