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.

Who can make this easier?

Help for those learning Tcl or writing their own scripts.
Post Reply
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Who can make this easier?

Post by darton »

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

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.
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

Is it too complex?
Look, this part

Code: Select all

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

      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
  • ] "
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

This way it is easier.

Code: Select all

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
   }
}
Post Reply