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 

Who can make this easier?

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Sun Jun 25, 2006 12:15 pm    Post subject: Who can make this easier? Reply with quote

Hello!
I made a script very circumstantially I think. There are definitely several lines which are unnecessary. Maybe somebody can make this more easier for me:
Code:
bind pubm - * reset:flag
proc reset:flag {nick uhost hand chan arg} {
  set reset [lrange [split $arg] 0 2]
  set reset [stripcodes bcruag $reset]
  set fd [open $::flagfile r+]

  if {[string match -nocase {text 1} $reset] || [string match -nocase {text 2} $reset]} {
      while {![eof $fd]} {
         lappend list [gets $fd]
      }
      set list [lreplace $list 0 0 [list 3 3]]
     seek $fd 0
     puts -nonewline $fd [join $list \n]
     close $fd
     return 0
     }

  if {[string match -nocase {text 3} $reset] || [string match -nocase {text 4} $reset] || [string match -nocase {text 5} $reset] || [string match -nocase {text 6} $reset] || [string match -nocase {text 7} $reset]} {

      while {![eof $fd]} {
         lappend list [gets $fd]
      }
      set list [lreplace $list 0 0 [list 4 4]]
     seek $fd 0
     puts -nonewline $fd [join $list \n]
     close $fd
     return 0
     }

  if {[string match -nocase {text 8} $reset] || [string match -nocase {text 9} $reset]} {
      while {![eof $fd]} {
         lappend list [gets $fd]
      }
      set list [lreplace $list 0 0 [list 5 5]]     
     seek $fd 0
     puts -nonewline $fd [join $list \n]
     close $fd
     return 0
     }
}

This script opens a textfile and change two numbers. But it should only change something if there are special texts written in the channel.
Back to top
View user's profile Send private message
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Tue Jun 27, 2006 7:20 am    Post subject: Reply with quote

Is it too complex?
Look, this part
Code:
bind pubm - * reset:flag

      while {![eof $fd]} {
         lappend list [gets $fd]
      }
      set list [lreplace $list 0 0 [list 3 3]]
     seek $fd 0
     puts -nonewline $fd [join $list \n]
     close $fd
     return 0
     }

is repeated 2 more times. Only the if-query is different. And now my question is whether I really must repeat the following part after each if-query.
Code:
      while {![eof $fd]} {
         lappend list [gets $fd]
      }
      set list [lreplace $list 0 0 [list 3 3]]
     seek $fd 0
     puts -nonewline $fd [join $list \n]
     close $fd
     return 0

Only this line is different after the if-queries: "set list [lreplace $list 0 0 [list 3 3]] "
Back to top
View user's profile Send private message
darton
Op


Joined: 21 Jan 2006
Posts: 155

PostPosted: Wed Jun 28, 2006 2:31 pm    Post subject: Reply with quote

This way it is easier.
Code:
bind pubm - * reset:flag
proc reset:flag {nick uhost hand chan arg} {
  set reset [lrange [split $arg] 0 2]
  set fd [open $::flagfile r+]
  set case 0
  if {[string match -nocase {text 1} $reset] || [string match -nocase {text 2} $reset]} {set case 1}
  if {[string match -nocase {text 8} $reset] || [string match -nocase {text 9} $reset]} {set case 2}
  if {$case == 1 || $case ==2} {
      while {![eof $fd]} {
         lappend list [gets $fd]
      }
      if {$case == 1} {set list [lreplace $list 0 0 [list 3 3]]}
      if {$case == 2} {set list [lreplace $list 0 0 [list 5 5]]}
         seek $fd 0
         puts -nonewline $fd [join $list \n]
         close $fd
        return 0
   }
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help 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