mIRC Home    About    Download    Register    News    Help

Print Thread
#215811 08/10/09 04:42 PM
Joined: Oct 2008
Posts: 167
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Oct 2008
Posts: 167
basic e.g.
Code:
on *:TEXT:!command:#: {
   /msg # RESPONSE
}

Instead of..
Quote:
<user> !command
<bot> RESPONSE
<user> !command
<bot> RESPONSE
<user2> !command
<bot> RESPONSE


I would like...
Quote:
<user> !command
<bot> RESPONSE
<user2> !command
<bot> RESPONSE
<user> !command
<user2> !command


And to "block" the user from using the command for about a minute. But I would want the user to be able to use all the other commands, so not to be added to the ignore list.

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
The method I prefer is using a hash table to track responses:
Code:
on *:text:!command:#: {
  var %unset = 60, %limit = 3

  ; add to a TABLE "flood" the ITEM "<$cid><$chan><$nick><randomnumber>" with DATA "<dummy-char>". the item unsets after %unset seconds
  ; you might as well add items to the table tracking the user's hostmask instead of nicknames ("$site" instead of "$nick"), to bypass nickchanges and increase protection vs. clones
  hadd $+(-mu,%unset) flood $+($cid,$chr(1),$chan,$chr(1),$nick,$chr(1),$rand(1,9999)) x

  ; response only if the number of items matching <$cid><$chan><$nick>* is below %limit
  if ($hfind( flood, $+($cid,$chr(1),$chan,$chr(1),$nick,$chr(1),*) ,0,w) < %limit) {

    ; your response here
    msg # my response
  }
}


You might alternatively group all your !commands (triggers) into one on text event and use it as some "global" protection, like:
Code:
on *:text:*:#: {
  ; text is one of your commands
  if ($istok(!command1 !command2 !commandN,$1-,32)) {
    var %unset = 60, %limit = 3

    hadd $+(-mu,%unset) commands $+($cid,$chr(1),$chan,$chr(1),$nick,$chr(1),$rand(1,9999)) x
    if ($hfind( commands, $+($cid,$chr(1),$chan,$chr(1),$nick,$chr(1),*) ,0,w) < %limit) {

      ; your responses
      if ($1 == !command1) { msg # response 1 }
      elseif ($1 == !command2) { msg # response 2 }
      elseif ($1 == !commandN) { msg # response N }
    }
  }
}

The above code should give you a basic idea. You can extend this kind of protection with other wildmasks for $hfind(w) - some examples are in this thread smile

Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
And something I just whipped up:
Code:
alias triggerblock {
  if (!$($+(%,tb.,$1,$2),2)) { set -u60 %tb. $+ $1 $+ $2 1 }
  else { return 1 }
}

Now you add that alias to your on TEXT events for the triggers. E.g.
Code:
on *:TEXT:!command:#: {
  if (!$triggerblock($1,$nick)) { msg # RESPONSE }
}

You could extend the stuff that is checked for with other identifiers than the current $1 (the trigger) and $nick (the person triggering the on TEXT event), as Horstl suggested.

Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
That's all fine and great, I just dont like to use all the extra code. I believe when the data is an integer, variables are faster anyway.

Code:
on *:text:!command:#:{
;halt if user has already triggered this twice.
if (%com_ [ $+ [ $nick ] ] > 2) return

;msg response
msg # RE$PON$E

;inc a variable when they get a response. 
inc -u5 %com_ [ $+ [ $nick ] ]
}

Last edited by DJ_Sol; 08/10/09 07:41 PM.

Link Copied to Clipboard