| View previous topic :: View next topic |
| Author |
Message |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Fri Oct 05, 2007 5:46 am Post subject: calculating days |
|
|
I am trying to make a script for someone here but I am stuck in the middle I want to know how to calculate this:
| Code: | [14:32] -NickServ- Time registered : Thu 23-Sep-2004 01:00:59 UTC
[14:32] -NickServ- Time now : Fri 05-Oct-2007 09:31:06 UTC |
I want to calculate that how many days ago that nickname was registered from Time now. I mean the reply should come in days, let's say 12 20 45 days. So that then I can easily use if command if numbers are > 7 then body.
Thanks
iamdeath _________________ |AmDeAtH @ Undernet
Death is only the *Beginning*... |
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Fri Oct 05, 2007 6:11 am Post subject: |
|
|
| Code: | set then [clock scan "Thu 23-Sep-2004 01:00:59 UTC"]
set now [clock scan "Fri 05-Oct-2007 09:31:06 UTC"]
set secondsInADay 86400
set daysAgo [expr {($now-$then)/$secondsInADay}] |
_________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Fri Oct 05, 2007 12:20 pm Post subject: |
|
|
Thanks alot I will give it a try and let you know. _________________ |AmDeAtH @ Undernet
Death is only the *Beginning*... |
|
| Back to top |
|
 |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Sat Oct 06, 2007 1:32 am Post subject: |
|
|
| Code: | ### Event
bind join - "#channel *!*@*" join-ignore
bind notc - "*is not a valid nickname*" notice-ignore
bind notc - "*Time registered*" notice-ignore
bind notc - "*Time now*" notice-ignore
### Command
proc join-ignore {nick uhost handle chan} {
putquick "PRIVMSG nickserv@services.dal.net :info $nick"
}
proc notice-ignore {nick uhost hand text dest} {
if {[string match "*is not a valid nickname*" $text]} {return}
if {[string match "*Time registered*" $text]} {
set then [split $text]
set then [lrange $text 3 end]
putlog "$then Before"
}
if {[string match "*Time now*" $text]} {
set now [split $text]
set now [lrange $text 3 end]
putlog "$now After"
}
set then [clock scan "$then"]
set now [clock scan "$now"]
set secondsInADay 86400
set daysAgo [expr {($now-$then)/$secondsInADay}]
putlog "$daysAgo Days ago"
} |
This is just half of my code but at the moment I am getting this error:
| Code: | Thu 23-Sep-2004 01:00:59 UTC Before
Tcl error [notice-ignore]: can't read "now": no such variable
Sat 06-Oct-2007 05:16:15 UTC After
Tcl error [notice-ignore]: can't read "then": no such variable |
any suggestions please?
Thanks
iamdeath _________________ |AmDeAtH @ Undernet
Death is only the *Beginning*... |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Oct 06, 2007 3:53 pm Post subject: |
|
|
Rethink your code.
You only set "now" when the notice matches "Time now", and you only set "then" when the notice matches "Time registered". In both cases you extract the 4th and further words as the time.
Obviously, upon execution, only one of them will be set at any time, and thus trying to use them both as in | Code: | | set daysAgo [expr {($now-$then)/$secondsInADay}] | will fail.
What you'll have to do, is store the value inbetween invocations, and do proper cleanup once you've gathered all the data and produced the output. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Sun Oct 07, 2007 1:41 am Post subject: |
|
|
Thanks for the reply, but the thing is I have
| Code: | | set then [lrange $text 3 end] |
which is ==
| Code: | | Thu 23-Sep-2004 01:00:59 UTC Before |
So is the case with now I don't understand how to calculate more or store it within inbetween invocations, if you please give me a little hint more I will be thankful to you
Thanks
iamdeath _________________ |AmDeAtH @ Undernet
Death is only the *Beginning*... |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sun Oct 07, 2007 7:34 am Post subject: |
|
|
One way would be to use global variables, with proper cleanup inbetween requests... _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Sun Oct 07, 2007 2:36 pm Post subject: |
|
|
Ive tried all the possible ways it's too much for me sorry for bothering you. I just cant solve it on my own _________________ |AmDeAtH @ Undernet
Death is only the *Beginning*... |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
|
| Back to top |
|
 |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Tue Oct 09, 2007 1:17 am Post subject: |
|
|
Thanks rosc actually the script works well when I give it
| Code: | set then [clock scan "Thu 23-Sep-2004 01:00:59 UTC"]
set now [clock scan "Fri 05-Oct-2007 09:31:06 UTC"]
set secondsInADay 86400
set daysAgo [expr {($now-$then)/$secondsInADay}] |
but the problem is the date always has to get changed for ever user so iused $text and $now instead of any specific date. But it;'s not recognizing that variable I wonder why _________________ |AmDeAtH @ Undernet
Death is only the *Beginning*... |
|
| Back to top |
|
 |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Tue Oct 09, 2007 1:45 am Post subject: |
|
|
| Code: | ### Event
bind join - "#Islamabad *!*@*" join-ignore
bind notc - "*is not a valid nickname*" notice-ignore
bind notc - "*Time registered*" notice-ignore
bind notc - "*Time now*" notice-ignore
### Command
proc join-ignore {nick uhost handle chan} {
putquick "PRIVMSG nickserv@services.dal.net :info $nick"
}
proc notice-ignore {nick uhost hand text dest} {
if {[string match "*is not a valid nickname*" $text]} {return}
if {[string match "*Time registered*" $text]} {
set then [split $text]
set then [lrange $text 3 end]
set then [clock scan "$then"]
if {[string match "*Time now*" $text]} {
set now [split $text]
set now [lrange $text 3 end]
set now [clock scan "$now"]
set secondsInADay 86400
set daysAgo [expr {($now-$then)/$secondsInADay}]
putlog "$daysAgo Days ago"
}
}
}
putlog "Nickname ignore tcl Loaded!" |
I even tried that its not working  _________________ |AmDeAtH @ Undernet
Death is only the *Beginning*... |
|
| Back to top |
|
 |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Tue Oct 09, 2007 2:24 am Post subject: |
|
|
| Code: | ### Event
bind join - "#Islamabad *!*@*" join-ignore
bind notc - "*is not a valid nickname*" notice-ignore
bind notc - "*Time registered*" notice-ignore
bind notc - "*Time now*" notice-ignore1
### Command
proc join-ignore {nick uhost handle chan} {
putquick "PRIVMSG nickserv@services.dal.net :info $nick"
}
proc notice-ignore {nick uhost hand text dest} {
global then
set then [split $text]
set then [lrange $text 3 end]
set then [clock scan "$then"]
putlog "$then"
}
proc notice-ignore1 {nick uhost hand text dest} {
global now then
set now [split $text]
set now [lrange $text 3 end]
set now [clock scan "$now"]
set secondsInADay 86400
set daysAgo [expr {($now-$then)/$secondsInADay}]
putlog "$daysAgo Days ago"
putlog "$now"
}
putlog "Nickname ignore tcl Loaded!" |
That works fine  _________________ |AmDeAtH @ Undernet
Death is only the *Beginning*... |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Tue Oct 09, 2007 2:28 am Post subject: |
|
|
Usually you can set the time for "now" using the tcl 'clock' command, or the eggdrop strftime, ctime or unixtime commands, there's a few different ways to go about it, no real need to depend on chanserv to get it (although you might have to account for the different timezones between what your shell and [unixtime] and chanserv are using.
As far as how to keep the $then var across proc's, just declare it as a global var at the top of each proc that needs it.
Anyway, the logic in your script won't set the vars properly.
The errors you're getting is because this proc is being run for each and every notice the bot is receiving, so maybe nest all further processing under the 1st test for if {[string match "*Time registered*" $text]} {
eg:
| Code: |
proc notice-ignore {nick uhost hand text dest} {
if {[string match "*is not a valid nickname*" $text]} {return}
if {[string match "*Time registered*" $text]} {
set then [split $text]
set then [lrange $text 3 end]
set then [clock scan "$then"]
set now [unixtime]
putlog "debug then '$then'"
putlog "debug now '$now'"
set secondsInADay 86400
set daysAgo [expr {($now-$then)/$secondsInADay}]
putlog "someone registered $daysAgo Days ago"
}
}
|
One last piece of advice - INDENT YOUR CODE =)
Makes it much easier to debug.. |
|
| Back to top |
|
 |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Tue Oct 09, 2007 3:34 am Post subject: |
|
|
| rosc2112 wrote: | Usually you can set the time for "now" using the tcl 'clock' command, or the eggdrop strftime, ctime or unixtime commands, there's a few different ways to go about it, no real need to depend on chanserv to get it (although you might have to account for the different timezones between what your shell and [unixtime] and chanserv are using.
As far as how to keep the $then var across proc's, just declare it as a global var at the top of each proc that needs it.
Anyway, the logic in your script won't set the vars properly.
The errors you're getting is because this proc is being run for each and every notice the bot is receiving, so maybe nest all further processing under the 1st test for if {[string match "*Time registered*" $text]} {
eg:
| Code: |
proc notice-ignore {nick uhost hand text dest} {
if {[string match "*is not a valid nickname*" $text]} {return}
if {[string match "*Time registered*" $text]} {
set then [split $text]
set then [lrange $text 3 end]
set then [clock scan "$then"]
set now [unixtime]
putlog "debug then '$then'"
putlog "debug now '$now'"
set secondsInADay 86400
set daysAgo [expr {($now-$then)/$secondsInADay}]
putlog "someone registered $daysAgo Days ago"
}
}
|
One last piece of advice - INDENT YOUR CODE =)
Makes it much easier to debug.. |
Thank your very very much it solved the problem actually I was trying to help this user thought I would learn something out of it too and I did learn many things, thanks alot to all of you guys for your great support and patience to stand me love you guys
HELPED
Thanks once again
iamdeath _________________ |AmDeAtH @ Undernet
Death is only the *Beginning*... |
|
| Back to top |
|
 |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Tue Oct 09, 2007 4:51 am Post subject: |
|
|
Time registered: Mar 07 21:22:37 2006 EST
If the format is like that, should'nt it work? _________________ |AmDeAtH @ Undernet
Death is only the *Beginning*... |
|
| Back to top |
|
 |
|