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
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
}
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
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.
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
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
}