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.

help needed for my script

Old posts that have not been replied to for several years.
Locked
s
seroal
Voice
Posts: 3
Joined: Tue Nov 09, 2004 7:26 am

help needed for my script

Post by seroal »

Code: Select all

bind pub - !bans pub:banes
proc pub:banes { nick uhost handle chan arg } {
if { [isop $nick $chan] || [ishalfop $nick $chan] || [isvoice $nick $chan] } {
set channel $chan
	if { $arg!="" } {
		set channel $arg
	}
set banli [chanbans $channel]
set banes 0
	foreach x $banli {
		set banner [lindex [split [split [lindex [split [lindex [split $x] 1] !] 0] \]] |] 0]
			if { [lsearch [lrange [split $banes] 1 end] $banner]==-1 } {
				set banes "$banes $banner"
				putlog [lrange [split $banes] 1 end]"
				set banarray($banner) 1
			} else {
				set banarray($banner) [expr $banarray($banner)+1]
				putlog "$banarray($banner)"
			}
	}
set listabaneador [lrange [split $banes] 1 end]
set textofin 0
putlog "longitud de baneado [llength $listabaneador]"
for { set i 0 } { $i<[llength $listabaneador] } { incr i } {
	if { $i==[expr [llength $listabaneador]-1] } {
		set textofin "$textofin y $banarray([lindex $listabaneador $i]) son de [lindex $listabaneador $i]. " 
	} else {
		set textofin "$textofin, $banarray([lindex $listabaneador $i]) son de [lindex $listabaneador $i]" 
		putlog "$textofin"
	}
}
set final [lrange [split $textofin] 1 end]
set text [join $final]
putlog "$text"
putserv "PRIVMSG $chan :There is [llength $banli] bans of 100 posible en in the channel $channel from which $text"
}
}

This is one of the scripts i made to count the number of bans in a chan and sum the bans made by each op in that chan. The problem is when i have a nick with special chars. Normaly the [ ] chars. For exemple, if i have a nick like [test] , it'll return:
{\\\{\\\[test\\} {{}} and then ..
Tcl error [pub:banes]: can't read "banarray(\{\[test)": no such element in array
i've tried reading all posts but i still don't know how i could solve it.. sorry if this as already been treated in other post but i'de apreciate some help. thx for all :) (sorry for my bad scripting .. :lol: )
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Try to use this proc to clean it

Code: Select all

  proc clean {i} {
    regsub -all -- \\\\ $i \\\\\\\\ i
    regsub -all -- \\\[ $i \\\\\[ i
    regsub -all -- \\\] $i \\\\\] i
    regsub -all -- \\\} $i \\\\\} i
    regsub -all -- \\\{ $i \\\\\{ i
    return $i
  }
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

MeTroiD wrote:Try to use this proc to clean it

Code: Select all

  proc clean {i} {
    regsub -all -- \\\\ $i \\\\\\\\ i
    regsub -all -- \\\[ $i \\\\\[ i
    regsub -all -- \\\] $i \\\\\] i
    regsub -all -- \\\} $i \\\\\} i
    regsub -all -- \\\{ $i \\\\\{ i
    return $i
  }
this could work, but it's not the proper way to approach that common problem of inexperienced scripters; there's a nice article in the FAQ section explaining how to deal with that issue; in essence, you shouldn't use certain list operation on strings before splitting the string into a proper list - no need of "cleaning", just use [split] and [join] wisely

@seroal:
instead of building rather ugly-looking nested lindex/split constructs, use this to divide nick!user@host into variables:

Code: Select all

scan $who %\[^!\]!%\[^@\]@%s nick user host
Locked