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.

Unbind bind time and bind cron ?

General support and discussion of Eggdrop bots.
Post Reply
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Unbind bind time and bind cron ?

Post by juanamores »

The code has several bind crone and bind time commands, activated every x minutes.
Example:

Code: Select all

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 :)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Code: Select all

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
.
w
willyw
Revered One
Posts: 1197
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Also, go here:
http://www.eggheads.org/support/egghtml ... mands.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 !
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

SpiKe^^ wrote:

Code: Select all

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

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 :)
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

Now I found a way to fix it, but how could it be otherwise, I have problems with strings and lists. :oops:
[binds cron] returns a list of all cron binded (In this case has 8 elements):
{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: Select all

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

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

if {([info exist ok]) && ($ok == "1") } { unbind cron - {*/5 * * * *} warns
If not, increase the control counter and stores it in the avisos file

Code: Select all

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

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

foreach bin [binds cron]
I tried to put all the value in a variable, but the error continues:

Code: Select all

set compare [binds cron]
If I put:

Code: Select all

putmsg $chan "[binds cron]"
Return:
{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:

Code: Select all

.tcl binds cron
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 :)
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

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.
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

caesar wrote:

Code: Select all

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

 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:

Code: Select all

.tcl binds cron
and returned:
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:
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):
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! :D
In the Eggdrop Documentation I found this:
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: Select all

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 :)
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

juanamores wrote:
caesar wrote:

Code: Select all

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

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

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