| View previous topic :: View next topic |
| Author |
Message |
oxygen Voice
Joined: 05 Sep 2005 Posts: 22 Location: Germany
|
Posted: Mon Sep 05, 2005 5:37 pm Post subject: store nicks to a file |
|
|
Hello
I hope somebody is nice to help me with a script.
I want to store on a command in a channel like !add <team> the teamname and the nick in a file.
like:
Team1 nick1 nick2 nick3 ..
Team2 nick1 nick2 nick3 ..
Team3 nick1 nick2 nick3 ..
.
.
if the nick is already on a team return 0 , and if the team exists add his nick to the team, else create a new team.
Tnx for anybody could help.
friendly regards
oxygen |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Mon Sep 05, 2005 6:06 pm Post subject: |
|
|
| Code: |
bind pub - !add foo
bind time - ?0* bar
proc foo {n u h c t} {
set t [lindex [split $t] 0]
if {[info exists ::team($t)]} {
if {[lsearch -exact $::team($t) $n] != -1} {return}
}
lappend ::team($t) $n
puthelp "notice $n :added you to $t team"
}
proc bar {args} {
set f [open teams.txt w]
foreach {t m} [array get ::team] {
puts $f "$t: [join $m ,]"
}
close $f
}
|
|
|
| Back to top |
|
 |
oxygen Voice
Joined: 05 Sep 2005 Posts: 22 Location: Germany
|
Posted: Tue Sep 06, 2005 2:48 pm Post subject: |
|
|
Hello demond.
Tnx for our reply. It works, but....
I made a mistake the txt file should be like this:
Team1 nick1 nick2 nick3 ..
Team2 nick4 nick5 nick6 ..
Team3 nick7 nick8 nick9 ..
Maybe it explains better I post the script I wrote but dosn't work:
| Code: |
bind pub - !add team
proc team {nick uhost hand chan arg} {
global newteam newmember
set addteam [lindex [split $arg] 0]
set in [open team.txt r]
while {![eof $in]} {
set list [gets $in]
if {[lsearch -exact $list $nick] != -1} {
set team [lindex [split $list] 0]
if {$addteam==$team} {
puthelp "notice $nick :you're already on $team "
return
} else {
puthelp "notice $nick :you're already on $team and can't leave your team"
return
}
} else {
set team [lindex [split $list] 0]
set members [lrange [split $list] 1 end]
if {$addteam==$team} {
puthelp "notice $nick :added you to $team"
set newmember "$team $members $nick"
saveteam2
return
} else {
puthelp "notice $nick :you created $addteam"
set newteam "$addteam $nick"
saveteam1
return
}
}
close $in
}
}
proc saveteam1 {} {
global newteam
set fd [open team.txt a+]
puts $fd "$newteam"
close $fd
}
proc saveteam2 {} {
global newmember
set fd [open team.txt w]
puts $fd "$newmember"
close $fd
}
|
I hope you can help me with this.
friendly regards
oxygen |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Tue Sep 06, 2005 2:54 pm Post subject: |
|
|
then replace:
| Code: |
puts $f "$t: [join $m ,]"
|
with:
| Code: |
puts $f "$t [join $m]"
|
|
|
| Back to top |
|
 |
oxygen Voice
Joined: 05 Sep 2005 Posts: 22 Location: Germany
|
Posted: Wed Sep 07, 2005 3:46 pm Post subject: |
|
|
Hello demond.
Sorry, but it isn't what I'm lookin' for. I feel bad to wast your time...
What I need is a script that reads the teams and nicks from a file, and when the nick is on any team to return 0. If the nick is not in the file, then it should check if arg is a team in the file, and if it is to add the nick to te team. Else creat a new team. And store all in the file again.
Something like I posted earlyer. I tryed several ways but couldn't make it work.
Hope anybody can help.
friendly regards
oxygen |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Wed Sep 07, 2005 3:59 pm Post subject: |
|
|
you didn't say anything about reading from file in your initial request, you only required storing - and now is kind of late for that I don't feel like constantly satisfying ever changing requirements anymore; but maybe some kind soul will do that for you, it's fairly easy |
|
| Back to top |
|
 |
oxygen Voice
Joined: 05 Sep 2005 Posts: 22 Location: Germany
|
Posted: Wed Sep 07, 2005 4:09 pm Post subject: |
|
|
No problem demond
You say it's easy? I try for over a week to do this
Seems I'm to lame for .tcl
Tnx anyway I appreciate your help.
Hope some "soul" will help.
friendly regards
oxygen |
|
| Back to top |
|
 |
demond Revered One

Joined: 12 Jun 2004 Posts: 3073 Location: San Francisco, CA
|
Posted: Wed Sep 07, 2005 4:30 pm Post subject: |
|
|
oh well, here it is with reading:
| Code: |
set tfile teams.txt
bind pub - !add foo
bind time - ?0* bar
if {![catch {set f [open $tfile]}]} {
foreach e [split [read $f] \n] {
set t [lindex [split $e] 0]; if {$t == ""} continue
set team($t) [lrange [split $e] 1 e]
}
close $f
}
proc foo {n u h c t} {
set t [lindex [split $t] 0]
if {[info exists ::team($t)]} {
if {[lsearch -exact $::team($t) $n] != -1} {return}
}
lappend ::team($t) $n
puthelp "notice $n :added you to $t team"
}
proc bar {args} {
set f [open $::tfile w]
foreach {t m} [array get ::team] {
puts $f "$t [join $m]"
}
close $f
}
|
|
|
| Back to top |
|
 |
minted Halfop
Joined: 20 Jul 2005 Posts: 64
|
Posted: Thu Sep 08, 2005 1:36 am Post subject: |
|
|
| lol! he was so polite u couldnt resist |
|
| Back to top |
|
 |
oxygen Voice
Joined: 05 Sep 2005 Posts: 22 Location: Germany
|
Posted: Thu Sep 08, 2005 4:26 am Post subject: |
|
|
Tnx demond
You're a nice guy
@minted
yepp, i'm a old man and always polite
friendly regards
oxygen |
|
| Back to top |
|
 |
|