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.

CountDown TCL

Old posts that have not been replied to for several years.
Locked
User avatar
Stealthx
Halfop
Posts: 68
Joined: Fri Oct 01, 2004 3:37 am
Location: StealthBox

CountDown TCL

Post by Stealthx »

Hi guys, I'm currently looking for a TCL that countdown to a specify date, when someone trigger a command in the main (example. !count), the bot will respond to it as in (There are 1 week 1 day 1 hour left to 01/01/2005)... The date will be input into the TCL manually so the bot would be able to get the data from the TCL.

I've found a TCL (Daystill v1.02 by David Proper (Dr. Nibble [DrN])), it's the script that does a countdown too but however, it only countdown for the day (example There are 47 days left to My Birthday). The TCL I wan is to check for the duration (exact timing as in day, hours, minutes, seconds).

This is the coding of the TCL:

Code: Select all

set daystill(ver) "v1.02.00"

proc cmdchar { } {global cmdchar_; return $cmdchar_}


bind join - ******* do_daystill_join
proc do_daystill_join {nick uhost hand chan} {
global daystill
 if {![daystillchan $chan]} {return 0}
 putserv "NOTICE $nick :[getdaystill $daystill(month) $daystill(day) $daystill(year) $daystill(name)]"
}

proc daystillchan {$chan} {
global daystill
 if {$daystill(onjoinchan) == ""} {return 0}
 set chans [string tolower $daystill(onjoinchan)]
 if {$chans == "*"} {set chans [string tolower [channels]]}
 if {[lsearch -glob $chans [string tolower "*$chan*"]] > -1 } {return 1}
 return 0
}

proc getdaystill {month day year name} {
 set timediff [daystill $month $day $year]
if {$timediff > 0} {return "There are [lindex [tdiff2 $timediff] 0] days until $name"}
if {$timediff == 0} {return "Today is $name!"}
if {$timediff < 0} {
                    set timediff [expr $timediff - ($timediff * 2)]
                     return "It's been [lindex [tdiff2 $timediff] 0] days Since last $name"
                   }
                                                                
}


bind pub - [cmdchar]$daystill(trigger) pub_daystill
proc pub_daystill {nick uhost hand chan rest} {
global daystill
 putserv "PRIVMSG $chan :[getdaystill $daystill(month) $daystill(day) $daystill(year) $daystill(name)]"
}

bind msg - $daystill(trigger) msg_daystill
proc msg_daystill {nick uhost handle args} {
global daystill
 putserv "PRIVMSG $nick :[getdaystill $daystill(month) $daystill(day) $daystill(year) $daystill(name)]"
}

bind dcc - $daystill(trigger) dcc_daystill
proc dcc_daystill {handle idx args} {
global daystill
 putdcc $idx "[getdaystill $daystill(month) $daystill(day) $daystill(year) $daystill(name)]"
}

bind dcc - daystill dcc_daystillm
proc dcc_daystillm {handle idx args} {
global daystill
 foreach line $daystill(list) {
 set month [lindex $line 0]
 set day [lindex $line 1]
 set year [lindex $line 2]
 set name [lrange $line 3 end]
 putdcc $idx "[getdaystill $month $day $year $name]"
                              }
}

bind msg - daystill msg_daystillm
proc msg_daystillm {nick uhost handle args} {
global daystill
 foreach line $daystill(list) {
 set month [lindex $line 0]
 set day [lindex $line 1]
 set year [lindex $line 2]
 set name [lrange $line 3 end]
 putserv "PRIVMSG $nick :[getdaystill $month $day $year $name]"
                              }
}



bind pub - [cmdchar]daystill pub_daystillm
proc pub_daystillm {nick uhost hand chan rest} {
global daystill
 foreach line $daystill(list) {
 set month [lindex $line 0]
 set day [lindex $line 1]
 set year [lindex $line 2]
 set name [lrange $line 3 end]
 putserv "PRIVMSG $chan :[getdaystill $month $day $year $name]"
                              }
}

proc daystill {targetmonth targetday targetyear} {
  set rtime [ctime [unixtime]]
  set amonth [string range $rtime 4 6]

  switch $amonth {
    Jan {set month "1"}
    Feb {set month "2"}
    Mar {set month "3"}
    Apr {set month "4"}
    May {set month "5"}
    Jun {set month "6"}
    Jul {set month "7"}
    Aug {set month "8"}
    Sep {set month "9"}
    Oct {set month "10"}
    Nov {set month "11"}
    Dec {set month "12"}
  }


  set day [lindex $rtime 2]
  set year [string range $rtime 20 23]
  set date1 [clock scan $month/$day/$year]
  if {$targetyear == 0} {set targetyear $year
       set date2 [clock scan $targetmonth/$targetday/$targetyear]
       if {$date2<$date1} {set targetyear [expr $year + 1]}
                        }

  set date2 [clock scan $targetmonth/$targetday/$targetyear]
  set date3 [expr $date2 - $date1]
  return $date3
}


proc tdiff {t} {
 return [dotdiff 1 $t]
}
proc tdiff2 {t} {
 return [dotdiff 2 $t]
}

proc dotdiff {v ltime} {
 if {$v == 1} {
               set m_ "m"
               set h_ "h"
               set d_ "d"
               set s_ "s"
              } else {
               set m_ " minute"
               set h_ " hour"
               set d_ " day"
               set s_ " second"
                     }
set days 0
set hours 0
set minutes 0
set seconds 0
set after 0
set out ""

set seconds [expr $ltime % 60]
set ltime [expr ($ltime - $seconds) / 60]
set minutes [expr $ltime % 60]
set ltime [expr ($ltime - $minutes) / 60]
set hours [expr $ltime % 24]
set days [expr ($ltime - $hours) / 24]
if {$v == 1} {
if {$days > 0} {append out "${days}$d_ "}
if {$hours > 0} {append out "${hours}$h_ "}
if {$minutes > 0} {append out "${minutes}$m_ "}
if {$seconds > 0} {append out "${seconds}$s_ "}
             } else {
 if {$days > 0} {append out "${days}$d_[thes $days] "}
 if {$hours > 0} {append out "${hours}$h_[thes $hours] "}
 if {$minutes > 0} {append out "${minutes}$m_[thes $minutes] "}
 if {$seconds > 0} {append out "${seconds}$s_[thes $seconds] "}
                    }

if {[string index $out [expr [string length $out] - 1]] == " "} {
  set out [string range $out 0 [expr [string length $out] - 2]]}
return "$out"
}

proc thes {num} {
if {$num == 1} {return ""} else {return "s"}
}
Anyone could help? :) Thanks! :mrgreen:
+ Stealth Box +
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

yay, bloatware. something like this should do it

Code: Select all

set when "August 20 00:00:00 2005"
set why "my birthday!"

bind pub - !birthday pub:countdown
proc pub:countdown {nick uhost hand chan text} {
 global when why
  set dur [expr [clock scan $when]-[clock seconds]]
  putquick "PRIVMSG $chan :There's [duration $dur] until $why"
}
P
PLUGGER
Voice
Posts: 24
Joined: Sat Nov 30, 2002 6:54 am
Contact:

Post by PLUGGER »

Just use this one - why re-invent the wheel...lol

Code: Select all

###############################################
# Countdown.tcl 0.1 by #egghelp@efnet (KuNgFo0)
#
# Set the next line as the countdown msg you want to say
set countdown_msg "Its getting nearer - Blackpool get prepared - the nutters are on the way !!!"
# Set the next line as the channels you want to run in
set countdown_chans "#blackpool"
# Set the next line as the date to count down to (Month day time year)
set countdown_time "August 20 10:00:00 2004"
# Set the next line as the command you want to initiate the countdown update
set countdown_command "!countdown"

bind pub - $countdown_command pub_countdown
set countdown_time [clock scan $countdown_time]

putlog "*** Countdown.tcl 0.1 by #egghelp@efnet loaded"

proc pub_countdown {nick uhost hand chan arg} {
 global countdown_msg countdown_chans countdown_time
 if {([lsearch -exact [string tolower $countdown_chans] [string tolower $chan]] != -1) || ($countdown_chans == "*")} {
  set countdown_diff [expr abs($countdown_time - [unixtime])]
  set countdown_secs $countdown_diff
  set countdown_mins [expr $countdown_diff / 60]
  set countdown_hours [expr $countdown_diff / 3600]
  set countdown_days [expr $countdown_diff / 86400]
  set countdown_secs [expr int($countdown_secs - (int($countdown_mins) * 60))]
  set countdown_mins [expr int($countdown_mins - (int($countdown_hours) * 60))]
  set countdown_hours [expr int($countdown_hours - (int($countdown_days) * 24))]
  set countdown_days [expr int($countdown_days)]
  if {$countdown_days > 0} {
   set countdown_temp "$countdown_days day"
   if {$countdown_days != 1} {
    append countdown_temp "s"
   }
  }
  if {$countdown_hours > 0} {
   lappend countdown_temp $countdown_hours hour
   if {$countdown_hours != 1} {
    append countdown_temp "s"
   }
  }
  if {$countdown_mins > 0} {
   lappend countdown_temp $countdown_mins minute
   if {$countdown_mins != 1} {
    append countdown_temp "s"
   }
  }
  if {$countdown_secs > 0} {
   lappend countdown_temp $countdown_secs second
   if {$countdown_secs != 1} {
    append countdown_temp "s"
   }
  }
  if {$countdown_time > [unixtime]} {
   putserv "PRIVMSG $chan :There are: $countdown_temp left till [ctime $countdown_time], $countdown_msg"
  } else {
   putserv "PRIVMSG $chan :There have been: $countdown_temp since [ctime $countdown_time], $countdown_msg"
  }
 }
}
User avatar
Stealthx
Halfop
Posts: 68
Joined: Fri Oct 01, 2004 3:37 am
Location: StealthBox

Post by Stealthx »

gb wrote:yay, bloatware. something like this should do it

Code: Select all

set when "August 20 00:00:00 2005"
set why "my birthday!"

bind pub - !birthday pub:countdown
proc pub:countdown {nick uhost hand chan text} {
 global when why
  set dur [expr [clock scan $when]-[clock seconds]]
  putquick "PRIVMSG $chan :There's [duration $dur] until $why"
}
I've used this countdown coding but anyone got any idea how could I let this TCL to only allow 1-2minutes per public trigger? (!birthday) so that it could prevent my bottie to get excess flood if there's any troublemaker keep pulling the trigger.

Meaning that the trigger would only activate after 1-2 minutes later after the previous countdown.

::01:26:00:: <user> !birthday
::01:26:01:: <bot> There's 11 hours 9 minutes 6 seconds until XXX, xxth of xxx
::01:26:02:: <user> !birthday
::01:26:02:: <bot> Please pull the trigger after 1-2 minutes.
::01:27:03:: <user> !birthday
::01:27:04:: <bot> There's 11 hours 8 minutes 6 seconds until XXX, xxth of xxx
+ Stealth Box +
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

That would be the exact same effect. The bot would say, Please wait 2 minutes everytime and excess flood all the same.
Locked