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.

clock

Help for those learning Tcl or writing their own scripts.
User avatar
abi
Voice
Posts: 10
Joined: Mon Feb 12, 2024 1:11 am
Location: Kota Makassar

clock

Post by abi »

########################
#      ShareTime       #     
# -------------------  #
#   Date: 25-01-2018   #
#   Version: v0.6      #
#   Author(s): wie     #
########################

set sharetime(format) "%A %B %d %Y -- %H:%M:%S"
bind time - "00 * * * *" sharetime
bind pubm - *jam* sharetime_pub

setudef flag sharetime

proc sharetime {nick uhost hand chan arg} {
	global sharetime waktu
	foreach chan [channels] {
		if {[channel get $chan sharetime]} {
			replacetime
			puthelp "PRIVMSG $chan :$waktu"
		}
	}
}

proc sharetime_pub {nick uhost hand chan arg} {
	global sharetime otime waktu 
	set rtime [unixtime]
	if { $rtime - $otime  > 15} {
		replacetime
		puthelp "PRIVMSG $chan :$waktu"
		set otime $rtime
	}
}
set otime 0

proc replacetime { } {
global sharetime waktu
set arguments [clock format [clock seconds] -timezone :Asia/Makassar -format $sharetime(format)]
	set day [lindex [split $arguments] 0]
	if {$day == "Monday"} { set hari "\00312Senin\003" }
	if {$day == "Tuesday"} { set hari "\00312Selasa\003" }
	if {$day == "Wednesday"} { set hari "\00312Rabu\003" }
	if {$day == "Thursday"} { set hari "\00312Kamis\003" }
	if {$day == "Friday"} { set hari "\00303Jum'at\003" }
	if {$day == "Saturday"} { set hari "\00304Sabtu\003" }
	if {$day == "Sunday"} { set hari "\00304Ahad\003" }
	set tanggal [lindex [split $arguments] 2]
	set month [lindex [split $arguments] 1]
	if {$month == "January"} { set bulan "\00312Januari\003" }
	if {$month == "February"} { set bulan "\00313Februari\003" }
	if {$month == "March"} { set bulan "\00331Maret\003" }
	if {$month == "April"} { set bulan "\00303April\003" }
	if {$month == "May"} { set bulan "\00320Mei\003" }
	if {$month == "June"} { set bulan "\00325Juni\003" }
	if {$month == "July"} { set bulan "\00337Juli\003" }
	if {$month == "August"} { set bulan "\00304Agustus\003" }
	if {$month == "September"} { set bulan "\00309September\003" }
	if {$month == "October"} { set bulan "\00310Oktober\003" }
	if {$month == "November"} { set bulan "\00322November\003" }
	if {$month == "December"} { set bulan "\00304Desember\003" }
	set tahun [lindex [split $arguments] 3]
	set jam [lindex [split $arguments] 5]

	set waktu "Hari $hari, Tanggal64 $tanggal $bulan55 $tahun, Jam12 $jam WITA"
}

putlog "\002SHARETIME:\002 ShareTime.tcl 0.6 by wie is loaded."
Can this script be made into AM or PM time?
Last edited by CrazyCat on Mon Feb 12, 2024 3:35 am, edited 1 time in total.
Reason: replace quote with tcl tags
Online
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: clock

Post by CrazyCat »

(Moderation : replaced quote tag with tcl tag)

Yes, you can easily by changing sharetime(format)
set sharetime(format) "%A %B %d %Y -- %I:%M:%S %p"
Reference: https://www.tcl.tk/man/tcl8.5/tutorial/Tcl41.html
User avatar
abi
Voice
Posts: 10
Joined: Mon Feb 12, 2024 1:11 am
Location: Kota Makassar

Re: clock

Post by abi »

CrazyCat wrote: Mon Feb 12, 2024 3:39 am (Moderation : replaced quote tag with tcl tag)

Yes, you can easily by changing sharetime(format)
set sharetime(format) "%A %B %d %Y -- %I:%M:%S %p"
Reference: https://www.tcl.tk/man/tcl8.5/tutorial/Tcl41.html
thanks @CrazyCat work fine
p
pektek
Halfop
Posts: 51
Joined: Sat Jul 01, 2023 4:51 pm

Re: clock

Post by pektek »

15 minutes time is not working my friend

Code: Select all

if { $rtime - $otime  > 15} {
or

Code: Select all

bind time - "00 * * * *" sharetime
I don't know which one
Online
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: clock

Post by CrazyCat »

Your bind time is used to run when minutes are exactly 0.
Documentation wrote:
bind time <flags> <mask> <proc>

procname <minute 00-59> <hour 00-23> <day 01-31> <month 00-11> <year 0000-9999>
Description: allows you to schedule procedure calls at certain times. mask matches 5 space separated integers of the form: “minute hour day month year”. The month var starts at 00 (Jan) and ends at 11 (Dec). Minute, hour, day, month have a zero padding so they are exactly two characters long; year is four characters. Flags are ignored.
https://docs.eggheads.org/using/tcl-commands.html#binds

If you want it runs every 15 minutes, 2 ways:
1. have 4 bind time (00, 15, 30 and 45). Not the best imho
2. use a bind cron:
bind cron - "*/15 * * * *" sharetime
And change your sharetime proc definition, because you actually use definition of a pub proc:
proc sharetime {min hour day month dow} {
p
pektek
Halfop
Posts: 51
Joined: Sat Jul 01, 2023 4:51 pm

Re: clock

Post by pektek »

:?:
Using cron gave an error
error message



bad type, should be one of: act, away, bcst, bot, chat, chjn, chof, chon, chpt, ctcp, ctcr, dcc, disc, evnt, filt, flud, join, kick, link, load, mode, msg, msgm, need, nick, nkch, notc, note, part, pub, pubm, raw, rejn, sign, splt, time, topc, unld, wall
while executing
"bind cron - "*/15 * * * *" sharetime"
Online
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: clock

Post by CrazyCat »

Which version of eggdrop do you use ? Pretty old I guess.
Update your eggdrop to 1.9.5

Or use the 1st solution I gave (4 bind time)
p
pektek
Halfop
Posts: 51
Joined: Sat Jul 01, 2023 4:51 pm

Re: clock

Post by pektek »

I upgraded the version but it gives this error

can't read "replacetime": no such variable
while executing
"set otime $replacetime"
(procedure "sharetime_pub" line 7)
invoked from within
"sharetime_pub $_pubm1 $_pubm2 $_pubm3 $_pubm4 $_pubm5"
Last edited by pektek on Sun Mar 17, 2024 11:34 am, edited 1 time in total.
Online
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: clock

Post by CrazyCat »

https://www.eggheads.org/download/

Take care that your config file may not be compatible with 1.9.5, you'll probably have to redo it
p
pektek
Halfop
Posts: 51
Joined: Sat Jul 01, 2023 4:51 pm

Re: clock

Post by pektek »

I upgraded the version but it gives this error

Tcl error [sharetime_pub]: can't read "replacetime": no such variable
can't read "replacetime": no such variable
while executing
"set otime $replacetime"
(procedure "sharetime_pub" line 7)
invoked from within
"sharetime_pub $_pubm1 $_pubm2 $_pubm3 $_pubm4 $_pubm5
Online
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: clock

Post by CrazyCat »

Pastebin your full script, the previous code you post doesn't have any line looking like "set otime $replacetime"
p
pektek
Halfop
Posts: 51
Joined: Sat Jul 01, 2023 4:51 pm

Re: clock

Post by pektek »

Sorry
2 min timer

[19:46:00] triggering bind sharetime
[19:46:00] triggered bind sharetime, user 0.029ms sys 0.008ms

When 2 minutes expire, privmsg does not show on the channel
Everything is fine but the timer did not show the channel

Code: Select all

########################
#      ShareTime       #     
# -------------------  #
#   Date: 25-01-2018   #
#   Version: v0.6      #
#   Author(s): wie     #
########################

set sharetime(format) "%A %B %d %Y -- %I:%M:%S %p"
bind cron - "*/2 * * * *" sharetime
bind pubm - *jam* sharetime_pub

setudef flag sharetime

proc sharetime {min hour day month dow} {
	global sharetime waktu
	foreach chan [channels] {
		if {[channel get $chan sharetime]} {
			replacetime
			puthelp "PRIVMSG $chan :$waktu"
		}
	}
}

proc sharetime_pub {nick uhost hand chan arg} {
	global sharetime otime waktu 
	set rtime [unixtime]
	if { $rtime - $otime  > 2} {
		replacetime
		puthelp "PRIVMSG $chan :$waktu"
		set otime $rtime
	}
}
set otime 0

proc replacetime { } {
global sharetime waktu
set arguments [clock format [clock seconds] -timezone :Asia/Makassar -format $sharetime(format)]
	set day [lindex [split $arguments] 0]
	if {$day == "Monday"} { set hari "\00312Senin\003" }
	if {$day == "Tuesday"} { set hari "\00312Selasa\003" }
	if {$day == "Wednesday"} { set hari "\00312Rabu\003" }
	if {$day == "Thursday"} { set hari "\00312Kamis\003" }
	if {$day == "Friday"} { set hari "\00303Jum'at\003" }
	if {$day == "Saturday"} { set hari "\00304Sabtu\003" }
	if {$day == "Sunday"} { set hari "\00304Ahad\003" }
	set tanggal [lindex [split $arguments] 2]
	set month [lindex [split $arguments] 1]
	if {$month == "January"} { set bulan "\00312Januari\003" }
	if {$month == "February"} { set bulan "\00313Februari\003" }
	if {$month == "March"} { set bulan "\00331Maret\003" }
	if {$month == "April"} { set bulan "\00303April\003" }
	if {$month == "May"} { set bulan "\00320Mei\003" }
	if {$month == "June"} { set bulan "\00325Juni\003" }
	if {$month == "July"} { set bulan "\00337Juli\003" }
	if {$month == "August"} { set bulan "\00304Agustus\003" }
	if {$month == "September"} { set bulan "\00309September\003" }
	if {$month == "October"} { set bulan "\00310Oktober\003" }
	if {$month == "November"} { set bulan "\00322November\003" }
	if {$month == "December"} { set bulan "\00304Desember\003" }
	set tahun [lindex [split $arguments] 3]
	set jam [lindex [split $arguments] 5]

	set waktu "Hari $hari, Tanggal64 $tanggal $bulan55 $tahun, Jam12 $jam WITA"
}

putlog "\002SHARETIME:\002 ShareTime.tcl 0.6 by wie is loaded."
Online
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: clock

Post by CrazyCat »

Well, I don't understand what your really expecting.

Can you just describe, in simple words, what the script must do ? Just tell the time (in your language) every x minutes on channels where it's activated ?
And the public command is used to force the script to say the time on the current channel ?
p
pektek
Halfop
Posts: 51
Joined: Sat Jul 01, 2023 4:51 pm

Re: clock

Post by pektek »

Just tell the time (in your language) every x minutes on channels where it's activated ?
Yes

When 2 minutes expire, privmsg does not show on the channel.
Online
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: clock

Post by CrazyCat »

Try this:
setudef flag sharetime
set sharetime(format) "%A %B %d %Y -- %I:%M:%S %p"


proc sharetime {min hour day month dow} {
   set now [clock format [clock seconds] -timezone :Asia/Makassar -format $::sharetime(format)]
   foreach chan [channels] {
		if {[channel get $chan sharetime]} {
			puthelp "PRIVMSG $chan :[i18ndate $now]"
		}
	}
}

proc sharetime_pub {nick uhost handle chan text} {
   puthelp "PRIVMSG $chan :[i18ndate [clock format [clock seconds] -timezone :Asia/Makassar -format $::sharetime(format)]]"
}

proc i18ndate {date} {
   return [string map {\
      "Monday" "\00312Senin\003" "Tuesday" "\00312Selasa\003" "Wednesday" "\00312Rabu\003" "Thursday" "\00312Kamis\003" "Friday" "\00303Jum'at\003" "Saturday" "\00304Sabtu\003" "Sunday" "\00304Ahad\003" \
      "January" "\00312Januari\003" "February" "\00313Februari\003" "March" "\00331Maret\003" "April" "\00303April\003" "May" "\00320Mei\003" "June" "\00325Juni\003" \
      "July" "\00337Juli\003" "August" "\00304Agustus\003" "September" "\00309September\003" "October" "\00310Oktober\003" "November" "\00322November\003" "December" "\00304Desember\003"} $date]
}

bind cron - "*/2 * * * *" sharetime
bind pubm - "*jam*" sharetime_pub
Not tested, but might be better
Post Reply