| View previous topic :: View next topic |
| Author |
Message |
Riddler Halfop
Joined: 20 May 2007 Posts: 60 Location: Brasov, Romania
|
Posted: Sat May 26, 2007 10:23 pm Post subject: a anti-flood script ! |
|
|
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: | # 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: | | <|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 ?! _________________ I am a man of few words, but many riddles
Last edited by Riddler on Sat May 26, 2007 11:21 pm; edited 1 time in total |
|
| Back to top |
|
 |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Sat May 26, 2007 10:30 pm Post subject: |
|
|
| Code: | 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*... |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sun May 27, 2007 11:35 am Post subject: |
|
|
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: | | 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: | 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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
awyeah Revered One

Joined: 26 Apr 2004 Posts: 1580 Location: Switzerland
|
Posted: Sun May 27, 2007 8:36 pm Post subject: |
|
|
Heres something you can do off with. It bans for flood messages:
Channel text/actions/notices
| Code: |
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.
================================== |
|
| Back to top |
|
 |
YooHoo Owner

Joined: 13 Feb 2003 Posts: 939 Location: Redwood Coast
|
Posted: Sun May 27, 2007 9:14 pm Post subject: |
|
|
Am I missing something, or doesn't all these functions already exist in sentinel.tcl? _________________
Johoho's TCL for beginners
 |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Sun May 27, 2007 9:39 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
awyeah Revered One

Joined: 26 Apr 2004 Posts: 1580 Location: Switzerland
|
Posted: Sun May 27, 2007 9:49 pm Post subject: |
|
|
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 .  _________________ ·awyeah·
==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
================================== |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Sun May 27, 2007 10:37 pm Post subject: |
|
|
| 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 .  |
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 |
|
| Back to top |
|
 |
Riddler Halfop
Joined: 20 May 2007 Posts: 60 Location: Brasov, Romania
|
Posted: Tue May 29, 2007 9:10 am Post subject: |
|
|
| 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
so, I`ll take some advice from iamdeath, nml375 and awyeah and see if I can make the script to work
Thanks for the suggestion guys, I`ll place a later post with the result. _________________ I am a man of few words, but many riddles |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue May 29, 2007 9:53 am Post subject: |
|
|
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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|