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.

store nicks to a file

Old posts that have not been replied to for several years.
Locked
o
oxygen
Voice
Posts: 22
Joined: Mon Sep 05, 2005 2:22 pm
Location: Germany

store nicks to a file

Post by oxygen »

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
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

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
}
o
oxygen
Voice
Posts: 22
Joined: Mon Sep 05, 2005 2:22 pm
Location: Germany

Post by oxygen »

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: Select all

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
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

then replace:

Code: Select all

puts $f "$t: [join $m ,]" 
with:

Code: Select all

puts $f "$t [join $m]" 
o
oxygen
Voice
Posts: 22
Joined: Mon Sep 05, 2005 2:22 pm
Location: Germany

Post by oxygen »

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
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

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
o
oxygen
Voice
Posts: 22
Joined: Mon Sep 05, 2005 2:22 pm
Location: Germany

Post by oxygen »

No problem demond ;)

You say it's easy? I try for over a week to do this :(
Seems I'm to lame for .tcl :shock:
Tnx anyway :D I appreciate your help.
Hope some "soul" will help.

friendly regards
oxygen
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

oh well, here it is with reading:

Code: Select all

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
} 
m
minted
Halfop
Posts: 64
Joined: Wed Jul 20, 2005 9:58 am

Post by minted »

lol! he was so polite u couldnt resist
o
oxygen
Voice
Posts: 22
Joined: Mon Sep 05, 2005 2:22 pm
Location: Germany

Post by oxygen »

Tnx demond

You're a nice guy :)

@minted
yepp, i'm a old man and always polite :wink:

friendly regards
oxygen
Locked