Hi!
I have the following problem: i would like to add an public command, which would give the users in my channel the ability to let the bot join new channels (maximum is 10). The clue is, that these users mus be an OP in the channel, which the bot should join.
bind pub - "!+chan" ad:addchan
proc ad:addchan { nick host handle chan text } {
if {[isop $nick $text]} {
set i 0
foreach channel [channels] {
incr i 1
}
if {$i < 10} {
channel add $text
} else {
putserv "PRIVMSG $nick :Es tut mir leid, aber ich bin schon in zu vielen Channels!"
}
}
}
But everytime, i say this command followed by a channel (for example !+chan #kitchenhost-test) , the bot says (in the partyline):
bind pub - !+chan ad:addchan
proc ad:addchan { nick host handle chan text } {
channel add $text
utimer 5 [list channel:check $nick $text]
}
proc channel:check {nick text} {
if {[isop $nick $text]} {
set i 0
foreach channel [channels] {
incr i 1
}
if {$i > 10} {
channel remove $text
putserv "PRIVMSG $nick :exceeded maximum number of channels allowed"
} elseif {![isop $nick $text]} {
channel remove $text
putserv "PRIVMSG $nick :Es tut mir leid, aber ich bin schon in zu vielen Channels!"
}
}
}
bind pub - "!+chan" ad:addchan
bind raw - "319" ad:whois
proc ad:addchan { nick host handle chan text } {
putserv "WHOIS $nick"
}
proc ad:whois {from keyword text} {
set text [split $text]
set nick [lindex $text 1]
putserv "PRIVMSG Mangi :nick=$nick"
}
It works so far, but now the problem is, how i could "transfer" the variable $text from ad:addchan to ad:whois to check the right channel? But, if that works, without using global variables, i dont like them very much.
yes, that is, what i mean with "transfer", to have the value of $text also available in ad:whois. But is there a posibility to do that without using a global variable?
bind pub - "!+chan" ad:addchan
bind raw - "319" ad:whois
set ad_addchannel ""
proc ad:addchan { nick host handle chan text } {
global ad_addchannel
set ad_addchannel $text
putserv "WHOIS $nick"
}
proc ad:whois {from keyword text} {
global ad_addchannel
if {$ad_addchannel != ""} {
putserv "PRIVMSG [lindex $text 1] :Ich bearbeite momentan bereits eine Anfrage, bitte versuch es gleich nochmal!"
return
}
set i 0
foreach channel [channels] {
incr i
}
if {$i >= 10} {
putserv "PRIVMSG [lindex $text 1] :Es tut mir leid, aber ich bin schon in zu vielen Channels ($i)"
set ad_addchannel ""
return
}
foreach channel $text {
if {$ad_addchannel == [string trimleft $channel ":+@!"]} {
if { [string first "@" $channel] != "-1" } {
channel add $ad_addchannel
putserv "PRIVMSG [lindex $text 1] :Da bin ich!"
break
} else {
putserv "PRIVMSG [lindex $text 1] :Du musst Op in $ad_addchannel sein, damit ich komme!"
}
}
}
set ad_addchannel ""
}
So the visitors could say the bot that he should join the channel they said. For example !+chan #kitchenhost-test .
But the bot should only join the channel if the user, which requestet the join is an op in this channel.
And the question is: how could i du that whithout using the global variable $ad_addchannel and without using the command isop. because then the bot must join the channel first.
you cannot, you have to globalize the channel var in order to match it to the whois.
guess you want to do that because you don't want it to cause errors whenever the bot does a whois on anyone (for other reasons than the !+chan command). But I guess you can tolerate a little error from time to time, it won't harm you .
Also, I would say that unset ad_addchannel instead of set ad_addchannel "" would be better.