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.

can't read "chan": no such variable

Help for those learning Tcl or writing their own scripts.
Post Reply
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

can't read "chan": no such variable

Post by Gemster »

Hi i think i know the problem but not sure how to resolve it :/

Code: Select all

bind raw - 379 whois:stoner
proc whois:stoner {from keyword text} {
        putserv "PRIVMSG #opers :My Modes are \00310[lrange $text 5 end]\003" 
}
This works fine but when i change channel #opers to $chan i get can't read "chan": no such variable.

I think it needs {nick host handle chan arg} but it also needs {from keyword text}.

So how do i overcome this so that i can use $chan

Thanks
Gemster
User avatar
caesar
Mint Rubber
Posts: 3777
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The variables 'from keyword text' are correct. The $chan variable needs to declared before is used, thus why it complains about it can't be read.

Anyway, what you want to accomplish?
Once the game is over, the king and the pawn go back in the same box.
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

Post by Gemster »

caesar wrote:The variables 'from keyword text' are correct. The $chan variable needs to declared before is used, thus why it complains about it can't be read.

Anyway, what you want to accomplish?
I need to use $chan instead of #opers, so it will reply in any channel that me and the bot is in.

Thanks
Gemster
User avatar
caesar
Mint Rubber
Posts: 3777
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You need to store that channel name in a variable (array) cos there's no way to get it just from a raw.

I'll give you an example on how this should be done.

Code: Select all

bind pub * .whois whois:pub
bind raw - 379 whois:stoner

proc whois:pub {nick uhost hand chan text} {
  # we make sure we can access the variable globally
  global whoised

  # grab the person to whois from the user's input
  set user [lindex [split $text] 0]

  # store the name of the user and the channel in an array for later use
  set whoised($user) $chan

  # issue the whois command on the user
  putserv "WHOIS $user"
}

proc whois:stoner {from keyword text} {
  # globally call the whoised array
  global whoised

  # if the whoised array doesn't exists we return. better safe than sorry :)
  if {![info exists whoised]} return

  #grab the user from $text
  set nick [lindex [split $text] 0]

  # grab the nicks that are stored in whoised array
  set names [array names whoised]

  # return if $nick doesn't exists in that $names list
  if {[lsearch -exact -- $names $nick] == -1} return

  # $nick exists in the list, now let's grab the channel where the command to whois him has been issued
  set channel $whoised($nick)

  # we no longer need $nick in that array so we purge it
  array unset whoised $nick

  # do whatever you wish with $channel
  putserv "PRIVMSG $channel :My Modes are \00310[lrange $text 5 end]\003"
} 
I tried to explain all the lines of the code and hope you will understand them all. :) Anyway, don't be shy and leave a message if you haven't understood something.

Edit: fixed.
Last edited by caesar on Mon Mar 07, 2011 3:51 pm, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Just a quick note:
caesar wrote:

Code: Select all

# grab the nicks that are stored in whoised array
  set names [array names whoised]

  # return if $nick doesn't exists in that $names list
  if {![string equal -nocase $nick $names]} return
This can actually cause problems if the nicknames contain special characters. Things might not match since this uses the array names "list" within a "string" command.

Code: Select all

  # return if $nick doesn't exists in that $names list
  if {[lsearch -exact -- $names $nick] == -1} return
Using a "list" command on this "list" will avoid the problems that come with nicknames containing special characters...

Just trying to help avoid scenarios where people mingle string commands on lists and vice versa, as this is what creates exploits. This doesn't create an exploit in this example, but can cause things not to match when they should.
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

Post by Gemster »

Thanks caesar,

I think you may have missunderstud a little.

There is no user for it to whois, it whois itself. Basically this is for me to grab the bots modes when needed to check them.

Code: Select all

bind raw - 379 whois:stoner
proc whois:stoner {from keyword text} {
        putserv "PRIVMSG #opers :My Modes are \00310[lrange $text 5 end]\003" 
}
bind pub m ".whome" whome
proc whome {nick host handle chan arg} {
putserv "whois Stoner"
}
The above code i made works fine but will say im in channel #test or #help or #lobby ect and i type ".whome" it msg #opers not #test.

This is why i need to use $chan. and the bot is in all of the above mentioned channels.

Thanks
Gemster
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

bind raw - 379 whois:stoner

proc whois:stoner {from keyword text} {

  # does a channel to send whois info exist?
  if {[info exists ::whereWhois]} {  

    #grab the user from $text
    set nick [lindex [split $text] 0] 
  
    # is it the bots nick?
    if {[isbotnick $nick]} {

      # message the whois channel
      putserv "PRIVMSG $::whereWhois :My Modes are \00310[join [lrange [split $text] 5 end]]\003"

      # no longer need whois channel, discard it
      unset ::whereWhois
    }
}

bind pub m ".whome" whome

proc whome {nick host handle chan arg} {

  # create a global variable, to hold the whois channel
  set ::whereWhois $chan

  # send the whois
  putserv "whois $::botnick"
}
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

Post by Gemster »

Thanks but dont need

Code: Select all

  # does a channel to send whois info exist?
  if {[info exists ::whereWhois]} {  
as the chan does exist as i type .whome in that channel.

Dont need

Code: Select all

    # is it the bots nick?
    if {[isbotnick $nick]} {
The bot is called Stoner and the command is "whois Stoner"

basically i know that if i use

Code: Select all

{nick host handle chan arg}
then i can use the $chan var as it is but with my code it uses

Code: Select all

{from keyword text}


Thanks
Gemster
User avatar
caesar
Mint Rubber
Posts: 3777
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

@speechles : was working on another script and guess I mixed stuff around. Thanks for pointing that out. :)

@Gemster : I've already answered you to that question in the first post, guess you missed that out.

Anyway, raw proc expects 3 arguments: from keyword text. No matter how you name them and as long there are just 3, you would have the same information in each of them.

Like I've said before, you can't get a channel name out of the raw, or at least not like how you want. The whois command on the bot is triggered by a pub command, dcc chat or from where? Be more specific on what you want to do.

Oh, also moved this to Scripting Help.
Once the game is over, the king and the pawn go back in the same box.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Gemster wrote:Thanks but dont need

Code: Select all

  # does a channel to send whois info exist?
  if {[info exists ::whereWhois]} {  
as the chan does exist as i type .whome in that channel.
You do need that, otherwise your procedure will swallow things it shouldn't. You are trapping raws. You will over-ride eggdrops own mechanism to detect things without that check.
Gemster wrote:Dont need

Code: Select all

    # is it the bots nick?
    if {[isbotnick $nick]} {
The bot is called Stoner and the command is "whois Stoner"
Your bot isn't always called that. It uses alternative nicknames. Also, anytime the bot runs whois on anyone your procedure will take-over. You sound like you don't want help. I should stop.
Gemster wrote:basically i know that if i use

Code: Select all

{nick host handle chan arg}
then i can use the $chan var as it is but with my code it uses

Code: Select all

{from keyword text}
You refuse to listen. So help is beyond you. You don't know how to read.
Gemster wrote:Thanks
Gemster
No, it is us who thank you for being so obtuse..and wasting our efforts on you.
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

Post by Gemster »

speechles, caesar

Im sorry if it seems that i cant read or need help.

Im new to tcl scripting so i like to try to keep things simple.

Id rather have a command or whatever added to my first code so that i can learn from it and understand how it works.

Yes you guys make scripts that work how i need them but they are rather hard for me to understand them, so its a case of useing it but not learning to write it as i dont understand it.

Thanks
Gemster
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

Post by Gemster »

Anyways i finally found a way to declare the chan :D

Code: Select all


bind raw - 379 whois:stoner
proc whois:stoner {from keyword text} {
global whochan
        putserv "PRIVMSG $whochan :My Modes are \00310[lrange $text 5 end]\003" 
}
bind pub m ".whome" whome
proc whome {nick host handle chan arg} {
global whochan
putserv "whois Stoner"
set whochan $chan
}
Probilly isent the best way but it works how i need it to :D

Thanks
Gemster
User avatar
caesar
Mint Rubber
Posts: 3777
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

That's almost the same thing we said, meaning you need to store the channel in a global variable in the proc you trigger the whois then use it in the raw proc to do whatever you need. :)

Even with explaining each line of the code, you still didn't understood much?
Once the game is over, the king and the pawn go back in the same box.
G
Gemster
Halfop
Posts: 51
Joined: Mon Oct 04, 2010 5:43 pm

Post by Gemster »

caesar,

All i was saying it that there were things added that i didnt need and things i didnt understand and yes you both explained them. I guess i learn a different way as i make simple script and get them working then i grow on the scripts making them better when i learn more.

Thanks
Gemster
Post Reply