countdown.tcl
#1
Hello coders,

good day to all, this tcl is working perfect.  

Can someone help me to fix the autoshow message in the channel every 4 hours?
I've added a bind cron, but it is not working. i am not sure if i do it correctly.

And also, can we add it on autotopic every midnight?

Thank you in advance.

TCL
###############################################
# 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 "#christmas"
# Set the next line as the date to count down to (Month day time year)
set countdown_time "December 25 12:00:00 2023"
# Set the next line as the command you want to initiate the countdown update
set countdown_command "!countdown"
 
bind cron - "?0 *" pub_countdown:cron
 
bind pub - $countdown_command pub_countdown:cron
 
set countdown_time [clock scan $countdown_time]
proc pub_countdown:cron {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"
  }
 }
}
putlog "*** Countdown.tcl 0.1 by #egghelp@efnet loaded"


Répondre Avertir
#2
You try to call a proc designed for a public command with a cron, it can't work, the proc won't get the required arguments.
You can try to replace your bind with the following one and it associated proc:
TCL
bind cron - "00 */4 * * *" cron_countdown
proc cron_countdown {min hour day month dow} {
   pub_countdown $::botnick "bot@127.0.0.1" $::botnick countdown_chans ""
}



This will work if countdown_chans has only one channel, if you want to use several ones, the proc must become:
TCL
proc cron_countdown {min hour day month dow} {
   foreach chan [split $::countdown_chans] {
      pub_countdown $::botnick "bot@127.0.0.1" $::botnick $chan ""
   }
}


Répondre
#3
i got this error

Code :
Tcl error [cron_countdown]: can't read "botnick": no such variable



sorrry, i am still studying and learning with the codes.
Répondre Avertir
#4
I've edited my previous code (I made a typo and reproduce it).
You have to use $::botnick and not $botnick in the procedures
Répondre


Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)
Tchat 100% gratuit -Discutez en toute liberté