| View previous topic :: View next topic |
| Author |
Message |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Sun Mar 06, 2011 8:36 pm Post subject: can't read "chan": no such variable |
|
|
Hi i think i know the problem but not sure how to resolve it :/
| Code: |
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 |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Mon Mar 07, 2011 2:19 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Mon Mar 07, 2011 7:11 am Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Mon Mar 07, 2011 8:22 am Post subject: |
|
|
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: |
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. _________________ Once the game is over, the king and the pawn go back in the same box.
Last edited by caesar on Mon Mar 07, 2011 3:51 pm; edited 1 time in total |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Mon Mar 07, 2011 2:51 pm Post subject: |
|
|
Just a quick note:
| caesar wrote: | | Code: | # 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: | # 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. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Mon Mar 07, 2011 3:12 pm Post subject: |
|
|
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: | 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 |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Mon Mar 07, 2011 3:26 pm Post subject: |
|
|
| Code: | 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"
} |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Mon Mar 07, 2011 3:48 pm Post subject: |
|
|
Thanks but dont need
| Code: | # 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: | # 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: | | {nick host handle chan arg} | then i can use the $chan var as it is but with my code it uses | Code: | | {from keyword text} |
Thanks
Gemster |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Mon Mar 07, 2011 3:49 pm Post subject: |
|
|
@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. |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Mon Mar 07, 2011 4:07 pm Post subject: |
|
|
| Gemster wrote: | Thanks but dont need
| Code: | # 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: | # 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: | | {nick host handle chan arg} | then i can use the $chan var as it is but with my code it uses | Code: | | {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. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Mon Mar 07, 2011 6:54 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Mon Mar 07, 2011 7:08 pm Post subject: |
|
|
Anyways i finally found a way to declare the chan
| Code: |
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
Thanks
Gemster |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Mar 08, 2011 1:36 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Tue Mar 08, 2011 6:41 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
|