This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Help with a scriptlet im working on. Writing masks to file

Old posts that have not been replied to for several years.
Locked
User avatar
Aron
Halfop
Posts: 86
Joined: Sat Mar 15, 2003 8:35 am

Help with a scriptlet im working on. Writing masks to file

Post by Aron »

Im working on a script that will check a nick's hostmask on join, and if it doesnt match one of the hostmasks for that nick, it will add it.
When i rejoin the channel, i get the following error message:

I want it to write to a text file, in the form of "Nick host1 host2 host3 etc".
With my basic knowledge of tcl, i thought one way to do this, was to set all the info in a a list, then write it. Any suggestions are welcome ;)

Code: Select all

[00:18] Tcl error [join:hostcheck]: can not find channel named "file17"
This is my code:

Code: Select all

set hostfile "/home/asoaron/devbot/scripts/hosts/hosts.dat"

bind join - * join:hostcheck

proc join:hostcheck {nick host hand chan} {
 global hostfile botnick
  set found 0 
  set fs [open $hostfile r] 
  while {![eof $fs]} { 
   gets $fs line 
   if {[lrange $line 1 end] == $host} { set found 1 } 
   close $fs    
 } 
 if {$found} { 
  return 0
 } 
  else { 
   if {[lindex $line 0] == $nick} {
    set lijst  [split $line] 
    set lijst2 [lappend $lijst $host]
    set fs [open $hostfile w] 
    puts $fs "$lijst2" 
    close $fs 
   } 
  }
}

Thanks in advance.
The best way to start learning is to start helping.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

The problem is your use of "close". Also your while loop is bad -- try searching on the forum for how to properly read in a file.
User avatar
Aron
Halfop
Posts: 86
Joined: Sat Mar 15, 2003 8:35 am

Post by Aron »

Could you be a bit more specific? I already saw some other topics, but i really dont know what im doing wrong... :(
The best way to start learning is to start helping.
User avatar
Aron
Halfop
Posts: 86
Joined: Sat Mar 15, 2003 8:35 am

Hours of scripting later

Post by Aron »

Alright, ive got a large part of the script finished now.

But now i've got another problem..

When writing the person's nick to a dat file, it adds { }'s in the nick, if it contains [ ] 's..

Is there any way to solve this?
The best way to start learning is to start helping.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

split and lappend operate on lists. you didn't use 'join' to turn it into a normal string before writing to the file.

also you use 'lrange' (again without 'join') in the first loop without first splitting the line.
Locked