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

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

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

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

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

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

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

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
Halfop


Joined: 23 Jun 2011
Posts: 96
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
Voice


Joined: 14 Jan 2019
Posts: 28
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: 9

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
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
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