egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Check if a user is inside a specific channel

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
boehmi
Voice


Joined: 11 Apr 2009
Posts: 14
Location: Germany

PostPosted: Tue Aug 18, 2009 8:38 am    Post subject: Check if a user is inside a specific channel Reply with quote

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 Wink

Can you help me?

Thank you
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Tue Aug 18, 2009 9:55 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Tue Aug 18, 2009 3:15 pm    Post subject: Reply with quote

Code:

# 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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
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


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber