egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[SOLVED] Date | time | Unix time
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
m4s
Halfop


Joined: 30 Jan 2017
Posts: 97

PostPosted: Tue Aug 20, 2019 3:10 pm    Post subject: [SOLVED] Date | time | Unix time Reply with quote

Hello! Smile

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 Smile
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
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1193

PostPosted: Wed Aug 21, 2019 1:17 am    Post subject: Re: Date | time | Unix time Reply with quote

Experiment with this:

Code:


# 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. Smile

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 !
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1193

PostPosted: Wed Aug 21, 2019 1:29 am    Post subject: Re: Date | time | Unix time Reply with quote

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 !
Back to top
View user's profile Send private message
m4s
Halfop


Joined: 30 Jan 2017
Posts: 97

PostPosted: Wed Aug 21, 2019 1:30 pm    Post subject: Re: Date | time | Unix time Reply with quote

willyw wrote:
Experiment with this:


Thank You willyw, the script works well! Smile
Back to top
View user's profile Send private message
Stefano1990
Voice


Joined: 04 Jun 2018
Posts: 25

PostPosted: Sun Sep 15, 2019 9:02 pm    Post subject: Hello Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1193

PostPosted: Tue Sep 24, 2019 4:53 pm    Post subject: Re: Hello Reply with quote

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.
Smile
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:


# 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 !
Back to top
View user's profile Send private message
heartbroken
Op


Joined: 23 Jun 2011
Posts: 110
Location: somewhere out there

PostPosted: Wed Sep 25, 2019 8:59 am    Post subject: Reply with quote

looks ugly and simple but I guess it can be used as an alternative.
Code:
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 -- {&raquo;} $str \003\u00bb\00304 str
   regsub -all -- {&nbsp;} $str { } str
   regsub -all -- {\s+} $str { } str
   return $str
}

setudef flag wtime



_________________
Life iS Just a dReaM oN tHE wAy to DeaTh
Back to top
View user's profile Send private message
Dominatez
Halfop


Joined: 14 Jan 2019
Posts: 49
Location: United Kingdom

PostPosted: Sun Oct 06, 2019 7:12 am    Post subject: Reply with quote

Script works lovely heartbroken. Always well coded.

Might want to add

.chanset #channelname +wtime

Just for the newer people who are still learning.
Back to top
View user's profile Send private message
blameshift
Voice


Joined: 27 Mar 2017
Posts: 12

PostPosted: Wed Oct 23, 2019 12:37 am    Post subject: Reply with quote

Thanks HeartBroken Great Script as always
Back to top
View user's profile Send private message
Arnold_X-P
Master


Joined: 30 Oct 2006
Posts: 226
Location: DALnet - Trinidad - Beni - Bolivia

PostPosted: Sun Nov 14, 2021 12:29 am    Post subject: Reply with quote

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:
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:


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 -- {&raquo;} $str \003\u00bb\00304 str
   regsub -all -- {&nbsp;} $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:
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:
[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:
[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:
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
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
heartbroken
Op


Joined: 23 Jun 2011
Posts: 110
Location: somewhere out there

PostPosted: Sun Nov 14, 2021 10:28 am    Post subject: Reply with quote

Code:
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 -- {&raquo;} $str \003\u00bb\00304 str
   regsub -all -- {&nbsp;} $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
Back to top
View user's profile Send private message
Goga
Halfop


Joined: 19 Sep 2020
Posts: 83

PostPosted: Mon Nov 15, 2021 1:21 am    Post subject: Nothing compares to what I have endured Reply with quote

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.
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1145
Location: France

PostPosted: Mon Nov 15, 2021 3:15 am    Post subject: Reply with quote

Did you do a .chanset #yourchannel +wtime ?
_________________
Eggdrop community - French IRC network
Back to top
View user's profile Send private message Visit poster's website
heartbroken
Op


Joined: 23 Jun 2011
Posts: 110
Location: somewhere out there

PostPosted: Mon Nov 15, 2021 5:09 am    Post subject: Reply with quote

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à!


_________________
Life iS Just a dReaM oN tHE wAy to DeaTh


Last edited by heartbroken on Mon Nov 15, 2021 7:22 am; edited 1 time in total
Back to top
View user's profile Send private message
Goga
Halfop


Joined: 19 Sep 2020
Posts: 83

PostPosted: Mon Nov 15, 2021 5:45 am    Post subject: [SOLVED] Date | time | Unix time Reply with quote

Job Done!!
Thanks you too heartbroken & CrazyCat
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber