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.

Problem with Public +chan - script

Old posts that have not been replied to for several years.
Locked
F
FloFri

Problem with Public +chan - script

Post by FloFri »

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.

Here is my script:

Code: Select all

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):

Code: Select all

Tcl error [ad:addchan]: illegal channel: #kitchenhost-test
I hope, you can say me, what is wrong.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

well, that's because the bot is not on $text yet so he can't know if nick isop on that channel unless he joins the channel. so what you want is:

Code: Select all

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!" 
  } 
 } 
}
this probably should do it.
F
FloFri

Post by FloFri »

It works, thanks, but is there also a posibility to get the info if someone is an op in a specific channel without joining that channel first?

I thought that could be done with whois. Heres the testscript i wrote:

Code: Select all

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.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Why to to transfer it when you can do the stuff in the ad:whois proc? Call globaly the name of the channel and do your stuff there..
Once the game is over, the king and the pawn go back in the same box.
F
FloFri

Post by FloFri »

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?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

What exactly do you want to do? Call globaly the text variable from ad:addchan in to ad:whois?
Once the game is over, the king and the pawn go back in the same box.
F
FloFri

Post by FloFri »

I want to use the variable $text in ad:whois but WITHOUT making $text a global variable because i dont like them very much.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Calling the $text variable in the ad:whois.. got that part, but what do you want to do with it there?
Once the game is over, the king and the pawn go back in the same box.
F
FloFri

Post by FloFri »

Here is my actual script, so you should see what i would do:

Code: Select all

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.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

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 :P .

Also, I would say that unset ad_addchannel instead of set ad_addchannel "" would be better.
Locked