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.

prevent public command abuse with a timer on a user

Help for those learning Tcl or writing their own scripts.
Post Reply
C
CyBaH
Voice
Posts: 3
Joined: Mon Aug 06, 2007 1:53 pm
Location: emmen, The Netherlands
Contact:

prevent public command abuse with a timer on a user

Post by CyBaH »

Hi all,

I tried to use the search function but could not really find the right search keywords i assume.

I am having the problem that ppl are able to use a trigger(public command like !test) at any moment.
I would like to let my bot look if the user allready used the !test trigger in the last for example 1 minute.

any suggestions where to search / how to add it ?

Code: Select all

bind pub -|- !test test:test
proc test:test {nick uhost hand channel arg} {
putserv "PRIVMSG $channel : text i want to send by trigger"
}
so again..bot has to remember the user allready used the trigger in the last minute.

I must say i have some tcl knowledge but this i could not find.

Thanks and i hope i wrote in the correct forum

CyBaH
[/code]
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Simplest way, I suppose, would be to save a timestamp for the last time each user used the command. You'd probably have to use handle-names or implement some method of keeping track of who's who (nickchanges, etc).
As one later on triggers the command, check wether the timestamp is old enough to determine wether it should be permitted or not.
NML_375
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Search the forum for the keyword 'throttled'.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Sir_Fz wrote:Search the forum for the keyword 'throttled'.
I think that old proc is ready for an upgrade:

Code: Select all

proc throttled {id time} { 
	global throttled 
	if {[info exists throttled($id)]} { 
		return 1 
	} { 
		set throttled($id) [utimer $time [list unset throttled($id)]]
		return 0 
	} 
}
...making better use of the variable - That way, you can clean things up a little easier, if you ever need to:

Code: Select all

proc killthrottle id {
	global throttled
	if {[info exists throttled($id)]} {
		killutimer $throttled($id)
		unset throttled($id)
	}
}
Have you ever read "The Manual"?
B
BoaR
Halfop
Posts: 48
Joined: Fri Jul 20, 2007 1:36 am

Post by BoaR »

This should work also..

Code: Select all

#set time in seconds to wait after the user can use the command.
set antiflood "10"
variable flood

proc {} {
if {![info exists flood($chan)]} {set flood($chan) 0}
if {[unixtime] - $flood($chan) <= $antiflood} {return}
set flood($chan) [unixtime]

code here...
}
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

BoaR wrote:This should work also..

Code: Select all

#set time in seconds to wait after the user can use the command.
set antiflood "10"
variable flood

proc {} {
if {![info exists flood($chan)]} {set flood($chan) 0}
if {[unixtime] - $flood($chan) <= $antiflood} {return}
set flood($chan) [unixtime]

code here...
}
Try to follow what your code does and see if it is what CyBaH wants.

Here's an example using user's proc:

Code: Select all

bind pub -|- !test test:test
proc test:test {nick uhost hand channel arg} {
 if {![throttled $uhost:$channel 60]} {
  putserv "PRIVMSG $channel : text i want to send by trigger"
 }
}

proc throttled {id time} {
   global throttled
   if {[info exists throttled($id)]} {
      return 1
   } {
      set throttled($id) [utimer $time [list unset throttled($id)]]
      return 0
   }
}
This allows using !test only once every 60 seconds for user@host on every channel.
C
CyBaH
Voice
Posts: 3
Joined: Mon Aug 06, 2007 1:53 pm
Location: emmen, The Netherlands
Contact:

Post by CyBaH »

Much thanks for the replies, i will try to implant it and see how it works

much thanks so far

CyBaH
HappY
C
CyBaH
Voice
Posts: 3
Joined: Mon Aug 06, 2007 1:53 pm
Location: emmen, The Netherlands
Contact:

Post by CyBaH »

much thanks again

it works great o/

CyBaH
Post Reply