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.

Adding a delay on a loop ('foreach')

Old posts that have not been replied to for several years.
Locked
User avatar
TC^^
Voice
Posts: 22
Joined: Tue Jul 05, 2005 11:50 am

Adding a delay on a loop ('foreach')

Post by TC^^ »

Demond provided me with this simple and wonderfull script , that nailed the request I had dead on, and i appreciate it very much. Now I'm working on tweaking it for my needs, and kinda 'learning TCL scripting by doing TCL scripting'.

I saw this problem comming, but was hoping I had a basic understanding enough to solve it myself... I was wrong...

The problem with the script, is that if I have more than one bot, a few perhaps, and all the bots is in 15-20 channels, then the server disconnects me for excess flood if i send a rather large broadcast message (well *doorh* right? I know...).

I was hoping to solve the problem, by adding som sort of delay. A delay that makes the script pause a few seconds before posting in each channel?!

I'm posting the raw code, as I got it, without my modifications and unsuccessfull tries to make it pause. And I'm hoping it can be solved rather simple, and someone will show me how :oops:

Code: Select all

bind bot - announce botannounce
bind msg m announce gotannounce

proc announce {text} {
  foreach chan [channels] {
    if {[botonchan $chan]} {
      puthelp "privmsg $chan :$text"
    }
  }
}
proc botannounce {from cmd text} {
  announce $text
}
proc gotannounce {nick uhost hand text} {
  putallbots "announce $text"
  announce $text
}
[/code]
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

see my code here
User avatar
TC^^
Voice
Posts: 22
Joined: Tue Jul 05, 2005 11:50 am

Post by TC^^ »

So.. Tried to tie in your bit of code, to the script.. This it what I got from it. Does the announcements, but without the delay!?... I'm sure I've done something wrong, maybe put the code the wrong place. Please advice..

Code: Select all

bind bot - announce botannounce
bind msg m announce gotannounce

set queue {} 
set frequency 5 ;# seconds 
proc getqueue {} { 
 if {$::queue != {}} { 
  puthelp [lindex $::queue 0] 
  set ::queue [lreplace $::queue 0 0] 
 } 
 utimer $::frequency getqueue 
} 
proc putqueue {str} { 
 lappend ::queue $str 
} 

getqueue 



proc announce {text} {
  putlog ":: Announce :: Announced to channels ( $text )"
  foreach chan [channels] {
    if {[botonchan $chan]} {
      putqueue "privmsg $chan :$text"
    }
  }
}
proc botannounce {from cmd text} {
  putlog ":: Announce :: $from instructed me to announce"
  announce $text
}
proc gotannounce {nick uhost hand text} {
  putlog ":: Announce :: $nick ($uhost) instructed me to announce"
  putallbots "announce $text"
  announce $text
}
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

increase frequency (actually the name of that variable is misleading - increasing it means your messages will show up with longer delay - but anyway)
User avatar
TC^^
Voice
Posts: 22
Joined: Tue Jul 05, 2005 11:50 am

Post by TC^^ »

Allready tried that.. I just set it to 30 and tried again.. No effect :(
User avatar
TC^^
Voice
Posts: 22
Joined: Tue Jul 05, 2005 11:50 am

Post by TC^^ »

Actually.. It has an effect.. It delays the broadcast with 30 seconds.

30 seconds after i send the trigger, the bot announces the message on all channels at the same time.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

TC^^ wrote: 30 seconds after i send the trigger, the bot announces the message on all channels at the same time.
that's simply not possible with the code as shown, you must have messed up something; that queue gets emptied one message at a time, every $::frequency seconds
User avatar
TC^^
Voice
Posts: 22
Joined: Tue Jul 05, 2005 11:50 am

Post by TC^^ »

It's a completly new installation of Eggdrop (not windrop), basic configuration (only changed name, channel, some ports and such) and with only one custom script, this one.

This is the result, in a test I just did, with the code posted above:

Test 1

[19:17:59] -› msg °InformiZle° announce Broadcasted announcement...

Channel #1 -> [19:18:10] [InformiZle] Broadcasted announcement...
Channel #2 -> [19:18:12] [InformiZle] Broadcasted announcement...
Channel #3 -> [19:18:27] [InformiZle] Broadcasted announcement...
Channel #4 -> [19:18:28] [InformiZle] Broadcasted announcement...


Test 2

[19:18:37] -› msg °InformiZle° announce Broadcasted announcement...

Channel #1 -> [19:18:40] [InformiZle] Broadcasted announcement...
Channel #2 -> [19:18:42] [InformiZle] Broadcasted announcement...
Channel #3 -> [19:18:56] [InformiZle] Broadcasted announcement...
Channel #4 -> [19:18:58] [InformiZle] Broadcasted announcement...


Test 3

[19:19:03] -› msg °InformiZle° announce Broadcasted announcement...

Channel #1 -> [19:19:11] [InformiZle] Broadcasted announcement...
Channel #2 -> [19:19:13] [InformiZle] Broadcasted announcement...
Channel #3 -> [19:19:27] [InformiZle] Broadcasted announcement...
Channel #4 -> [19:19:29] [InformiZle] Broadcasted announcement...


Test 4

[19:19:35] -› msg °InformiZle° announce Broadcasted announcement...

Channel #1 -> [19:19:40] [InformiZle] Broadcasted announcement...
Channel #2 -> [19:19:42] [InformiZle] Broadcasted announcement...
Channel #3 -> [19:19:56] [InformiZle] Broadcasted announcement...
Channel #4 -> [19:19:58] [InformiZle] Broadcasted announcement...


I noticed a pattern.. It does make a delay, but only between channel 2 and 3!? From channel 1 to 2, and 2 to 4 there is only the 2 second delay that the bot makes by default? Have any ideas why?

[edit] Please be aware that I changed the delay to 15 seconds in the script! [/edit]
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

try changing [puthelp] to [putserv] or [putquick] and see if anything changes; other than that, I fail to anything else causing your problem but somehow messed up original utimer queue code
User avatar
TC^^
Voice
Posts: 22
Joined: Tue Jul 05, 2005 11:50 am

Post by TC^^ »

'puthelp' did the trick...

[19:58:25] -› msg °InformiZle° announce Broadcasted announcement...
[19:58:38] [InformiZle] Broadcasted announcement...
[19:58:54] [InformiZle] Broadcasted announcement...
[19:59:08] [InformiZle] Broadcasted announcement...
[19:59:24] [InformiZle] Broadcasted announcement...

Roughly 15 seconds between...


Thanks again for the help Demond..
User avatar
TC^^
Voice
Posts: 22
Joined: Tue Jul 05, 2005 11:50 am

Post by TC^^ »

Now thats just wierd... I changed the script, restarted the bot, and tried it out.. Worked as posted above.. Then I tried again, and the same error appears again. Only delay between channel 3 and 4?!.....

...... :?:
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

lag, either with your bot or the server
User avatar
TC^^
Voice
Posts: 22
Joined: Tue Jul 05, 2005 11:50 am

Post by TC^^ »

Thats why I do 4 tests and not only one.. Well actually more than 4.. But I guess I just have to live with it.
Locked