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.

[SOLVED] Date | time | Unix time

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
User avatar
m4s
Halfop
Posts: 97
Joined: Mon Jan 30, 2017 3:24 pm

[SOLVED] Date | time | Unix time

Post by m4s »

Hello! :)

I would like to have a script to my egg, which shows the current date and time and unix time if I use the !date command.

Example:
!date
The current date is 2019-08-20 | 20:00:00 | 1566331200

I would like to activate this script via DCC with .chattr #channel +time.
The date format is: YYYY-mm-dd | HH:mm:ss | unix time <-bold :)
I would like to set the timezone in the script like in the config file (Europe/Berlin).
Would be greet a flood protection as well.

Can anyone help?
Last edited by m4s on Wed Aug 21, 2019 1:31 pm, edited 1 time in total.
w
willyw
Revered One
Posts: 1196
Joined: Thu Jan 15, 2009 12:55 am

Re: Date | time | Unix time

Post by willyw »

Experiment with this:

Code: Select all


# August 20, 2019
#
# http://forum.egghelp.org/viewtopic.php?t=20656
#
##
#
# Usage:
# To enable on a given chan :  .chanset #channel +saytime
# To disable on a given chan:  .chanset #channel -saytime
#
# Public command to display time:   !date
#
###


###
namespace eval pubdatetime {
###




####   Configuration ####

# Set the time zone here  ( Use only one active line. Leave others commented out.  Or - comment them all out and add your own new line
#  ( reference: http://www.tcl.tk/man/tcl8.6/TclCmd/clock.htm#M78
#  ( Note : On the system that this script was built on, this command:   ls -latr /usr/share/zoneinfo     would list useful info tor this.
#variable t_zone "America/New_York"
#variable t_zone "GMT"
variable t_zone "Europe/Berlin"


# Set the number of seconds duration of throttling
variable throttle_secs "30"


####   End configuration ###


#
#
#


bind pub - "!date" pubdatetime::say_date

setudef flag saytime



###
###
proc say_date {nick uhost handle chan text } {
variable t_zone
variable throttle_secs

        if {![channel get $chan saytime]} {
                return 0
        }

        # throttling - found here: http://forum.egghelp.org/viewtopic.php?t=9009#45537

        if {[throttled $uhost,$chan $throttle_secs]} {
                putserv "PRIVMSG $chan :$nick: denied. ( wait [lindex [lsearch -inline  [utimers] *$uhost,$chan*] 0] seconds )"
        } else {
               putserv "privmsg $chan :The current date is: [clock format [clock seconds] -format {%Y-%m-%d | %H:%M:%S} -timezone :$t_zone] \002[clock seconds]\002"

        }

}
###
###
# procedure for throttling
# reference:  http://forum.egghelp.org/viewtopic.php?t=9009#45537
proc throttled {id time} {
variable throttled

   if {[info exists throttled($id)]} {
      return 1
   } {
      set throttled($id) [clock seconds]
      utimer $time [list unset [namespace current]::throttled($id)]
      return 0
   }
}


}
# end namespace pubdatetime

Tested briefly. Works for me.

I am not a real wizard with time zones, but I tried.

I believe it is dependent on other things installed on the system. Perhaps somebody else here can comment on that for you.
If it was a script for my own use, I would probably just use the
date command on the command line of the shell and find the system time. Then I'd code it to do the difference, mathmatically - and not use TCL's timezone stuff.
Anyway - it seem to work fine. Again, that is on the system that I built it on. Let us know how it goes, on your system. :)

There are a couple of very long lines of code. Be sure that when you copy from here, that your editor does't line wrap them.

I hope this helps.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
w
willyw
Revered One
Posts: 1196
Joined: Thu Jan 15, 2009 12:55 am

Re: Date | time | Unix time

Post by willyw »

I now notice that I either read too quick, or didn't pay attention, or I'm tired... or something... and that only unixtime is bolded in the text posted to the channel. It appears that you wanted the whole line bolded.

I'm sure you can find it, in the code, and edit it.

Here's a nice reference for colors, bold, etc. :
http://tclhelp.net/#faqcolor

Don't try to fix it, *before* you get it running as-is.
First, copy it, make your new tcl script file, check the very short Configuration section, and then source it.

Test it, in channel.

No need to worry about some cosmetic editing, if you don't get it running just like it is, first.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
User avatar
m4s
Halfop
Posts: 97
Joined: Mon Jan 30, 2017 3:24 pm

Re: Date | time | Unix time

Post by m4s »

willyw wrote:Experiment with this:
Thank You willyw, the script works well! :)
S
Stefano1990
Voice
Posts: 25
Joined: Mon Jun 04, 2018 10:07 am
Contact:

Hello

Post by Stefano1990 »

Is possible to show time & date of each citty country via request

!time berlin de
!time ny us
Use your common sense and try not to make me look too much like I know what I'm doing.
w
willyw
Revered One
Posts: 1196
Joined: Thu Jan 15, 2009 12:55 am

Re: Hello

Post by willyw »

Stefano1990 wrote:Is possible to show time & date of each citty country via request

!time berlin de
!time ny us
Try this.

You're probably going to really need this now:
ls -latr /usr/share/zoneinfo
on the shell command line.
:)
You have to know exactly what to ask for.

Some day I may play around, and try to come up with something that will create another command - to search those files and dirs, so the user can find out what is available.

If I get motivated to do so, and succeed, I'll post it here.

Code: Select all


# Septermber 24, 2019

# http://forum.egghelp.org/viewtopic.php?t=20656
# then:
# http://forum.egghelp.org/viewtopic.php?p=107828#107828
#
######
######

# Do:  .chaninfo #channel  
# and look for the value of saytime , to determine if the !date command is
# currently on or off, on #channel.
# Change it by using .chanset
#


###
namespace eval pubdatetime {
###




####   Configuration ####

# Set the number of seconds duration of throttling
variable throttle_secs "30"

####   End configuration ###



#######
#######
###########


bind pub - "!date" pubdatetime::say_date

setudef flag saytime



###
###
proc say_date {nick uhost handle chan text } {
variable throttle_secs

        if {![channel get $chan saytime]} {
                return 0
        }

        if {![llength [split $text]]} {
                putserv "privmsg $chan :Syntax: !date <country/city>"
                putserv "privmsg $chan :Capitalization matters!  and use underscores for spaces in names"
                putserv "privmsg $chan :A real working example:   !date America/New_York"
                return 0
        }



        set text [string trim $text]
        set t_zone [lindex [split $text] 0]


        # throttling - found here: http://forum.egghelp.org/viewtopic.php?t=9009#45537

        if {[throttled $uhost,$chan $throttle_secs]} {
                putserv "PRIVMSG $chan :$nick: denied. ( wait [lindex [lsearch -inline  [utimers] *$uhost,$chan*] 0] seconds )"
        } else {
                  if {[catch {clock format [clock seconds] -format {%Y-%m-%d | %H:%M:%S} -timezone ":$t_zone"}  resultvar optionsvar] } {
                        lassign $resultvar v1 v2 v3 v4 v5

                        set v3 [string trimleft $v3 :]
                        putserv "privmsg $chan :$v1 $v2 $v3 $v4 $v5"
                } else {
                        putserv "privmsg $chan : "
                        putserv "privmsg $chan :$resultvar"
                }
        }

}
###
###
# procedure for throttling
# reference:  http://forum.egghelp.org/viewtopic.php?t=9009#45537
proc throttled {id time} {
variable throttled

   if {[info exists throttled($id)]} {
      return 1
   } {
      set throttled($id) [clock seconds]
      utimer $time [list unset [namespace current]::throttled($id)]
      return 0
   }
}


}
# end namespace pubdatetime

For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

looks ugly and simple but I guess it can be used as an alternative.

Code: Select all

package require http

bind pub - .t worldntime

proc worldntime {nick uhost hand chan text} {
   if {![channel get $chan wtime]} { return 0 }
	if {![llength $text]} { puthelp "privmsg $chan :Usage: $::lastbind <location>"; return 0 }
	set token [http::geturl http://localtimes.mobi/search/?s=[join $text +]&x=0&y=0 -timeout 9000]
	set data [http::data $token]
	::http::cleanup $token
	if {[regexp -- {Home</a>(.+?)</span>.+?<div class="timeinfo">(.+?)</div>.+?<div class="tz_container">(.+?)</li>} $data - loc t1 t2]} {
		puthelp "privmsg $chan :\00304[cleanup $loc]\003: [cleanup $t1]"
		puthelp "privmsg $chan :[cleanup $t2]"
	} else { puthelp "privmsg $chan :No any information found for \"$text\". Please be more specific!"; return }
	return 0
}

proc cleanup str {
   regsub -all -- {(?:<label>|</label>)} $str \002 str
	regsub -all -- "<.+?>" $str " " str
	regsub -all -- {»} $str \003\u00bb\00304 str
	regsub -all -- { } $str { } str
	regsub -all -- {\s+} $str { } str
	return $str
}

setudef flag wtime
Image
Life iS Just a dReaM oN tHE wAy to DeaTh
User avatar
Dominatez
Halfop
Posts: 50
Joined: Mon Jan 14, 2019 5:08 pm
Location: United Kingdom

Post by Dominatez »

Script works lovely heartbroken. Always well coded.

Might want to add

.chanset #channelname +wtime

Just for the newer people who are still learning.
b
blameshift
Voice
Posts: 12
Joined: Mon Mar 27, 2017 4:24 am

Post by blameshift »

Thanks HeartBroken Great Script as always
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Post by Arnold_X-P »

heartbroken It is an excellent code but it needs to add words that link to other examples such as words from Spanish to English

I added to the tcl this route which will recognize a word in Spanish
example: (españa=spain) or (republica dominicana=Dominican Republic) in IRC: .t españa

Code: Select all

set text [string map [list México mexico japon japan granada Grenada españa Spain Japón japon italia Italy francia France egipto egypt rusia russia alemania germany chipre cyprus {republica dominicana} {Dominican Republic}] $text]

Code: Select all


bind pub - .t worldntime

proc worldntime {nick uhost hand chan text} {
   if {![channel get $chan wtime]} { return 0 }
	if {![llength $text]} { puthelp "privmsg $chan :Usage: $::lastbind <location>"; return 0 }
set text [string map [list México mexico japon japan granada Grenada españa Spain Japón japon italia Italy francia France egipto egypt rusia russia alemania germany chipre cyprus {republica dominicana} {Dominican Republic}] $text]
	set token [http::geturl http://localtimes.mobi/search/?s=[join $text +]&x=0&y=0 -timeout 9000]
	set data [http::data $token]
	::http::cleanup $token
	if {[regexp -- {Home</a>(.+?)</span>.+?<div class="timeinfo">(.+?)</div>.+?<div class="tz_container">(.+?)</li>} $data - loc t1 t2]} {
		puthelp "privmsg $chan :\00304[cleanup $loc]\003: [cleanup $t1]"
		puthelp "privmsg $chan :[cleanup $t2]"
	} else { puthelp "privmsg $chan :No any information found for \"$text\". Please be more specific!"; return }
	return 0
}

proc cleanup str {
   regsub -all -- {(?:<label>|</label>)} $str \002 str
	regsub -all -- "<.+?>" $str " " str
	regsub -all -- {»} $str \003\u00bb\00304 str
	regsub -all -- { } $str { } str
	regsub -all -- {\s+} $str { } str
	return $str
}

setudef flag wtime
What I added works well for me but I don't know if it will be fine like that, I would like you to review it please

Code: Select all

set text [string map [list México mexico japon japan granada Grenada españa Spain Japón japon italia Italy francia France egipto egypt rusia russia alemania germany chipre cyprus {republica dominicana} {Dominican Republic}] $text]

Code: Select all

[00:37] <@Arnold_X-P> .t spain
[00:37] <@Kantuta>  » Europe » Spain :  Current local time: 5:37:27 am Date: Sunday 14 November 2021 Time zone: CET (Central Europe Time) Current time zone offset: +01:00 hours 
[00:37] <@Kantuta>  Western Europe Time WET 31 Oct 2021 Sunday 31 Oct 2021 at 1:00:00 am local time to 27 Mar 2022 Sunday 27 Mar 2022 at 1:00:00 pm local time, the time changes to 2:00:00 am Offset: UTC +0:00 DST ended on 31 Oct 2021, clocks moved back 1 hour; from 2:00:00 am to 1:00:00 am 
and the linked variant from Spanish to English (spain= españa)

Code: Select all

[00:37] <@Arnold_X-P> .t españa
[00:37] <@Kantuta>  » Europe » Spain :  Current local time: 5:37:30 am Date: Sunday 14 November 2021 Time zone: CET (Central Europe Time) Current time zone offset: +01:00 hours 
[00:37] <@Kantuta>  Western Europe Time WET 31 Oct 2021 Sunday 31 Oct 2021 at 1:00:00 am local time to 27 Mar 2022 Sunday 27 Mar 2022 at 1:00:00 pm local time, the time changes to 2:00:00 am Offset: UTC +0:00 DST ended on 31 Oct 2021, clocks moved back 1 hour; from 2:00:00 am to 1:00:00 am 
Also if it is possible to add that when there is no internet connection the bot makes it known by means of a message to the channel.

Code: Select all

if {[string match -nocase "*couldn't open socket*" $error]} {
         puthelp "PRIVMSG $chan :Error: There is no internet connection .. Please try again later."
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

Code: Select all

package require http
package require tls 1.6.4

bind pub - .t worldntime

proc worldntime {nick uhost hand chan text} {
	if {![channel get $chan wtime]} { return 0 }
	if {![llength $text]} { puthelp "privmsg $chan :Usage: $::lastbind <location>"; return 0 }
	set TxT [YouGotTheSource https://translate.googleapis.com/translate_a/single?[http::formatQuery client gtx sl auto tl en dt t q $text]]
	if {[regexp -- {\"([^\"]+)\"} $TxT - transout]} { set query $transout } { set query $text }
	set data [YouGotTheSource http://localtimes.mobi/search/?[http::formatQuery s $query x 0 y 0]]
	if {[regexp -- {Home</a>(.+?)</span>.+?<div class="timeinfo">(.+?)</div>.+?<div class="tz_container">(.+?)</li>} $data - loc t1 t2]} {
		puthelp "privmsg $chan :\00304[cleanup $loc]\003: [cleanup $t1]"
		puthelp "privmsg $chan :[cleanup $t2]"
	} else { puthelp "privmsg $chan :No any information found for \"$text\". Please be more specific!"; return }
	return 0
}

proc cleanup str {
	regsub -all -- {(?:<label>|</label>)} $str \002 str
	regsub -all -- "<.+?>" $str " " str
	regsub -all -- {»} $str \003\u00bb\00304 str
	regsub -all -- { } $str { } str
	regsub -all -- {\s+} $str { } str
	return $str
}

proc YouGotTheSource URL {
	if {[catch {set token [http::geturl $URL -timeout 9000]} error]} {
		set err "Connection failor! [string map {\n " "} $error]"
	} elseif {[http::status $token] ne "ok" || [http::ncode $token] != "200"} {
		set err "[http::status $token] - [http::code $token]"
		::http::cleanup $token
	} else {
		set data [http::data $token]
		::http::cleanup $token
	}
	if {[info exists data] && [string length $data]} {
		return $data
	}
	if {[info exists err] && [string length $err]} {
		foreach _ [channels] { if {[channel get $_ wtime]} { puthelp "privmsg $_ :$err" }}
	}
}

::http::register https 443 [list ::tls::socket -ssl2 0 -ssl3 0 -tls1 1]

setudef flag wtime
You don't need to add anything anymore. This script translating your queries itself!
Life iS Just a dReaM oN tHE wAy to DeaTh
G
Goga
Halfop
Posts: 83
Joined: Sat Sep 19, 2020 2:12 am

Nothing compares to what I have endured

Post by Goga »

Mr. heartbroken, I don't know why this TCL Didn't work for me. It didn't show me any error .
Please suggest me anything to make it working.
User avatar
CrazyCat
Revered One
Posts: 1214
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Did you do a .chanset #yourchannel +wtime ?
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

I don't know what to say..
You only need to have TclTLS (I know you already have one.)
Source it into your .conf , connect to your bot + ( .rehash / .restart )
.chanset #channel +wtime (as CrazyCat said above.)
and voilà!

Image
Last edited by heartbroken on Mon Nov 15, 2021 7:22 am, edited 1 time in total.
Life iS Just a dReaM oN tHE wAy to DeaTh
G
Goga
Halfop
Posts: 83
Joined: Sat Sep 19, 2020 2:12 am

[SOLVED] Date | time | Unix time

Post by Goga »

Job Done!!
Thanks you too heartbroken & CrazyCat
Post Reply