egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

store nicks to a file

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive
View previous topic :: View next topic  
Author Message
oxygen
Voice


Joined: 05 Sep 2005
Posts: 22
Location: Germany

PostPosted: Mon Sep 05, 2005 5:37 pm    Post subject: store nicks to a file Reply with quote

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
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Mon Sep 05, 2005 6:06 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
oxygen
Voice


Joined: 05 Sep 2005
Posts: 22
Location: Germany

PostPosted: Tue Sep 06, 2005 2:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Tue Sep 06, 2005 2:54 pm    Post subject: Reply with quote

then replace:
Code:

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

with:
Code:

puts $f "$t [join $m]"
Back to top
View user's profile Send private message Visit poster's website
oxygen
Voice


Joined: 05 Sep 2005
Posts: 22
Location: Germany

PostPosted: Wed Sep 07, 2005 3:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Wed Sep 07, 2005 3:59 pm    Post subject: Reply with quote

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 Wink 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
View user's profile Send private message Visit poster's website
oxygen
Voice


Joined: 05 Sep 2005
Posts: 22
Location: Germany

PostPosted: Wed Sep 07, 2005 4:09 pm    Post subject: Reply with quote

No problem demond Wink

You say it's easy? I try for over a week to do this Sad
Seems I'm to lame for .tcl Shocked
Tnx anyway Very Happy I appreciate your help.
Hope some "soul" will help.

friendly regards
oxygen
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Wed Sep 07, 2005 4:30 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
minted
Halfop


Joined: 20 Jul 2005
Posts: 64

PostPosted: Thu Sep 08, 2005 1:36 am    Post subject: Reply with quote

lol! he was so polite u couldnt resist
Back to top
View user's profile Send private message
oxygen
Voice


Joined: 05 Sep 2005
Posts: 22
Location: Germany

PostPosted: Thu Sep 08, 2005 4:26 am    Post subject: Reply with quote

Tnx demond

You're a nice guy Smile

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

friendly regards
oxygen
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber