| View previous topic :: View next topic |
| Author |
Message |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Sat May 16, 2015 2:53 am Post subject: Unbind bind time and bind cron ? |
|
|
The code has several bind crone and bind time commands, activated every x minutes.
Example:
| Code: | bind cron - {*/5 * * * *} warns
proc warns {nick uhost hand chan text} {
global canal_admin
if {(![file exist notices]) || (![file exist dj])} {return}
set temp [open "notices" r]
set data [read -nonewline $temp]
close $temp
set lines [split $data "\n"]
set djnickname [lindex $lines 0]
set nchan [lindex $lines 1]
if {[file exist dj]} {
set temp [open "dj" r]
set dj [gets $temp]
set dj [lindex $dj 0]
close $temp
if {$djnickname != $dj} {return}
}
if {$djnickname == "AutoCHz"} {return}
set entra ""
set ic ""
set x 0
set y [llength $nchan]
while {$x < $y} {
set ic [lindex [split $nchan] $x end]
set x [expr {$x + 1}]
if { $ic == "" } { continue }
if {[onchan $djnickname $ic]} { continue
} else {
append entra [encoding convertfrom utf-8 " $ic"]
}}
set entra [encoding convertfrom utf-8 "$entra"]
putquick "NOTICE $djnickname :For to emit is neccesary join into $entra"
return
} |
With this script, the bot warns the current DJ every 5 minutes, you should join a x channels to broadcast.
I have noticed that this TCL, together with others, lag to much bot.
For that reason desire which in x time or x number of warnings, the warning no longer continue, and that the command will disabled.
I can put a counter and reached a x number put a return command.
But what I really want is to see how to make a unbind this command.
You can perform unbind this commands? _________________ If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks  |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Sat May 16, 2015 11:15 am Post subject: |
|
|
| Code: | | unbind cron - {*/5 * * * *} warns |
_________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Sat May 16, 2015 2:12 pm Post subject: |
|
|
Also, go here:
http://www.eggheads.org/support/egghtml/1.6.21/tcl-commands.html
and text search to find: unbind
It will be in the section labeled:
9. Miscellaneous commands
Read about the unbind command there. _________________ For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia ! |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Mon May 18, 2015 3:57 am Post subject: |
|
|
| SpiKe^^ wrote: | | Code: | | unbind cron - {*/5 * * * *} warns |
|
I had already tried but fails in that way.
Tcl error [warns]: no such binding
What I want is that the proc warns not run again when the control variable is greater or equal to 4.
Perhaps I misspoke and not is with the unbind command that accomplishes what I want.
So the proc warns continues to run, that's why the unbind is attempted again and gives the error.
| Code: | bind cron - {*/5 * * * *} warns
proc warns {nick uhost hand chan text} {
global canal_admin control
if {$control >= 4} { unbind cron - {*/5 * * * *} warns }
if {(![file exist notices]) || (![file exist dj])} {return}
if {[file exist avisos]} {
set temp [open "avisos" r]
set data [read -nonewline $temp]
close $temp
set lines [split $data "\n"]
set control [lindex $lines 0]
if {$control >= 3} {
putlog "\002NOTICEs\002 for \002DJ\002 \002disabled."
putmsg $canal_admin [encoding convertfrom utf-8 "After 3
warnings, will not be more alert to DJ ."]
set control [expr {$control + 1}]
return
}
}
set temp [open "notices" r]
set data [read -nonewline $temp]
close $temp
set lines [split $data "\n"]
set djnickname [lindex $lines 0]
set nchan [lindex $lines 1]
if {[file exist dj]} {
set temp [open "dj" r]
set dj [gets $temp]
set dj [lindex $dj 0]
close $temp
if {$djnickname != $dj} {return}
}
if {$djnickname == "AutoCHz"} {return}
set entra ""
set ic ""
set x 0
set y [llength $nchan]
while {$x < $y} {
set ic [lindex [split $nchan] $x end]
set x [expr {$x + 1}]
if { $ic == "" } { continue }
if {[onchan $djnickname $ic]} { continue
} else {
append entra [encoding convertfrom utf-8 " $ic"]
}
}
set entra [encoding convertfrom utf-8 "$entra"]
putquick "NOTICE $djnickname :For to emit is neccesary join into $entra"
set control [expr {$control + 1}]
set temp [open "avisos" w]
puts $temp $control
close $temp
return
} |
_________________ If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks  |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Mon May 18, 2015 9:59 pm Post subject: |
|
|
Now I found a way to fix it, but how could it be otherwise, I have problems with strings and lists.
[binds cron] returns a list of all cron binded (In this case has 8 elements):
| Quote: |
{cron -|- {*/10 * * * *} 14 notify} {cron -|- {*/10 * * * *} 14 advertise} {cron -|- {* * * * *} 140 tiempos} {cron -|- {* * * * *} 140 envivo} {cron -|- {*/1 * * * *} 23 warns} {cron -|- {*/30 * * * *} 4 status} {cron -|- {*/30 * * * *} 4 advertise3} {cron -|- {*/20 * * * *} 7 advertise2} |
The ease that I have to find the name of the proc (warns), is that all elements of the list, beginning with cron, and ending with the name of the process.
My idea was to compare the last word of each item on the list, with the name of the process warns.
First, I store each item the list to the compare variable.
| Code: | foreach bin [binds cron] {
set compare [lindex [split $bin] $x] |
If the proc warns is in the list, means that is not unbinded. When is matched, sets Ok variable value to 1 and use break to cut the loop.
| Code: | | if {[string index $compare end] == "warns"} {set ok 1;break } |
Then, if there is Ok variable it has a value of 1, unbind the proc.
| Code: | | if {([info exist ok]) && ($ok == "1") } { unbind cron - {*/5 * * * *} warns |
If not, increase the control counter and stores it in the avisos file
| Code: | set control [expr {$control + 1}]
set temp [open "avisos" w]
puts $temp $control
close $temp
return |
But I have changed several times code and continues to the following error:
Tcl error [warns]: wrong # args: should be "for start test next command"
| Code: | bind cron - {*/5 * * * *} warns
proc warns {nick uhost hand chan text} {
global canal_admin canal_djs control
if {$control >= 4} {
for x 0
foreach bin [binds cron] {
set compare [lindex [split $bin] $x]
if {[string index $compare $x] == "warns"} {set ok 1;break }
set x [expr {$x + 1}]
}
if {([info exist ok]) && ($ok == "1") } { unbind cron - {*/5 * * * *} warns; return
} else {
set control [expr {$control + 1}]
set temp [open "avisos" w]
puts $temp $control
close $temp
return
}
}
#### more stuff###
} |
EDIT: The error is given by:
| Code: | | foreach bin [binds cron] |
I tried to put all the value in a variable, but the error continues:
| Code: | | set compare [binds cron] |
If I put:
| Code: | | putmsg $chan "[binds cron]" |
Return:
| Quote: |
{cron -|- {*/10 * * * *} 14 notify} {cron -|- {*/10 * * * *} 14 advertise} {cron -|- {* * * * *} 140 tiempos} {cron -|- {* * * * *} 140 envivo} {cron -|- {*/1 * * * *} 23 warns} {cron -|- {*/30 * * * *} 4 status} {cron -|- {*/30 * * * *} 4 advertise3} {cron -|- {*/20 * * * *} 7 advertise2} |
If I put on the party line:
It returns the same values, but without error.
How I can fix it? _________________ If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks  |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue May 19, 2015 12:35 am Post subject: |
|
|
| Code: |
foreach ele [binds cron] {
if {[scan $ele {%s%s%s%d%s} type flags cmd hits func] != 5} continue
if {$func ne "warns"} continue
putlog "unbind cron - $flags $func"
}
|
Give this a try and if shows the stuff you want to be removed correctly then drop the putlog and the "" _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Tue May 19, 2015 6:34 pm Post subject: |
|
|
| caesar wrote: | | Code: |
foreach ele [binds cron] {
if {[scan $ele {%s%s%s%d%s} type flags cmd hits ] != 5} continue
if {$func ne "warns"} continue
putlog "unbind cron - $flags $func"
}
|
Give this a try and if shows the stuff you want to be removed correctly then drop the putlog and the "" |
caesar it not worked.
The condition that control variable is >=4 was fulfilled, but not the unbind was run.
What means the number 5 in this expression?
| Code: | | if {[scan $ele {%s%s%s%d%s} type flags cmd hits func] != 5} continue |
Because, if the number of item in the list I pasted above, will not work, since the list is dynamically sorted by the number of hits occurred.
In this moment I put the party line:
and returned:
| Quote: | | Tcl: {cron -|- {*/30 * * * *} 4 warns} {cron -|- {*/30 * * * *} 4 advertise3} {cron -|- {*/1 * * * *} 109 entrada} {cron -|- {* * * * *} 109 envivo} {cron -|- {*/20 * * * *} 5 advertise2} {cron -|- {*/10 * * * *} 11 notify} {cron -|- {*/10 * * * *} 11 advertise} |
And about 5 minutes ago before was:
| Quote: | | Tcl: {cron -|- {* * * * *} 81 envivo} {cron -|- {*/1 * * * *} 81 warns} {cron -|- {*/20 * * * *} 4 advertise2} {cron -|- {*/10 * * * *} 8 notify} {cron -|- {*/10 * * * *} 8 advertise} {cron -|- {*/30 * * * *} 3 warns} {cron -|- {*/30 * * * *} 3 advertise3} |
EDIT:
I have tried for debbugin purpose (7 is number of elements in the binds cron list actually):
| Quote: | foreach ele [binds cron] {
if {[scan $ele {%s%s%s%d%s} type flags cmd hits func] > 7} break
putmsg $canal_admin "FUNC: $func"
if {$func ne "warns"} continue
putlog "unbind cron - $flags $func"
} |
Tcl error [warns]: can't read "func": no such variable
FINAL EDIT: Fixed!
In the Eggdrop Documentation I found this:
| Quote: | binds [type/mask]
Returns: a list of Tcl binds, each item in the list is a sublist of five elements: {<type> <flags> <name> <hits> <proc>} |
| Code: | foreach ele [binds] {
foreach {type flags name hits proc} $ele {
if {[string match "warns" $proc]} {
unbind $type $flags $name $proc
break
}
}
}
|
_________________ If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks  |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Wed May 20, 2015 3:22 am Post subject: |
|
|
| juanamores wrote: |
| caesar wrote: |
| Code: |
foreach ele [binds cron] {
if {[scan $ele {%s%s%s%d%s} type flags cmd hits ] != 5} continue
if {$func ne "warns"} continue
putlog "unbind cron - $flags $func"
}
|
|
|
| Code: |
if {[scan $ele {%s%s%s%d%s} type flags cmd hits func] != 5} continue
|
Please notice the missing of 5th element func in your code. I posted 5 and somehow you ate one.
As for foreach, here's a better way to do it:
| Code: |
foreach {type flags cmd hits func} [join [binds]] {
if {$func eq "warns"} {
unbind $type $flags $cmd $func
break
}
}
|
_________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
|