This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Peak in choosen channel

Help for those learning Tcl or writing their own scripts.
Post Reply
s
starpossen
Op
Posts: 139
Joined: Tue Jan 10, 2006 1:08 am

Peak in choosen channel

Post by starpossen »

I found this script on an old backup cd:

Code: Select all

bind PUB fo|fo -peak pub:peak
bind JOIN -|- *  join:peak

setudef str peak-data
setudef flag peak

proc pub:peak {nickname hostname handle channel arguments} {
  if {![channel get $channel peak]} {return}
  if {[set peakdata [channel get $channel peak-data]] == ""} {
    puthelp "PRIVMSG $channel :No peak data available yet (try rejoining)."
  } else {
    puthelp "PRIVMSG $channel :Peak for $channel: [lindex $peakdata 3] (by [lindex $peakdata 0]![lindex $peakdata 1] at [clock format [lindex $peakdata 2] -format {%d/%m/%y %H:%M:%S}])"
  }
}

proc join:peak {nickname hostname handle channel} {
  if {[channel get $channel peak]} {
    if {[set peakdata [channel get $channel peak-data]] == ""} {
      channel set $channel peak-data [list $nickname $hostname [clock seconds] [llength [chanlist $channel]]]
    } elseif {[lindex $peakdata 3] < [llength [chanlist $channel]]} {
      channel set $channel peak-data [list $nickname $hostname [clock seconds] [llength [chanlist $channel]]]
      # if you want to announce there is a new peak, do it here (just remove the comment)
      puthelp "PRIVMSG $channel :New peak ([llength [chanlist $channel]]) by $nickname!"
    }
  }
}
It works and all, but i'd like to define channels in which to use it
is that hard to make it do so?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

It kinda already does that, using .chanset. If you meant a static channel list, you can use the changes below.

Code: Select all

#change
setudef flag peak 
#into
variable peakchanlist "#chan1 #chan2 #etc" ;#space delimited

#change
if {![channel get $channel peak]} {return}
#into
if {![lsearch -exact [split $::peakchanlist] $channel]} {return}

#change 
if {![channel get $channel peak]} {
#into
if {[lsearch -exact [split $::peakchanlist] $channel]} {
s
starpossen
Op
Posts: 139
Joined: Tue Jan 10, 2006 1:08 am

Post by starpossen »

I tried that and it seemed to work, so thank you
one thing that bothers me, is the output:

Code: Select all

<bot> Peak for #channel: 30 (by nick !host@hots.host at 08/05/08 02:48:57)
I don't like the idea of it showing the host, I just want nick and date/time, I tried removing the host part in the script, but once again realized that i'm no pro scripter, so the bot crashed, any idea of which line to edit/remove to make it only show nick and date/time?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

#change
puthelp "PRIVMSG $channel :Peak for $channel: [lindex $peakdata 3] (by [lindex $peakdata 0]![lindex $peakdata 1] at [clock format [lindex $peakdata 2] -format {%d/%m/%y %H:%M:%S}])" 
#into either
#1) gives 'nick at date' as reply.
puthelp "PRIVMSG $channel :Peak for $channel: [lindex $peakdata 3] (by [lindex $peakdata 0] at [clock format [lindex $peakdata 2] -format {%d/%m/%y %H:%M:%S}])"
#or
#2) gives 'nick duration ago' as reply, this is a better replacement.
puthelp "PRIVMSG $channel :Peak for $channel: [lindex $peakdata 3] (by [lindex $peakdata 0] [duration [expr [unixtime] - [lindex $peakdata 2]]] ago)"
s
starpossen
Op
Posts: 139
Joined: Tue Jan 10, 2006 1:08 am

Post by starpossen »

Number 2 is absolutly what I wanted, thanks alot for the help, and the quick replys.

So I guess there's nothing more to add to this script, or do you have any additions or ideas?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

starpossen wrote:Number 2 is absolutly what I wanted, thanks alot for the help, and the quick replys.

So I guess there's nothing more to add to this script, or do you have any additions or ideas?
A throttle mechanism to keep clueless users from repeating the command several thousand times (+f/o users can be clueless and yes i noticed you restricted binding to just those flags ;))
User has written a great one that could easily be incorporated.
s
starpossen
Op
Posts: 139
Joined: Tue Jan 10, 2006 1:08 am

Post by starpossen »

Somewhat a flood-control, let's say users can't use the peak command twice in a row, a 30 second denial of usage, to prevent spam/flood, could be very usefull, in case of flagged users getting a bit to hyper with the command.

And yes I know I can restrict the command so only I can use it, but still, a flood-control kinda thing would be great.

*EDIT* maybe i'm to tired, but it looks like I kinda repeated what you wrote, except my text looks confusing.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

To add it, copy the steps below. :lol:

Code: Select all

# code provided by user via egghelp forums
# url @ http://forum.egghelp.org/viewtopic.php?t=9009&start=3
proc throttled {id seconds} {
   global throttle
   if {[info exists throttle($id)]&&$throttle($id)>[clock sec]} {
      set id 1
   } {
      set throttle($id) [expr {[clock sec]+$seconds}]
      set id 0
   }
}
# delete expired entries every 10 minutes
bind time - ?0* throttledCleanup
proc throttledCleanup args {
   global throttle
   set now [clock sec]
   foreach {id time} [array get throttle] {
      if {$time<=$now} {unset throttle($id)}
   }
} 
Add the above to bottom of the script (in it's entirety without changing anything, user deserves credit). Then make the change below, that's it.

Code: Select all

#change
if {![lsearch -exact [split $::peakchanlist] $channel]} {return}
#into
if {[throttled $hostname,$channel 30] || ![lsearch -exact [split $::peakchanlist] $channel]} {return}
This allows one trigger per "!ident@hostname,#channel" every 30 seconds. If instead you think once public in channel is enough, use the code below.

Code: Select all

#into
if {[throttled $channel 30] || ![lsearch -exact [split $::peakchanlist] $channel]} {return}
Once every 30 seconds per channel, regardless of who why or what triggered it.
s
starpossen
Op
Posts: 139
Joined: Tue Jan 10, 2006 1:08 am

Post by starpossen »

Ofcourse i'll keep the script unchanged which you posted so credits are where they should be, and also it works very nicely, thanks for all your help, and especially the very quick reply's.
Post Reply