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.

Legalchan proc and other code improvements?

Old posts that have not been replied to for several years.
Locked
s
scr0llwheel
Voice
Posts: 17
Joined: Fri Jan 03, 2003 12:37 am

Legalchan proc and other code improvements?

Post by scr0llwheel »

Ok, first take a look at the code I've got so far:

Code: Select all

proc per:say { nick host handle chan text } {
  if { [legalchan $text] } {
    unset chan
    set chan [lindex $text 0]
    set text_ [lrange $text 1 end]
    unset text
    set text $text_
  }
  putquick "PRIVMSG $chan :[join [lrange $text 0 end]]"
  mydebug "Said \"$text\" in $chan requested by $nick ($handle)"
}

proc legalchan { text } {
  if { [string index [lindex $text 0] 0] == "#" && [botonchan [lindex $text 0]] } {
    return 1
  } else {
    return 0
  }
}
Now, there are three things:
1) I want to make it so the unsetting and setting of variables is in the legalchan proc and will return those values back into the per:say proc. I've also seen something like this related to "return -code" and "upvar" (so I don't have to pass the variables to the legalproc ?)
2) It's not working if I do something like "?say #adsf test" (and the bot isn't on #asdf). I get the error of "Tcl error [per:say]: illegal channel: #asdf." It seems the "botonchan" check isn't working?
3) Is there a "reset" command so I don't have to do unset/set and especially with the $text variable? (unset/set as another name/set again).

Thanks,
scr0llwheel
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

First off, you are handling strings and list incorrectly.

See the FAQ forum, for more details on converting the string to a list, before using the "lindex" command.

Another issue. Do not use the unset command on the variables defined in the proc definition, there is no need. Simply overwrite them.

OK, for your points.

1: There is no need to do this. It can and may break things. You should do this in the per:say proc.

However, you can use the uplevel command, though it's not as easy as you think, due to Tcl evaluation.

Code: Select all

proc legalchan { text } { 
  if { [string index [lindex [split $text] 0] 0] == "#" && [botonchan [lindex [split $text] 0]] } { 
    uplevel 1 [list set chan [lindex [split $text] 0]]
    return 1
  } else { 
    return 0 
  } 
}
2: The botonchan is working perfectly fine, it's the way you use it thats incorrect.

It's likely that either the way you handle lists, or somthing else is causing this. Though the documentation doesn't say this, it may also return a error, if the bot isn't support to be monitoring that channel (in which case, there are other command ypu need too).

3: I don't understand why you need a reset command, or why you used unset int he first place.
Locked