| View previous topic :: View next topic |
| Author |
Message |
Nivko Voice
Joined: 15 Nov 2005 Posts: 22 Location: The Netherlands, Helmond
|
Posted: Sun May 07, 2006 7:24 am Post subject: Writing to a TXT |
|
|
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. |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
|
| Back to top |
|
 |
Nivko Voice
Joined: 15 Nov 2005 Posts: 22 Location: The Netherlands, Helmond
|
Posted: Sun May 07, 2006 8:28 am Post subject: |
|
|
| Ok, i find the write section but not the remove (For removing the line's) |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sun May 07, 2006 8:54 am Post subject: |
|
|
Paste what you've written so far and we will help you finish it. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
Nivko Voice
Joined: 15 Nov 2005 Posts: 22 Location: The Netherlands, Helmond
|
Posted: Sun May 07, 2006 9:19 am Post subject: |
|
|
| Code: | bind join - * join_onjoin
proc join_onjoin {nick uhost hand chan} {
set txt [open "online.txt"]
puts $txt "$nick"
} |
|
|
| Back to top |
|
 |
KrzychuG Master

Joined: 16 Aug 2003 Posts: 306 Location: Torun, Poland
|
Posted: Sun May 07, 2006 9:47 am Post subject: |
|
|
| Code: |
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? |
|
| Back to top |
|
 |
Nivko Voice
Joined: 15 Nov 2005 Posts: 22 Location: The Netherlands, Helmond
|
Posted: Sun May 07, 2006 9:49 am Post subject: |
|
|
Ok, thanks that is the first part of the script
Now how remove the line if somone parts  |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Sun May 07, 2006 10:26 am Post subject: |
|
|
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... |
|
| Back to top |
|
 |
Nivko Voice
Joined: 15 Nov 2005 Posts: 22 Location: The Netherlands, Helmond
|
Posted: Sun May 07, 2006 10:29 am Post subject: |
|
|
| Uhm, i cant script TCL... Could you make it for me.. |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sun May 07, 2006 11:22 am Post subject: |
|
|
| Code: | 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. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
Nivko Voice
Joined: 15 Nov 2005 Posts: 22 Location: The Netherlands, Helmond
|
Posted: Sun May 07, 2006 11:24 am Post subject: |
|
|
| Sorry, but i need live if somone parts he must write and joins too:$ |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sun May 07, 2006 11:26 am Post subject: |
|
|
Well, what you're requesting is not recommended. If you want it to save immediately, you know what to fix. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
Nivko Voice
Joined: 15 Nov 2005 Posts: 22 Location: The Netherlands, Helmond
|
Posted: Sun May 07, 2006 11:29 am Post subject: |
|
|
Why it isnt recommed? BTW is this good without timer?:
| Code: | 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] |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sun May 07, 2006 11:38 am Post subject: |
|
|
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: | 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
}
} |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
Nivko Voice
Joined: 15 Nov 2005 Posts: 22 Location: The Netherlands, Helmond
|
Posted: Sun May 07, 2006 11:47 am Post subject: |
|
|
So this:
| Code: | 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 |
|
| Back to top |
|
 |
|