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.

Check if a user is inside a specific channel

Help for those learning Tcl or writing their own scripts.
Post Reply
b
boehmi
Voice
Posts: 14
Joined: Sat Apr 11, 2009 7:55 am
Location: Germany

Check if a user is inside a specific channel

Post by boehmi »

As the title says i want to check if a nickname is inside a specific channel
but i have absolutely no idea how to do this or what i have to look for ;)

Can you help me?

Thank you
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

You need to elaborate a little.

The code required to establish if a nickname is on one of the same IRC channels as the bot is easy.

onchan <nick> ?channel?

However, finding out if a nickname is on any specific IRC channel (or indeed online at all) is rather more difficult. It would require sending a network /WHOIS and interpreting the appropriate RAW responses.
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 »

Code: Select all

# whoischan.tcl

# functions in any IRC bot channel where colour output is allowed
# note that a user will appear not to be in a channel if the channel mode is +s (secret) unless the bot is on the same channel

# syntax (assuming default command trigger !)

# !channel <nick> ?#channel?

# !channel <nick> without the optional ?#channel? returns all the channels <nick> is on
# !channel <nick> ?#channel? confirms whether <nick> is on that specific ?#channel? or not

# set here the time allowed in seconds for a response to the network /WHOIS
set vChanWhoisTime 20

# set here the command trigger
set vChanWhoisTrigger !

proc pChanWhoisTrigger {} {
    global vChanWhoisTrigger
    return $vChanWhoisTrigger
}

bind PUB - [pChanWhoisTrigger]channel pChanWhoisSend

bind RAW - 312 pChanWhoisInfo
bind RAW - 402 pChanWhoisOffline
bind RAW - 319 pChanWhoisChannels
bind RAW - 318 pChanWhoisEnd

proc pChanWhoisCancelUtimer {} {
    foreach item [utimers] {
        if {[string equal pChanWhoisTimeout [lindex $item 1]]} {
            killutimer [lindex $item 2]
        }
    }
    return 0
}

proc pChanWhoisCancelWhois {} {
    global vChanWhoisSourceNick vChanWhoisTargetNick vChanWhoisSourceChan vChanWhoisTargetChan vChanWhoisResult
    if {[info exists vChanWhoisSourceNick]} {unset vChanWhoisSourceNick}
    if {[info exists vChanWhoisTargetNick]} {unset vChanWhoisTargetNick}
    if {[info exists vChanWhoisSourceChan]} {unset vChanWhoisSourceChan}
    if {[info exists vChanWhoisTargetChan]} {unset vChanWhoisTargetChan}
    if {[info exists vChanWhoisResult]} {unset vChanWhoisResult}
    return 0
}

proc pChanWhoisChannels {from keyword text} {
    global vChanWhoisTargetNick vChanWhoisResult
    if {[info exists vChanWhoisTargetNick]} {
        set target [lindex [split [stripcodes bcruag $text]] 1]
        if {[string equal -nocase $target $vChanWhoisTargetNick]} {
            set vChanWhoisResult [string trimleft [join [lrange [split [stripcodes bcruag $text]] 2 end]] :]
        }
    }
    return 0
}

proc pChanWhoisEnd {from keyword text} {
    global vChanWhoisSourceChan vChanWhoisTargetChan vChanWhoisSourceNick vChanWhoisTargetNick vChanWhoisResult
    if {[info exists vChanWhoisTargetNick]} {
        set target [lindex [split [stripcodes bcruag $text]] 1]
        if {[string equal -nocase $target $vChanWhoisTargetNick]} {
            if {[info exists vChanWhoisResult]} {
                switch -- [string length $vChanWhoisTargetChan] {
                    0 {putserv "PRIVMSG $vChanWhoisSourceChan :($vChanWhoisSourceNick) (\00310whois\003) .. channels for $vChanWhoisTargetNick are $vChanWhoisResult"}
                    default {
                        set vChanWhoisResult [regsub -all -- {[+@]} $vChanWhoisResult ""]
                        if {[lsearch -exact [split [string tolower $vChanWhoisResult]] [string tolower $vChanWhoisTargetChan]] != -1} {
                            putserv "PRIVMSG $vChanWhoisSourceChan :($vChanWhoisSourceNick) (\00310whois\003) .. $vChanWhoisTargetNick is on $vChanWhoisTargetChan"
                        } else {putserv "PRIVMSG $vChanWhoisSourceChan :($vChanWhoisSourceNick) (\00310whois\003) .. $vChanWhoisTargetNick is not on $vChanWhoisTargetChan"}
                    }
                }
            } else {putserv "PRIVMSG $vChanWhoisSourceChan :($vChanWhoisSourceNick) (\00310whois\003) .. $vChanWhoisTargetNick is online but not on any channels"}
            pChanWhoisCancelWhois
        }
    }
    return 0
}

proc pChanWhoisInfo {from keyword text} {
    global vChanWhoisTargetNick
    if {[info exists vChanWhoisTargetNick]} {
        set target [lindex [split [stripcodes bcruag $text]] 1]
        if {[string equal -nocase $target $vChanWhoisTargetNick]} {
            pChanWhoisCancelUtimer
        }
    }
    return 0
}

proc pChanWhoisOffline {from keyword text} {
    global vChanWhoisSourceNick vChanWhoisTargetNick vChanWhoisSourceChan
    if {[info exists vChanWhoisTargetNick]} {
        set target [lindex [split [stripcodes bcruag $text]] 1]
        if {[string equal -nocase $target $vChanWhoisTargetNick]} {
            putserv "PRIVMSG $vChanWhoisSourceChan :($vChanWhoisSourceNick) (\00304error\003) .. $vChanWhoisTargetNick is not online"
            pChanWhoisCancelUtimer
            pChanWhoisCancelWhois
        }
    }
    return 0
}

proc pChanWhoisSend {nick uhost hand chan text} {
    global vChanWhoisSourceChan vChanWhoisTargetChan vChanWhoisSourceNick vChanWhoisTargetNick vChanWhoisTime
    set arguments [string trim $text]
    switch -- [llength [split $arguments]] {
        1 {set vChanWhoisTargetChan ""}
        2 {set vChanWhoisTargetChan [lindex [split $arguments] 1]}
        default {
            putserv "PRIVMSG $chan :($nick) (\00304error\003) .. correct syntax is [pChanWhoisTrigger]channel <nick> ?#channel?"
            return 0
        }
    }
    set vChanWhoisTargetNick [lindex [split $arguments] 0]
    if {[regexp -- {^[\x41-\x7D][-\d\x41-\x7D]*$} $vChanWhoisTargetNick]} {
        if {([string length $vChanWhoisTargetChan] == 0) || ([regexp -- {^#} $vChanWhoisTargetChan])} {
            set vChanWhoisSourceNick $nick
            set vChanWhoisSourceChan $chan
            putserv "WHOIS $vChanWhoisTargetNick $vChanWhoisTargetNick"
            utimer $vChanWhoisTime pChanWhoisTimeout
        } else {putserv "PRIVMSG $chan :($nick) (\00304error\003) .. $vChanWhoisTargetChan is not a valid channel name"}
    } else {putserv "PRIVMSG $chan :($nick) (\00304error\003) .. $vChanWhoisTargetNick is not a valid nick"}
    return 0
}

proc pChanWhoisTimeout {} {
    global vChanWhoisSourceNick vChanWhoisTargetNick vChanWhoisSourceChan
    putserv "PRIVMSG $vChanWhoisSourceChan :($vChanWhoisSourceNick) (\00304error\003) .. whois operation timed out awaiting channel info for $vChanWhoisTargetNick"
    pChanWhoisCancelWhois
    return 0
}

# eof
I must have had nothing to do
Post Reply