05-28-2017, 04:47 +0200
AuthorPost
thommey  05-26-2005, 18:27   | [EGG] Join/Part a channel and spy out (aka Bot-Request) Jabber
(Administrator)
Member since 03/2004
62 Posts
                                                                                                                              
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
bind pub m !spychannel spychannel:init
proc spychannel:init {nick host hand chan text} {
    if {[set channel [string trim [lindex [split $text] 0]]] == "" || [string index $channel 0] != "#"} {
        putserv "PRIVMSG $chan :Syntax: $::lastbind <#channel>"
        return 0
    }
    channel add $channel
    set ::request_from_chan($channel) $chan
    set ::request_from_nick($channel) $nick
    return 1
}

#315 <botnick> <chan> :End of /WHO list.
bind raw - 315 spychannel:eow
proc spychannel:eow {from key text} {
    set channel [lindex [split $text] 1]
    if {![info exists ::request_from_chan($channel)]} {
        return 0
    }
    putserv "PRIVMSG $::request_from_chan($channel) :Hey $::request_from_nick($channel), on $channel are [llength [chanlist $channel]] users. Modes are: [getchanmode $channel]."
    unset ::request_from_chan($channel)
    unset ::request_from_nick($channel)
    channel remove $channel
    return 0
}

thommey  02-05-2009, 21:31   | Tcl8.6 coroutine-solution: Jabber
(Administrator)
Member since 03/2004
62 Posts
REQUIRES Tcl8.6!
Works without the use of global variables
                                                                                                                              
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package require Tcl 8.6
bind pub m !spychannel spychannel:init
proc spychannel:init {nick host hand chan text} {
    set channel [string tolower [lindex [split $text] 0]]
    if {[info commands spychannel_$channel] ne ""} {
        putserv "PRIVMSG $chan :Request already in progress for $channel"
        return 0
    }
    # init coroutine
    coroutine spychannel_$channel spychannel $nick $host $hand $chan $text
    return 1
}
proc spychannel {nick host hand chan text} {
    if {[set channel [lindex [split $text] 0]] == "" || [string index $channel 0] != "#"} {
        putserv "PRIVMSG $chan :Syntax: $::lastbind <#channel>"
        return 0
    }
    channel add $channel
    # pause the current procedure (to wait for raw 315)
    yield
    putserv "PRIVMSG $chan :Hey $nick, on $channel are [llength [chanlist $channel]] users. Modes are: [getchanmode $channel]."
    channel remove $channel
}
#315 <botnick> <chan> :End of /WHO list.
bind raw - 315 spychannel:eow
proc spychannel:eow {from key text} {
    set channel [lindex [split $text] 1]
    if {[info commands spychannel_$channel] ne ""} {
        # continue existing coroutine
        spychannel_$channel
    }
    return 0
}

This post was edited 4 times, last on 10-14-2009, 23:53 by thommey
Advanced options for this topic:

Ignore this topic (Do not list this topic in the "unread topics" search. You are currently not ignoring this topic.)
Hide this topic (Hidden topics are not displayed in the topics list. This topic is currently not hidden.)
Go to forum

Unclassified NewsBoard 1.5.3-d | © 2003-4 by Yves Goergen