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 

Timespent Script

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Mon Jan 28, 2013 6:11 pm    Post subject: Timespent Script Reply with quote

For any ideas for improving the code
For any bugs or questions please post here

Code:

#### ++++ Author: MadaliN <madalinmen28@yahoo.com>
### +++ Website: www.Ascenture.ro
## +++ TCL Name: Timespent
# +++ Version: 1.0
#
# Commands:
#   !timespent activate         (local or global owner)
#   !timespent deactivate         (local or global owner)
#   !timespent <$nickname> <$chan>      (local or global owner)
#

####
# +++ Created: 1/26/2013
####

bind TIME - * egghelp:timespent

bind PUB - !timespent timespent:pub

set announce(time) "1" ;#setting is in hours

setudef flag timespent

proc egghelp:timespent {min hour day month year} {
   global timespent announce noa

   set list ""
   foreach chan [channels] {
      if {[channel get $chan timespent]} {
         foreach u [chanlist $chan] {

            set host [lindex [split [getchanhost $u $chan] @] 1]

            if {![info exists timespent($chan,$host)]} {
               set timespent($chan,$host) "60 $u"
               timespent:save
            } else {
               set timespent($chan,$host) "[expr [lindex [split $timespent($chan,$host)] 0] + 60] $u"
               timespent:save

               if {$announce(time) != ""} {
                  if {[lindex [split $timespent($chan,$host)] 0] > [expr $announce(time) * 3600]} {
                     if {![info exists noa($chan,$host)]} {
                        set noa($chan,$host) "[unixtime]"
                        timespent:save

                        lappend list "\00303[lindex [split $timespent($chan,$host)] 1]\003"
                     }
                  }
               }
            }
         }
         if {$list != ""} {
            putserv "PRIVMSG $chan :Users who spent more than \00312$announce(time)\003 hour on \00304$chan\003 are: [join $list "\002,\002 "]"
         }
      }
   }
}

proc timespent:pub {nick uhost hand chan arg} {
   global timespent

   set host [lindex [split [getchanhost [lindex [split $arg] 0] $chan] @] 1]

   switch -exact -- [lindex [split $arg] 0] {
      activate {
         if {[matchattr $hand n] || [matchattr $hand |N $chan]} {
            channel set $chan +timespent

            putserv "PRIVMSG $chan :\002$nick\002 - TIMESPENT script \00312activated\003 succesfully"
         }
      }
      deactivate {
         if {[matchattr $hand n] || [matchattr $hand |N $chan]} {
            channel set $chan -timespent

            putserv "PRIVMSG $chan :\002$nick\002 - TIMESPENT script \00304deactivated\003 succesfully"
         }
      }
      default {
         if {[matchattr $hand n] || [matchattr $hand |N $chan]} {

            if {[string match -nocase "#*" [lindex [split $arg] 1]]} {
               if {![info exists timespent([lindex [split $arg] 1],$host)]} {
                  putserv "PRIVMSG $chan :\002$nick\002 - Nickname \00303[lindex [split $arg] 0]\003 has no info on \00312[lindex [split $arg] 1]"
               } else {
                  putserv "PRIVMSG $chan :\002$nick\002 - Nickname \00303[lindex [split $arg] 0]\003 idled on \00312[lindex [split $arg] 1]\003 for \00303[duration [lindex [split $timespent([lindex [split $arg] 1],$host)] 0]]"
               }
            } else {
               if {![info exists timespent($chan,$host)]} {
                  putserv "PRIVMSG $chan :\002$nick\002 - Nickname \00303[lindex [split $arg] 0]\003 has no info on this channel"
               } else {
                  putserv "PRIVMSG $chan :\002$nick\002 - Nickname \00303[lindex [split $arg] 0]\003 idled on \00312$chan\003 for \00303[duration [lindex [split $timespent($chan,$host)] 0]]"
               }
            }
         }
      }
   }
}

proc timespent:save {} {
   global timespent

   set ofile [open timespent w]
   puts $ofile "array set timespent [list [array get timespent]]"
   close $ofile
}

catch {source timespent}

putlog "+++ Succesfully loaded: \00312Timpespent TCL Script"

_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL


Last edited by Madalin on Tue Aug 06, 2013 7:19 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
x0x
Op


Joined: 10 Feb 2009
Posts: 140
Location: The Netherlands

PostPosted: Thu May 16, 2013 5:37 pm    Post subject: Reply with quote

Does it keep track of people even after they part/quit/split?
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Thu May 16, 2013 5:50 pm    Post subject: Reply with quote

It only keeps track if the user is seen in the channel
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
x0x
Op


Joined: 10 Feb 2009
Posts: 140
Location: The Netherlands

PostPosted: Thu May 16, 2013 6:12 pm    Post subject: Reply with quote

Would it be possible to write to a file and keep a record of a nicknames and their total time? So count when they are on and continue counting when they return after a quit or netsplit?
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Thu May 16, 2013 6:14 pm    Post subject: Reply with quote

This is how the script works now.
The eggdrop is counting (minute by minute) if the user is on the channel and writes the users with their idle time in a file (so it wont be lost)
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3583
Location: Mint Factory

PostPosted: Fri May 17, 2013 3:30 am    Post subject: Reply with quote

Shouldn't you should exclude the bot from adding itself to the list? Smile

The easiest way to do this would be with replacing:
Code:

foreach u [chanlist $chan] {

with this:
Code:

set userlist [lreplace [chanlist $chan] 0 0]
foreach u $userlist {


The time bind you got it's triggered every minute so it's a waste of resources when you could easily integrate the 1 hour check directly in the bind:
Code:

bind time {?0 *} gghelp:timespent


You have the timespent:save function called in like 3 places in the egghelp:timespent proc, why not have it just once?

In the timespent:pub proc why do you use matchattr to check user flags when you can bind the pub command directly in the bind line?
Code:

bind PUB n|N !timespent timespent:pub

or whatever..

I see you using [split $arg] for like 7 times in timespent:pub. Why don't you split it just once and use it from there on with just $arg?

If you want to keep track of since the user joined the channel, why don't you just use getchanjoin instead? The time bind would be triggered every 1 hour (or whatever) and get the info from there and announce the list. Seems more easier than keeping a list in memory, a list that has to be cleaned once the bot itself would quit, part, split, die, whatever.

Here's what I meant by that:
Code:

bind time {?0 *} announce:timespent

proc announce:timespent {min hour day month year} {
   foreach chan [channels] {
      if {![channel get $chan timespent]} continue
      set userlist [lreplace [chanlist $chan] 0 0]
      foreach user $userlist {
         set timestamp [getchanjoin $user $chan]
         if {[expr [unixtime] - $timestamp] < 3600} continue
         lappend list "$user $timestamp"
      }      
      set list [lsort -integer -index 1 $list]
      foreach ele $list {
         lappend users [lindex [split $ele] 0]
      }
      if {![info exists $users]} continue
      puthelp "PRIVMSG $chan :Users who spent more than 1 hour on $chan are:"
      while {[llength $users] != 0} {
         puthelp "PRIVMSG $chan :[join [lrange $users 0 14] ", "]"
         set users [lrange $users 15 end]
      }
   }
}

I've tested it in my head but not on an eggdrop. Rolling Eyes
_________________
I tawt I taw a puddy tat!
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Fri May 17, 2013 5:40 am    Post subject: Reply with quote

That is only the first version i know it can be improved but why improve something if its not constantly used. Maybe for sure thats the reason i didnt updated the script.

And exclude the bot from the list i would have done something like this
Code:
if {![isbotnick $var]} { .. }


and for the n|N flags at the !timespent command i didnt used the flags there because i used switch in that proc and i have more than 1 command in there so i could easy add a command for another flag and the list can continue
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases 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