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.

a anti-flood script !

Help for those learning Tcl or writing their own scripts.
Post Reply
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

a anti-flood script !

Post by Riddler »

Hello all, I need some help with a little script, that puts a chan mode, like +m wen there is a mass use of ctcp and notices.

Here is the code:

Code: Select all

# flood.tcl

# Channel
set flood(chan) "#Finlanda"

# Numbers of flood's in X second's 
set flood(nr) 5:2

# Channel Lock Modes
set flood(clm) "m"

# Channel Lock Time
set flood(clt) 30

### END CFG ###

bind ctcp - * s:flood
bind NOTC - * s:flood

proc s:flood {nick host hand text chan key} {
 global botnick flood flood_host_count
   if {![validchan $chan] || [matchattr $hand of|of $chan] || [isop $nick $chan] || [isvoice $nick $chan]}  { return 0 }
   if {(([lsearch -exact [string tolower $flood(chan)] [string tolower $chan]] != -1) || ($flood(chan) == "*")) && (![matchat$
     if {[lsearch -exact $flood(chan) $chan] == -1} {
        return 0
     }
     if {![info exists flood_host_count($host:$chan)]} {
       set flood_host_count($host:$chan) 1
     } else {
       incr flood_host_count($host:$chan)
     }
     utimer [lindex $flood(nr) 1] "s:expire flood_host_count($host:$chan)"
     if {$flood_host_count($host:$chan) > [lindex $flood(nr) 0]} {
       putquick "MODE $chan +$flood(clm)"
       utimer $flood(clt) [list putquick "MODE $chan -$flood(clm)"]
     return 0
    }
  }
}

proc s:expire var_exp {
  upvar $var_exp var_pointer

  if {$var_pointer > 1} {
    incr var_pointer -1
  } else {
    unset var_pointer
  }
}

set flood(chan) [string tolower $flood(chan)]
set flood(nr) [split $flood(nr) :]

# clear variables and timers on rehash
if {[array exists flood_host_count]} {unset flood_host_count}
  foreach check_utimer [utimers] {
  if {[string match flood_host_count [lindex $check_utimer 1]]} {
    killutimer [lindex $check_utimer 2]
   }
}

putlog "TCL Loaded: flood.tcl"
and I get this error:

Code: Select all

 <|R0B0T> [04:15] Tcl error [s:flood]: wrong # args: should be "s:flood nick host hand text chan key"
And the channel dosen`t get "locked"

Any suggestion ?!
Last edited by Riddler on Sat May 26, 2007 11:21 pm, edited 1 time in total.
I am a man of few words, but many riddles
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

Code: Select all

NOTC (stackable)
bind notc <flags> <mask> <proc>
procname <nick> <user@host> <handle> <text> <dest>

CTCP (stackable)
bind ctcp <flags> <keyword> <proc>
proc-name <nick> <user@host> <handle> <dest> <keyword> <text>
What I think is, notc and ctcp can't be in 1 proc like you used in s:flood. I might be wrong, I will research on it.
|AmDeAtH @ Undernet
Death is only the *Beginning*...
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Worth noting is that your argument-list is not coherent with either binding (althugh the choice of names is pretty much up to the author, it might be a good idea to use names that are not misleading). Also, as has already been pointed out, the different bindings provide different number of arguments (and some of them different contents), which is why you get the error of wrong number of arguments.

You've got two options to fix this:
1. Use two different procs, one for each binding.
2. Modify the script to allow it to take multiple number of arguments (could be messy if you're not familiar with the actual script).

For option two, the first step would be to change the argument-list of s:flood, giving "key" a default value if the parameter is not used. This is done by changing the item with a list containing the variable name and the default value. (something like below:)

Code: Select all

proc s:flood {nick host hand text chan {key ""}} {
You probably then have to modify other parts of the script to handle the cases where key was not present, which will require some understanding of the mechanics of the actual script...

There is a second version of option two, wich would make use of the special variable-name "args", which will allow your proc to handle an arbitrary number of arguments. In this case, each argument provided to the proc will be added to args as a list-item.
Ex:

Code: Select all

proc s:flood {nick host hand args} {
 switch [llength $args] {
  2 {
   set text [lindex $args 0]
   set dest [lindex $args 1]
   set type "notc"
  }
  3 {
   set text [lindex $args 2]
   set dest [lindex $args 0]
   set keyword [lindex $args 1]
   set type "ctcp"
  }
 }
 default {error "Wrong number of arguments!"}
 ...
}
In this case, dest would either be the channel the event took place, or your bot's own nickname (would require some test using isbotnick). text and key would be text written, and if available, the ctcp keyword. Be aware that in the case of a notice, key will not be set and any attempts to read it will cause an error.
NML_375
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Heres something you can do off with. It bans for flood messages:
Channel text/actions/notices

Code: Select all

set chantexttrigger "5:3"

bind pubm - "*" text:flood
bind ctcp - ACTION action:flood
bind notc - "*" notice:flood

proc text:flood {nick uhost hand chan text} {
 text:flood:delay $nick $uhost $hand $chan $text "Text"
}

proc action:flood {nick uhost hand dest keyword text} {
 if {[isbotnick $dest]} { return 0 }
 if {[string equal "#" [string index $dest 0]] && [string match "#*" $dest]} {
  text:flood:delay $nick $uhost $hand $dest $text "Action"
  }
}

proc notice:flood {nick uhost hand text {dest ""}} {
 if {[isbotnick $dest] || [string equal "ChanServ" $nick] || [string equal "NickServ" $nick] || [string equal "MemoServ" $nick] || ($nick == "")} { return 0 }
 if {[string equal "@" [string index $dest 0]] && [string equal "#" [string index $dest 1]]} { return 0 }
 if {[string equal "#" [string index $dest 0]] && [string match "#*" $dest]} {
  text:flood:delay $nick $uhost $hand $dest $text "Notice"
  }
}

proc text:flood:delay {nick uhost hand chan text type} {
 global chantexttrigger chantextflood
 if {[isbotnick $nick] || ![botisop $chan] || [isop $nick $chan] || [isvoice $nick $chan] || [string equal "awyeah" $nick]} { return 0 }
 if {[string match -nocase "#*" $chan]} {
 set user [string tolower $nick:$chan]
 if {![info exists chantextflood($user)]} {
  set chantextflood($user) 0
 }
 utimer [lindex [split $chantexttrigger :] 1] [list text:flood:list $user]
 if {[incr chantextflood($user)] >= [lindex [split $chantexttrigger :] 0]} {
   putquick "MODE $chan +b *!*@[lindex [split $uhost @] 1]"
   putquick "KICK $chan $nick :0,1 Channel $type Flood 12,0 - You 2typed6 [lindex [split $chantexttrigger :] 0] lines 2or more 12within6 [lindex [split $chantexttrigger :] 1] secs. 12Please 2slow down 12your 2typing speed, 12this isn't a 2typing contest."
   timer 60 [list putquick "MODE $chan -b *!*@[lindex [split $uhost @] 1]"]
    if {[info exists chantextflood($user)]} { unset chantextflood($user) }
    }
  }
}

proc text:flood:list u {
 global chantextflood
 if {[info exists chantextflood($u)]} { incr chantextflood($u) -1 }
}
You can add the lock by placing a putserv or putquick mode followed by the lockmode in the channel which you desire. And the unlock can be also placed by using a utimer or timer along with a putserv or putquick command embedded within a list argument, as in your script.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
YooHoo
Owner
Posts: 939
Joined: Thu Feb 13, 2003 10:07 pm
Location: Redwood Coast

Post by YooHoo »

Am I missing something, or doesn't all these functions already exist in sentinel.tcl?
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

YooHoo wrote:Am I missing something, or doesn't all these functions already exist in sentinel.tcl?
They do indeed and all minus the ridiculous mIRC colours (by the looks of that post).

It appears people still do not know how to write code correctly.

Colour and formatting codes
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Well yeah, the normal mirc color formating codes work exactly the same with TCL, hence I don't bother using \002 for bold, when I can use a smaller character . :D
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

awyeah wrote:Well yeah, the normal mirc color formating codes work exactly the same with TCL, hence I don't bother using \002 for bold, when I can use a smaller character . :D
The point is cross platform compatibility and conforming to the pre-existing set standards.

Proper coding doesn't include anything like (non-standard) mIRC inclusions. These forums also exist to teach users the correct method(s) of Tcl scripting which, to my mind, the aforementioned code does not.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

YooHoo wrote:Am I missing something, or doesn't all these functions already exist in sentinel.tcl?
Indeed they exist in sentinel.tcl, but I have some other scripts that handle the banning of excessive CTCP actions, or notices or other types ....and I wanted to add a help-script to help the other script handle the bans without having floods on channel :) :lol:

so, I`ll take some advice from iamdeath, nml375 and awyeah and see if I can make the script to work :D

Thanks for the suggestion guys, I`ll place a later post with the result.
I am a man of few words, but many riddles
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Also worth noting, is that bloating a script with all kind of control-characters, ascii-graphics, extensive "cool texts", and so forth, only takes the focus away from the actual code constructs, and really makes poor learning-examples..

When a single line of code wraps around three lines, it gets really hard to read that code, and makes me wonder if all that really is needed to illustrate the concept.
NML_375
Post Reply