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.

run command from another proc command ?

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

run command from another proc command ?

Post by Gemster »

Hi,

Ill try to explain this the best i can.

Code: Select all

proc totest {nick host handle chan arg} {
puthelp "PRIVMSG ###1 : this is a simple little test :D"
}

bind pub - ".loltest" loltest
proc loltest {nick host handle chan arg} {
totest
}
When i type ".loltest" in channel ###1 i want the bot to run the command "proc totest"

Thanks
Gemser
User avatar
Trixar_za
Op
Posts: 143
Joined: Wed Nov 18, 2009 1:44 pm
Location: South Africa
Contact:

Post by Trixar_za »

Do you know mIRC scripting? Well, take procs as an alias, because they function about the same.

Basically, you use the proc to create a custom 'command' or 'function' you want the script to use.

So to use your example, let's create script that works like you wanted:

Code: Select all

# Some Example code for you and comments to go with it ;)
# First let's bind the command properly
bind pub - .loltest loltest

# Now let's bind the test command, but let's make it a little more flexiable
# Note how I left out nick, host, handle, chan and stuff and is only using
# channel - this could be anything, but it makes more sense since that
# variable will hold the channel - but more on this later. Just know that it
# will now work in any channel that the bot is in when somebody
# uses the .loltest command.
proc totest {channel} {
    puthelp "PRIVMSG $channel :this is a simple little test :D"
}

#Ok, now for the proc that gets called by the .loltest command.
# Remember that the previous proc works like a command and just
# like if or any other command (like string, etc) it needs to be called
# in [] brackets - also note that since this is the proc called by the public 
# bind, we MUST include the standard variables nick, host, handle and
# chan. Ok, now we're going to call the previous proc, but remember
# that since it requires an channel variable, we MUST provide it when
# the command is called with the [] brackets.
proc loltest {nick host handle chan arg} {
    [totest $chan]
} 
And tada, it should be working now - sorry about the verbose comments, but they explain the basics.

Hope that helps ;)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Trixar:
Well done on the comments, though you're slightly off on the brackets...
Brackets are used for command substitutions, thus they are only needed when you'd like to take some further actions with the return value.
In this case it would mean that you try to execute the return value of "totest" as a new command, harmless as "totest" doesn't return anything in this case, but could easily get very nasty.
NML_375
a
ahlan
Voice
Posts: 4
Joined: Mon Apr 14, 2014 1:56 am
Location: Bandung Indonesia

Post by ahlan »

I have similar problem to fix. I get some script to modified, please help me. (i'm sorry for my bad english)

Code: Select all

set actReplies {
  {hei $nick, do not slap me}
  {ish..., $nick slapping me}
  {hai, $nick, miss me?}
}

bind ctcp - ACTION rep_act

proc rep_act {nick uhost hand chan keyword arg} {
  global botnick actReplies
  set repact [lindex $actReplies [rand [llength $actReplies]]]
  if {![validchan $chan]} {return 0}
  if {[string match "slaps $botnick*" $arg]} {
     puthelp "PRIVMSG $chan :[subst $repact]"
  }
  elseif {[string match "bbl*" $arg] || [string match "brb*"]} {
     [brb_speak $nick $uhost $handle $chan $args]
  }
}

set brb_msg {
  {okay, $nick}
  {$nick, dont take so long}
  {hope you not back, $nick}
  {$botnick, waiting 4 ya}
}

bind pubm - *brb* brb_speak
bind pubm - *bbl* brb_speak

proc brb_speak {nick uhost handle chan args} {
   global ini_msg oldreplytime botnick

   set replytime [unixtime]

   if { $replytime - $oldreplytime  > 7} {
      set brb_rmsg [lindex $brb_msg [rand [llength $brb_msg]]]
      puthelp "PRIVMSG $chan :[subst $brb_rmsg]"
      set oldreplytime $replytime
   }
}

set oldreplytime 0
To call procedure 'brb_speak' i write:

Code: Select all

[brb_speak $nick $uhost $handle $chan $args]
result if slaps botnick without any word after
-mybot- Rehashing...
* ahlan slaps severus
<mybot> hei ahlan, do not slap me
<mybot> ish..., $nick slapping me
result if i slaps botnick with any word after (working):
* ahlan slaps severus with
<mybot> hai, ahlan, miss me?
brb action result:
* ahlan bbl
no reply from bot
How do i fix thoose?
thx for advice
ahlan @dal.net
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

Code: Select all

set actReplies { 
   {hei $nick, do not slap me} 
   {ish..., $nick slapping me} 
   {hai, $nick, miss me?} 
 } 

 bind ctcp - ACTION rep_act 

 proc rep_act {nick uhost hand dest key text} { 
   global botnick actReplies 
   set repact [lindex $actReplies [rand [llength $actReplies]]] 
   if {$dest eq $botnick && ![validchan $dest]} { return 0 } 
   if {[string match "slaps $botnick*" $text]} { 
      puthelp "PRIVMSG $dest :[subst -nocommands $repact]" 
   } elseif {[string match "bbl*" $text] || [string match "brb*" $text]} { 
      brb_speak $nick $dest 
   } 
 } 

 set brb_msg { 
   {okay, $nick} 
   {$nick, dont take so long} 
   {hope you not back, $nick} 
   {$botnick, waiting 4 ya} 
 } 
 
 proc brb_speak {nick dest} { 
    global brb_msg oldreplytime botnick 

    set replytime [unixtime] 

    if {[expr {$replytime - $oldreplytime}]  > 7} { 
       set brb_rmsg [lindex $brb_msg [rand [llength $brb_msg]]] 
       puthelp "PRIVMSG $dest :[subst -nocommands $brb_rmsg]" 
       set oldreplytime $replytime 
    } 
 } 

 set oldreplytime 0 
have phun ...
Life iS Just a dReaM oN tHE wAy to DeaTh
a
ahlan
Voice
Posts: 4
Joined: Mon Apr 14, 2014 1:56 am
Location: Bandung Indonesia

Post by ahlan »

wow you're cool, heartbroken, call proc within proc solved.

but for slap respon, botnick still send msg twice:
* ahlan slaps severus around a bit with a large trout
<mybotnick> hai, ahlan, miss me?
<mybotnick> hei ahlan, do not slap me
* ahlan slaps severus
<mybotnick> ish..., ahlan slapping me
<mybotnick> ish..., $nick slapping me
i add "return 1" after:

Code: Select all

  if {[string match "slaps $botnick*" $text]} {
      puthelp "PRIVMSG $dest :[subst -nocommands $repact]"
      return 1
   } elseif {[string match "bbl*" $text] || [string match "brb*" $text]} {
 next line ....
and i'ts work! bot send msg on channel once. it's that ok? coz i don't know what's mean return 1. :D

And where:

Code: Select all

bind pubm - *brb* brb_speak
bind pubm - *bbl* brb_speak
because the point is I want to capture the event either through ACTION or a regular message, with the same bot. response.

Thx again for your advice
ahlan @dal.net
a
ahlan
Voice
Posts: 4
Joined: Mon Apr 14, 2014 1:56 am
Location: Bandung Indonesia

Post by ahlan »

Maybe I write like this:

Code: Select all

set actReplies {
   {hei $nick, do not slap me}
   {ish..., $nick slapping me}
   {hai, $nick, miss me?}
 }

 bind ctcp - ACTION rep_act

 proc rep_act {nick uhost hand dest key text} {
   global botnick actReplies brb_msg
   
   if {$dest eq $botnick && ![validchan $dest]} { return 0 }
   if {[string match "slaps $botnick*" $text]} {
      set repact [lindex $actReplies [rand [llength $actReplies]]]
      puthelp "PRIVMSG $dest :[subst -nocommands $repact]"
   } elseif {[string match "bbl*" $text] || [string match "brb*" $text]} {
      set repbrb [lindex $brb_msg [rand [llength $brb_msg]]]
      puthelp "PRIVMSG $dest :[subst -nocommands $repbrb]"
   }
 }


 set brb_msg {
   {okay, $nick}
   {$nick, dont take so long}
   {hope you not back, $nick}
   {$botnick, waiting 4 ya}
 }
 
bind pubm - *brb* brb_speak
bind pubm - *bbl* brb_speak 

 proc brb_speak {nick dest} {
    global brb_msg oldreplytime botnick

    set replytime [unixtime]

    if {[expr {$replytime - $oldreplytime}]  > 7} {
       set brb_rmsg [lindex $brb_msg [rand [llength $brb_msg]]]
       puthelp "PRIVMSG $dest :[subst -nocommands $brb_rmsg]"
       set oldreplytime $replytime
    }
 }

 set oldreplytime 0 
no proc within proc. but it's working :D
ahlan @dal.net
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

you can add another proc for public messages into code below :

Code: Select all

bind pubm - "*" pubm_speak

proc pubm_speak {nick uhost hand chan text} { 
     global brb_msg oldreplytime botnick 
    if {![string match "brb*" $text] || ![string match "bbl*" $text]} { return }
        set replytime [unixtime] 

     if {[expr {$replytime - $oldreplytime}]  > 7} { 
        set brb_rmsg [lindex $brb_msg [rand [llength $brb_msg]]] 
        puthelp "PRIVMSG $chan :[subst -nocommands $brb_rmsg]" 
        set oldreplytime $replytime 
     } 
	return 0
  } 
.restart your bot ..it keeps old binds .thats why it replies twice...
Life iS Just a dReaM oN tHE wAy to DeaTh
a
ahlan
Voice
Posts: 4
Joined: Mon Apr 14, 2014 1:56 am
Location: Bandung Indonesia

Post by ahlan »

thank you bro!!, muach muach... :D
ahlan @dal.net
Post Reply