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.

Writing to a TXT

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
N
Nivko
Voice
Posts: 22
Joined: Tue Nov 15, 2005 8:49 am
Location: The Netherlands, Helmond
Contact:

Writing to a TXT

Post by Nivko »

Hi,

Can somone help me with this script:

If people join the channel #blaat the bot must write the nickname to a .txt , if the people leaves #blaat he must he delete the people's name from the .txt.


Thanks.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Search the forum for 'write txt', you'll get a lot of usefull topics.
N
Nivko
Voice
Posts: 22
Joined: Tue Nov 15, 2005 8:49 am
Location: The Netherlands, Helmond
Contact:

Post by Nivko »

Ok, i find the write section but not the remove (For removing the line's)
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Paste what you've written so far and we will help you finish it.
N
Nivko
Voice
Posts: 22
Joined: Tue Nov 15, 2005 8:49 am
Location: The Netherlands, Helmond
Contact:

Post by Nivko »

Code: Select all

bind join - * join_onjoin

proc join_onjoin {nick uhost hand chan} {
set txt [open "online.txt"] 
   puts $txt "$nick"
}
User avatar
KrzychuG
Master
Posts: 306
Joined: Sat Aug 16, 2003 2:51 pm
Location: Torun, Poland
Contact:

Post by KrzychuG »

Code: Select all

bind join - * join_onjoin 

proc join_onjoin {nick uhost hand chan} { 
  set txt [open "online.txt"] 
  puts $txt "$nick" 
  close $txt ;# it's important to close the file!
}
;P
Que?
N
Nivko
Voice
Posts: 22
Joined: Tue Nov 15, 2005 8:49 am
Location: The Netherlands, Helmond
Contact:

Post by Nivko »

Ok, thanks that is the first part of the script 8)

Now how remove the line if somone parts :x
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

best you save the nicks as a list. and lsearch/lreplace the nick (or lappend in case to add one).
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
N
Nivko
Voice
Posts: 22
Joined: Tue Nov 15, 2005 8:49 am
Location: The Netherlands, Helmond
Contact:

Post by Nivko »

Uhm, i cant script TCL... Could you make it for me..
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

bind time - ?0* savelist
bind join - * addtolist
bind part - * remfromlist
bind sign - * remfromlist

if {![file exists online.txt]} { close [open online.txt w] }
set nicklist [split [read [set oltxt [open online.txt]]] \n][close $oltxt]

proc savelist args {
 set file [open online.txt w]
 foreach n $::nicklist {
  if {$n != ""} { puts $file $n }
 }
 close $file
}

proc addtolist {nick uhost hand chan} {
 global nicklist
 set nick [string tolower $nick]
 if {[lsearch -exact $nicklist $nick] == -1} {
  lappend nicklist $nick
 }
}

proc remfromlist {nick uhost hand chan rsn} {
 global nicklist
 set nick [string tolower $nick]
 if {[set i [lsearch -exact $nicklist $nick]] != -1} {
  set nicklist [lreplace $nicklist $i $i]
 }
}
This will add the nicks on join to the list and will remove the nicks from the list on part/quit. The list will be saved every 10 minutes into the file.
N
Nivko
Voice
Posts: 22
Joined: Tue Nov 15, 2005 8:49 am
Location: The Netherlands, Helmond
Contact:

Post by Nivko »

Sorry, but i need live if somone parts he must write and joins too:$
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Well, what you're requesting is not recommended. If you want it to save immediately, you know what to fix.
N
Nivko
Voice
Posts: 22
Joined: Tue Nov 15, 2005 8:49 am
Location: The Netherlands, Helmond
Contact:

Post by Nivko »

Why it isnt recommed? BTW is this good without timer?:

Code: Select all

bind join - * addtolist 
bind part - * remfromlist 
bind sign - * remfromlist 

if {![file exists online.txt]} { close [open online.txt w] } 
set nicklist [split [read [set oltxt [open online.txt]]] \n][close $oltxt] 

proc savelist args { 
 set file [open online.txt w] 
 foreach n $::nicklist { 
  if {$n != ""} { puts $file $n } 
 } 
 close $file 
} 

proc addtolist {nick uhost hand chan} { 
 global nicklist 
 set nick [string tolower $nick] 
 if {[lsearch -exact $nicklist $nick] == -1} { 
  lappend nicklist $nick 
 } 
} 

proc remfromlist {nick uhost hand chan rsn} { 
 global nicklist 
 set nick [string tolower $nick] 
 if {[set i [lsearch -exact $nicklist $nick]] != -1} { 
  set nicklist [lreplace $nicklist $i $i] 
 } 
}
[/code]
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

It's not recommended because it becomes CPU intensive to open and close the file everytime someone joins/parts/quits especially on mass events. Your code is alright, you only need to change these procs:

Code: Select all

proc addtolist {nick uhost hand chan} {
 global nicklist
 set nick [string tolower $nick]
 if {[lsearch -exact $nicklist $nick] == -1} {
  lappend nicklist $nick
  savelist
 }
}

proc remfromlist {nick uhost hand chan rsn} {
 global nicklist
 set nick [string tolower $nick]
 if {[set i [lsearch -exact $nicklist $nick]] != -1} {
  set nicklist [lreplace $nicklist $i $i]
  savelist
 }
}
N
Nivko
Voice
Posts: 22
Joined: Tue Nov 15, 2005 8:49 am
Location: The Netherlands, Helmond
Contact:

Post by Nivko »

So this:

Code: Select all

proc addtolist {nick uhost hand chan} { 
 global nicklist 
 set nick [string tolower $nick] 
 if {[lsearch -exact $nicklist $nick] == -1} { 
  lappend nicklist $nick 
  savelist 
 } 
} 

proc remfromlist {nick uhost hand chan rsn} { 
 global nicklist 
 set nick [string tolower $nick] 
 if {[set i [lsearch -exact $nicklist $nick]] != -1} { 
  set nicklist [lreplace $nicklist $i $i] 
  savelist 
 } 
}
proc savelist args { 
 set file [open online.txt w] 
 foreach n $::nicklist { 
  if {$n != ""} { puts $file $n } 
 } 
 close $file 
} 
I gonna this it and else i use your way
Post Reply