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
Thank You willyw, the script works well!willyw wrote:Experiment with this:
Try this.Stefano1990 wrote:Is possible to show time & date of each citty country via request
!time berlin de
!time ny us
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
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
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
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
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
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."
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