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.

Simple countdown script

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
a
alextide32
Voice
Posts: 3
Joined: Wed Oct 03, 2012 7:01 pm

Simple countdown script

Post by alextide32 »

I have searched the TCL archives and can't seem to find a countdown script that does what I want. It doesn't involve birthdays or any certain "date".
I run a channel that frequently does "listen-alongs" to albums.
I just need a bot that I can set a time, like an hour or so in advance, and it will make an announcement in the channel every 5 minutes until it gets to the last 10 seconds. Then set the channel +m and do a complete countdown for the last 10 seconds then -m.
I'm not sure how complicated this would be but it would be awesome.

An example would be like this:
**MyBot sets mode +m #chan
MyBot: 10
MyBot: 9
MyBot: 8
MyBot: 7
MyBot: 6
MyBot: 5
MyBot: 4
MyBot: 3
MyBot: 2
MyBot: 1
MyBot: GO!
**MyBot sets mode -m

If you can script this for me you are awesome!
Thanks!
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

test it:

Code: Select all

# Author: tomekk
# e-mail:  tomekk/@/oswiecim/./eu/./org
# home page: http://tomekk.oswiecim.eu.org/
#
# Version 0.1
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html

# if you want to use this script on your chan, type in eggdrop console (via telnet or DCC chat)
# .chanset #channel_name +countd
# and later .save

##############################################
bind pub -|- !countdown cd_main

set cd_set 0
set sec_index 0
set cd_chan ""
set ann_interval 300

setudef flag countd

proc one_second_timer { } {
        global cd_set sec_index cd_chan ann_interval

        if {$sec_index >= 0} {
                if {$sec_index == 11} {
                        putserv "MODE $cd_chan +m" -next
                }

                if {($sec_index <= 10) && ($sec_index > 0)} {
                        putserv "PRIVMSG $cd_chan :$sec_index"
                }

                if {$sec_index == 1} {
                        putserv "PRIVMSG $cd_chan :GO!"
                        set cd_set 0
                }

                if {$sec_index == 0} {
                        putserv "MODE $cd_chan -m"
                }

                if {([expr $sec_index % $ann_interval] == 0) && ($cd_set == 1)} {
                        putserv "PRIVMSG $cd_chan :*** countdown: [expr $sec_index / $ann_interval] minute/s to go!"
                }

                if {[string match *one_second_timer* [utimers]] != 1} {
                        utimer 1 one_second_timer
                }

                set sec_index [expr $sec_index - 1]
        }
}

proc cd_main { nick uhost hand chan arg } {
        global cd_set sec_index cd_chan

        if {![channel get $chan countd]} {
                return
        }

        set minutes [string trim [lindex [split $arg] 0]]
        set cd_chan $chan

        if {$minutes != ""} {
                if {[regexp {^([0-9]+)$} $minutes]} {
                        if {$cd_set == 0} {
                                putquick "PRIVMSG $nick :done! ($minutes minute/s for You)"
                                set cd_set 1
                                set sec_index [expr $minutes * 60]
                                utimer 1 one_second_timer
                        } {
                                putquick "PRIVMSG $nick :sorry - one countdown at the same time is max"
                        }
                } {
                        putquick "PRIVMSG $chan :$nick, use: !countdown <minute/s (number ;))>"
                }
        } {
                putquick "PRIVMSG $chan :$nick, use: !countdown <minutes>"
        }
}

putlog "countdown.tcl ver 0.1 by tomekk loaded"
No multichannel support.
One more thing, this script works in eggdrop memory - so, every restart etc. will reset the script.
a
alextide32
Voice
Posts: 3
Joined: Wed Oct 03, 2012 7:01 pm

Post by alextide32 »

Perfect! This is exactly what I was looking for!
There is one small issue that might be easily fixed, when the countdown is at 5 minutes out it says "1 minute/s to go!" and when it's 10 minutes out it says "2 minute/s to go!". I don't know how easy this is to fix but if you can't get it to work you can just take it out and it will be fine.
Also is there a way to make it so only people with +o flags on the bot can use it?
Thanks for taking the time to script this!
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

1.
change:

Code: Select all

bind pub -|- !countdown cd_main 
to:

Code: Select all

bind pub -|o !countdown cd_main 

2.
change:

Code: Select all

putserv "PRIVMSG $cd_chan :*** countdown: [expr $sec_index / $ann_interval] minute/s to go!"
to:

Code: Select all

putserv "PRIVMSG $cd_chan :*** countdown: [expr [expr $sec_index / $ann_interval] * [expr $ann_interval / 60]] minute/s to go!"
a
alextide32
Voice
Posts: 3
Joined: Wed Oct 03, 2012 7:01 pm

Post by alextide32 »

Works perfectly! Thanks so much for your help!
Post Reply