egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[SOLVED!] getting msg binds to work

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Fri Dec 31, 2010 9:47 pm    Post subject: [SOLVED!] getting msg binds to work Reply with quote

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:
bind msg -|- !test TestMsg


and then:

Code:
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-
Smile Smile


Last edited by dj-zath on Sat Jan 08, 2011 1:43 am; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Fri Dec 31, 2010 10:05 pm    Post subject: Re: getting msg binds to work Reply with quote

dj-zath wrote:

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


Quote:

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-
Smile Smile


proc TestMsg {nick uhost hand chan arg}


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

I hope this helps.
Smile
Back to top
View user's profile Send private message
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Fri Dec 31, 2010 10:17 pm    Post subject: Reply with quote

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-
Smile Smile
Back to top
View user's profile Send private message Visit poster's website
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Fri Dec 31, 2010 10:36 pm    Post subject: Reply with quote

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:
{nick uhost hand chan arg}


it works in a bind pub

and if I set:

Code:
{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-
Smile Smile
Back to top
View user's profile Send private message Visit poster's website
thommey
Halfop


Joined: 01 Apr 2008
Posts: 73

PostPosted: Fri Dec 31, 2010 11:46 pm    Post subject: Reply with quote

Code:

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:

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"
Back to top
View user's profile Send private message
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Wed Jan 05, 2011 4:10 pm    Post subject: Reply with quote

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 Smile

again, thanks for the example Smile

-DjZ-
Smile Smile
Back to top
View user's profile Send private message Visit poster's website
thommey
Halfop


Joined: 01 Apr 2008
Posts: 73

PostPosted: Thu Jan 06, 2011 11:25 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Sat Jan 08, 2011 2:19 am    Post subject: Reply with quote

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:
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! Smile

-DjZ-
Smile Smile
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Jan 08, 2011 1:40 pm    Post subject: Reply with quote

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:
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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber