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.

[SOLVED!] getting msg binds to work

Help for those learning Tcl or writing their own scripts.
Post Reply
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

[SOLVED!] getting msg binds to work

Post by dj-zath »

I know this one should be simple, but I'm not quite grasping it..

I can get bind pubs to work all-day-long...

but this:

Code: Select all

bind msg -|- !test TestMsg
and then:

Code: Select all

proc TestMsg {nick uhost hand chan arg} {
    putserv "PRIVMSG $nick :Command Successful!"
}
returns the error:

"wrong number of arguments: should be TestMsg nick uhost hand chan arg"

and, that.. as they say, is that!

so, what am I doing wrong? (sheepish grin)

-DjZ-
:) :)
Last edited by dj-zath on Sat Jan 08, 2011 1:43 am, edited 2 times in total.
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Re: getting msg binds to work

Post by willyw »

dj-zath wrote: ...

Code: Select all

proc TestMsg {nick uhost hand chan arg} {
    putserv "PRIVMSG $nick :Command Successful!"
}
chan?
what chan?
:wink:

It is a command that responds to a /msg to the bot.
No channel is involved at all.

returns the error:

"wrong number of arguments: should be TestMsg nick uhost hand chan arg"

and, that.. as they say, is that!

so, what am I doing wrong? (sheepish grin)

-DjZ-
:) :)
proc TestMsg {nick uhost hand chan arg}


Go here:
http://www.eggheads.org/support/egghtml ... mands.html
and text search to find:
bind msg
and you'll find:
procname <nick> <user@host> <handle> <text>

I hope this helps.
:)
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

hi there Willy!

and thanks for the reply

I have been screwing around with this as we speak..

II have changed it to "proc nick args" and it works.. but.. that was just the "test command" and now the actual command I need working..

I'll try to explain:

I need to be able to have users send pub commands with an arg

example:

!search tainted love

and I need them to be able to do it in a "msg window" as well..

since the bot returns the queryt in a message window, it woud only make sense that users can do that there as well...

the script to do this, in itself (I mean the script that gets the data and processess the query) is quite complex and involved... and the bext way to explain it is to demo it for you.. (that can be done simply by coming to my chat at http://ustream.tv/channel/piezo and typing !search <song name> I'm there now working on the thing...

-DjZ-
:) :)
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

thanks willy:

though I have allready read that file over a few times.. it wasn't much help in this case, however..

but, in playing around..

if I set:

Code: Select all

{nick uhost hand chan arg}
it works in a bind pub

and if I set:

Code: Select all

{nick uhost hand arg}
it works in a bind msg

the trick is to get it to work in BOTH a pub and a msg... but, if I can't do that.. (without repeating the command sets.. they are HUUUUUGE) I can live with just the msg bind..

again, thanks for the nudge!

-DjZ-
:) :)
t
thommey
Halfop
Posts: 76
Joined: Tue Apr 01, 2008 2:59 pm

Post by thommey »

Code: Select all

bind pub - !cmd docmd
bind msg - cmd docmd

proc docmd {args} {
# for pub we have 5 arguments, for msg it's 4
  if {[llength $args] == 5} {
# <=Tcl8.4 compatible way (instead of lassign):
#  foreach {nick host hand chan text} $args break
    lassign $args nick host hand chan text
    set replytarget $chan
  } elseif {[llength $args] == 4} {
# <=Tcl8.4 compatible way (instead of lassign):
#  foreach {nick host hand text} $args break
    lassign $args nick host hand text
    set replytarget $nick
  } else {
    error "Weird call of arguments"
  }
  putmsg $replytarget "Worked!"
}
Or some generic wrapper if you know your existing pub cmd procs can deal with a "fake" channel and don't require a real one (to check for [isop] etc. and just need it for replying):

Code: Select all

bind pub - !cmd "wrap pub:cmd"
bind msg - cmd "wrap pub:cmd"

proc wrap {procname args} {
  if {[llength $args] == 5} {
    lassign $args nick host hand chan text
  } else {
    lassign $args nick host hand text
    set chan $nick
  }
  $procname $nick $host $hand $chan $text
}
You can figure out other stuff you can do, just read tutorials that mention "args"
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

thanks for the heads-up thommey!

yeah, I know about using args.. but I was told to -avoid- using args (whenever possable)

I'm looking at your exmaple and (re)teaching myself the basics again :)

again, thanks for the example :)

-DjZ-
:) :)
t
thommey
Halfop
Posts: 76
Joined: Tue Apr 01, 2008 2:59 pm

Post by thommey »

Avoiding "args" because it's special is just the generic advice for beginners who use it without being aware of the special meaning instead of "text" or something else.

You can read about it here (chapter 7.5) and/or here
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

hi thommey, nml, speechles and gang..


Again, this place is some of the best minds for eggdrop!

the example you gave me didn't fix the issue, however it did offer a working example- which taught me something I didn't even realize...

args can be "list"ed!

the reason the example didn't work was because I needed arg- and once it got lassigned, it no-longer was a local varable..

I solved my problem with a simple line though...

although my code where I used the "fix" is too lengthy to display.. I'll diosplay a simple example instead..

Code: Select all

bind pub - !test command
bind msg - !test command

proc command {nick args} {
    set arg [lindex $args end-0]
    if {($args == "4")} {
        set $VarA {PRIVMSG}
    } else {
        set $VarA {NOTICE}
    }
    putquick "$VarA $nick :Command Successful! you said $arg"
}
this is very close to what I did to fix my code to work.. (I added the end so it makes sense in this example)

nonetheless it works! :)

-DjZ-
:) :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Actually, if you use "args" as the last argument in a proc-definition, it is guaranteed to be a valid tcl-list, with one item for each parameter (if any) supplied (when the proc is invoked).

Using lassign should not alter the scope of the source, as this is expected to be a list, not a variable containing a list.
The scope of the variables set by lassign depends on the names you provide with the command; do they include any namespace paths? (::myvar ::somespace::myvar), is the variable linked to a different execution level using upvar or global?, and so on.

Regarding your code; I doubt that does what you intended; $args would never be equal to the string "4". You should use the llength command to get the length of the list. Also, VarA is not set prior either "set $VarA" lines, causing an error. I assume you actually intended to set a value to the variable VarA, not a variable named by the contents of VarA (remove the $-sign).

Code: Select all

bind pub - !test command
bind msg - !test command

proc command {nick args} {
    set arg [lindex $args end]
    if {[llength $args] == 4} {
        #Triggered by the pub-binding
        set VarA {PRIVMSG}
    } else {
        #Triggered by the msg-binding
        set VarA {NOTICE}
    }
    putquick "$VarA $nick :Command Successful! you said $arg"
}
NML_375
Post Reply