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 comparison

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

arfer wrote:I think the regexp I have used would be correct in all circumstances.

Code: Select all

set limit [lindex [split [string trim [lindex [split [getchanmode $chan] l] 1]]] 0]
Note: that is a lowercase L during the [split] on [getchanmode]. It is not the numeral 1.

This works almost as well as your regexp with the same common problem. If the channel is keyed and contains any digits, your regexp will pick this up instead as k comes before l. In my version it will pick up the entire key regardless of digits or not. Yours will fail on a key with digits, mine will fail with a key period.. HAW

There is probably a simple way to extract just the limit but may require more than a single line of code. Need to get an if in there to perform some manipulation depending upon circumstances (presence of +k)...

Code: Select all

-- in channel #test
* speechles sets mode: +l 1337
* speechles sets mode: +k 31337

-- in partyline
<speechles> .tcl regexp -- {\+[^\-]+l ([0-9]+)} [getchanmode #test] -> limit
<bot> Tcl: 1
<speechles> .tcl set test $limit
<bot> Tcl: 31337
<speechles> .tcl set test  [lindex [split [string trim [lindex [split [getchanmode #test] l] 1]]] 0]
<bot> Tcl: 31337
Basically, it needs this code:

Code: Select all

set place 0
if {[string match "*k*" [lindex [split [getchanmode #test] l] 0]]} { incr place }
set limit [lindex [split [string trim [lindex [split [getchanmode #test] l] 1]]] $place]
This should work with a key now and in all situations. *crosses fingers* ;)

Code: Select all

-- in partyline
<speechles> .tcl set place 0
<bot> Tcl: 0
<speechles> .tcl if {[string match "*k*" [lindex [split [getchanmode #test] l] 0]]} { incr place }
<bot> Tcl: 1
<speechles> .tcl set limit [lindex [split [string trim [lindex [split [getchanmode #test] l] 1]]] $place]
<bot> Tcl: 1337
<speechles> YAY!!
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Ok thanks. It was my IRC knowledge that let me down, though I don't doubt there must be a regexp that would do the trick no matter how complex the compounded modes get.

Code: Select all

regexp -- {\+[^\-]+k?l([\s].+)? ([0-9]+)} [getchanmode $chan] -> key limit
The above seems to work as long as there is no other mode appearing between k and l
I must have had nothing to do
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Just to answer the original poster, I think the following will now work in all circumstances (all that I can test anyway).

Code: Select all

bind JOIN - * pLimitJoin
bind MODE - "% +l" pLimitChange

proc pLimitJoin {nick uhost hand chan} {
    if {[isbotnick $nick]} {
        utimer 10 [list pLimitCheck $chan]
    }
    return 0
}

proc pLimitCheck {chan} {
    global vLimitOld
    regexp -- {^[^-\s]+k?l([\s][^-\s]+)?[\s]([0-9]+)} [getchanmode $chan] -> dummy vLimitOld($chan)
    return 0
}

proc pLimitChange {nick uhost hand chan mode target} {
    global vLimitOld
    if {([info exists vLimitOld($chan)]) && ([string length $vLimitOld($chan)] != 0)} {
        if {$vLimitOld($chan) != $target} {
            putlog "limit change in $chan from $vLimitOld($chan) to $target"
        }
    }
    set vLimitOld($chan) $target
    return 0
}

# eof
I must have had nothing to do
n
neoclust
Halfop
Posts: 55
Joined: Fri Aug 14, 2009 11:03 am

Post by neoclust »

Thanks a lot arfer and Speechless the code works
Post Reply