egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

auto voice between 11pm and 8am
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
jeroen_005
Voice


Joined: 22 Jun 2008
Posts: 19

PostPosted: Sat Jul 04, 2009 8:04 am    Post subject: auto voice between 11pm and 8am Reply with quote

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 Sad Can someone help?

proc pub:onjoin {nick uhost hand chan} {
putserv "MODE $chan +v $nick"
return 1
}
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sat Jul 04, 2009 10:35 am    Post subject: Reply with quote

LOL! You might need to indicate in what time zone
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
jeroen_005
Voice


Joined: 22 Jun 2008
Posts: 19

PostPosted: Sat Jul 04, 2009 10:40 am    Post subject: Reply with quote

Uhm server time xD That's GMT +1 Smile
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Jul 04, 2009 11:13 am    Post subject: Reply with quote

Something like this should do the trick..

Code:
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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
username
Op


Joined: 06 Oct 2005
Posts: 196
Location: Russian Federation, Podolsk

PostPosted: Sat Jul 04, 2009 11:14 am    Post subject: Reply with quote

What is the difference between %H and %k in clock command?
_________________
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Jul 04, 2009 11:16 am    Post subject: Reply with quote

username,
%k does not prefix single-digit values with 0, %H does..
For further explanations, see the man-pages.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
jeroen_005
Voice


Joined: 22 Jun 2008
Posts: 19

PostPosted: Sat Jul 04, 2009 11:30 am    Post subject: Reply with quote

thanks for helping nml375 Very Happy you are great Smile
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Jul 04, 2009 12:05 pm    Post subject: Reply with quote

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:
.. ($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:
.. ($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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sat Jul 04, 2009 12:12 pm    Post subject: Reply with quote

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:

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
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sat Jul 04, 2009 12:15 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Jul 04, 2009 12:25 pm    Post subject: Reply with quote

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:
if {$hour >= $start && $hour < $end || ($hour >= $start || $hour < $end) && $start > $end} {

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sat Jul 04, 2009 1:16 pm    Post subject: Reply with quote

Code:
# 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. Very Happy
_________________
speechles' eggdrop tcl archive


Last edited by speechles on Sat Jul 04, 2009 2:24 pm; edited 14 times in total
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Jul 04, 2009 1:20 pm    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sat Jul 04, 2009 1:22 pm    Post subject: Reply with quote

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. Wink
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Jul 04, 2009 1:37 pm    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber