| View previous topic :: View next topic |
| Author |
Message |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Wed Jan 19, 2005 9:21 am Post subject: something like this? |
|
|
| Code: | 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)}
}
}
|
...or using timers to do the cleanup
| Code: | proc throttled {id time} {
global throttled
if {[info exists throttled($id)]} {
return 1
} {
set throttled($id) [clock sec]
utimer $time [list unset throttled($id)]
return 0
}
} |
example limiting usage by same user@host on a specific channel
(the id part can be what ever you like of course)
| Code: | bind pub n !test pub:test
proc pub:test {n u h c a} {
if {[throttled $u,$c 30]} {
puthelp "PRIVMSG $c :$n: denied. (wait or try a different channel)"
} else {
puthelp "PRIVMSG $c :$n: allowed (wait 30 seconds)"
}
} |
_________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
Sibelius Voice
Joined: 18 Jan 2005 Posts: 3
|
Posted: Wed Jan 19, 2005 5:05 pm Post subject: |
|
|
User,
Many Thanks for your very complete solution ! |
|
| Back to top |
|
 |
|