| View previous topic :: View next topic |
| Author |
Message |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Sun Jun 25, 2006 12:15 pm Post subject: Who can make this easier? |
|
|
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 |
|
 |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Tue Jun 27, 2006 7:20 am Post subject: |
|
|
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 |
|
 |
darton Op
Joined: 21 Jan 2006 Posts: 155
|
Posted: Wed Jun 28, 2006 2:31 pm Post subject: |
|
|
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 |
|
 |
|