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.

auto voice between 11pm and 8am

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
j
jeroen_005
Voice
Posts: 19
Joined: Sun Jun 22, 2008 7:47 am

auto voice between 11pm and 8am

Post by jeroen_005 »

I need a script that auto voice ppl between 11pm and 8am in my channel.

I know how to make a auto voice script but don't know how to includes those time range in my script :( Can someone help?

proc pub:onjoin {nick uhost hand chan} {
putserv "MODE $chan +v $nick"
return 1
}
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

LOL! You might need to indicate in what time zone
I must have had nothing to do
j
jeroen_005
Voice
Posts: 19
Joined: Sun Jun 22, 2008 7:47 am

Post by jeroen_005 »

Uhm server time xD That's GMT +1 :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Something like this should do the trick..

Code: Select all

proc pub:onjoin {nick uhost handle channel} {
  set hour [clock format [clock seconds] -format "%k"]
  if {$hour == 23 || $hour < 8} {
    pushmode $channel +v $nick
  }
}
NML_375
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

What is the difference between %H and %k in clock command?
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

username,
%k does not prefix single-digit values with 0, %H does..
For further explanations, see the man-pages.
NML_375
j
jeroen_005
Voice
Posts: 19
Joined: Sun Jun 22, 2008 7:47 am

Post by jeroen_005 »

thanks for helping nml375 :D you are great :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

arfer,
24 would actually be 0, not 24, and would thus be covered by the "less than 8" part. The logic is not flawed...

Of course, if we'd rather have a different limit than 11pm such as 10pm, you'd simply change "$hour == 23" into "$hour >= 22". As for your logics in your script, I'm quite confident to say that it is flawed:

Code: Select all

.. ($h >= $vStartHour) && ($h >= $vEndHour) ..
Tests whether we've passed both the start and end hour. If we've passed both, we really should'nt voice.

Code: Select all

.. ($h <= $vStartHour) && ($h <= $vEndHour) ..
Tests whether we've yet to reach both the start and end hour. Hence, we've yet to reach the time when we should start voicing.

So you are actually voicing when you should not voice...

The gmt-offset is also flawed, as this code could generate hours out of bounds. You'd atleast need to use the modulus operator to make certain the result is in bounds. In my honest opinion, this is overworked though, as the clock command honours time zone settings, and will always use the same time as your eggdrop.
NML_375
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

sorry nml375, I realised was taking nonsense before you replied and deleted my post

However, I was interested to develop a more flexible script and cant seem to find the math to calculate whether a particular hour is between two others, as follows :-

I think your mod maths is needed to check if a number is in bounds.

Could you take a look and advise please

Code: Select all

set vStartHour 23
set vEndHour 8
set vGmtOffset +1
set vVoiceDelay 10

bind JOIN - * pTimedVoiceJoin

proc pTimedVoiceJoin {nick uhost hand chan} {
    global vGmtOffset vStartHour vEndHour vVoiceDelay
    set hour [expr {[clock format [clock seconds] -format %k -gmt 1] + $vGmtOffset}]
    # {if statement needed here for checking if within bound} {
        utimer $vVoiceDelay [list pTimedVoiceDelay $nick $chan]
    # }
    return 0
}

proc pTimedVoiceDelay {nick chan} {
    if {[botisop $chan]} {
        if {[onchan $nick $chan]} {
            if {(![isop $nick $chan]) && (![isvoice $nick $chan])} {
                pushmode $chan +v $nick
                flushmode $chan
            }
        }
    }
    return 0
}

# eof
I must have had nothing to do
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Hmm, I also see what you mean regarding the gmt code. This could erroneously generate hour 24

This is not easy to accomplish
I must have had nothing to do
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

arfer,
Just use the modulus operator, and you won't have to bother with testing..
Or, as I suggested, simply make use of the already existing time zone settings.. Seems rather overkill to add a second time zone setting that only affects one function...

Next, you have three cases with start- and end-hour:
  • start is less than end
    We should only voice if $hour is greater than or equal to start and less than end.
  • start is greater than end
    We should only voice if $hour is greater than or equal to start or less than end.
  • start is equal to end
    This is really not a valid range. We should not voice at all.
If we choose to ignore the last case, as it is not valid, we can compile the following expression (in it's most simplified form, be aware that this expression is designed with operator priority in mind).:

Code: Select all

if {$hour >= $start && $hour < $end || ($hour >= $start || $hour < $end) && $start > $end} {
NML_375
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

# set some global vars up with contents
# voice delay (in minutes) this is to prevent a
# flood of voices during a netsplit rejoin, or
# rogue users flooding your channel.
variable vVoiceDelay 10
# hour to start voice (24 hour) 
variable vStartHour 23
# hour to stop voicing (24 hour)
variable vEndHour 8

# init voicelist
variable voicelist [list]

# init timer to check list, so if a flood of joins occurs
# in that period, we can stuff as many modes on one line
# as possible in as many channels as possible.
timer $vVoiceDelay timer:onjoin

proc pub:onjoin {nick uhost handle channel} {
  # maybe this is nml375's code :)
  set hour [clock format [clock seconds] -format "%k"]
  if {$hour >= $::vStartHour && $hour < $::vEndHour || ($hour >= $::vStartHour || $hour < $::vEndHour) && $::vStartHour > $::vEndHour} {
    # create a single in-line voicelist, checking that
    # a rotating nickname gets added only once.
    if {[lsearch -exact $::voicelist [string tolower $nick]] == -1} {
      lappend ::voicelist [string tolower $nick] $uhost $handle $channel 
    }
  }
}

proc timer:onjoin { } {
  set channellist [list]
  # iterate through the in-line voicelist
  foreach {nick uhost handle channel} $::voicelist {
    # conditionals
    if {[botisop $channel] && [onchan $nick $channel] && ![isvoice $nick $channel]} {
      pushmode $channel +v $nick
      # for the flushmode below to work we need to track every chan
      # we've done any mode changes through. to keep this list short
      # and no channels repeated, i propose an lsearch. i know this
      # would be executed at the end of the proc anyways. this is
      # for style points.. :P
      if {[lsearch -exact $channellist $channel] == -1} {
        lappend $channellist $channel
      }
    }
  }
  # STYLE POINTS! this is totally unnecessary, but it looks cool.
  foreach $chan $channelist {
    flushmode $chan
  }
  # clear voicelist for next flush
  set ::voicelist [list]
  # recall timer to check next joiners
  timer $::vVoiceDelay timer:onjoin 
}
If I may throw my 2cents worth into this debate. This is probably where arfer was going with his script. The idea is to keep mode changes to a minimum in case a flood of joins occurs and this keeps it global for every channel the bot resides in just like the rest of your scripts did..

Edit: Corrected many stupid mistakes and obvious over sights mentioned further down in this thread. This should now be something useful to the poster rather than something to be looked down upon as a poor example of poster's request. :D
Last edited by speechles on Sat Jul 04, 2009 2:24 pm, edited 14 times in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Speechles,
Not to be rude, but the expression you've entered is not even remotely close to what I've suggested! Also, it is severely flawed.
Please do not attach my signature with some random piece of code.
NML_375
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

nml375 wrote:Speechles,
Not to be rude, but the expression you've entered is not even remotely close to what I've suggested! Also, it is severely flawed.
Please do not attach my signature with some random piece of code.
Not to be rude sir, but your code will flood a channel in the event of a flood of joins. Be this a netsplit, rogue users, etc. I would rather think you at your caliber of this field you would be more caring. But i digress....

Also corrected that silly concat I did above to keep all elements available to allow the timer to keep the contents intact. The foreach seemed simplest and the only way to do it without using a series of sets with lindexes on them. concat is the answer. This is not to criticize your help to the user as all he asked was for a direction to go in accomplishing it. He probably could have figured out the rest. This was just for the sake of debate which clearly we are having. Bravo. ;)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

speechles,
I did not make any comments as to your flood protection, neither anyone else's. You might also like to keep in mind that the original request did not come with flood protection, neither did the initial code example by the requester have one.

That, however, does not change the case that you've attached my signature to code I've not written, and which is non-functional. At best, I consider that slander.

On a side note, you could improve performance in your script by using the lappend command rather than resetting the variable with a concat'd value...
NML_375
Post Reply