| View previous topic :: View next topic |
| Author |
Message |
Gemster Halfop
Joined: 04 Oct 2010 Posts: 51
|
Posted: Wed Mar 09, 2011 8:27 pm Post subject: run command from another proc command ? |
|
|
Hi,
Ill try to explain this the best i can.
| Code: |
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 |
|
| Back to top |
|
 |
Trixar_za Op

Joined: 18 Nov 2009 Posts: 143 Location: South Africa
|
Posted: Wed Mar 09, 2011 9:26 pm Post subject: |
|
|
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: | # 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  _________________ http://www.trixarian.net/Projects |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Mar 10, 2011 4:16 pm Post subject: |
|
|
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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
ahlan Voice
Joined: 14 Apr 2014 Posts: 4 Location: Bandung Indonesia
|
Posted: Tue Apr 15, 2014 1:20 am Post subject: |
|
|
I have similar problem to fix. I get some script to modified, please help me. (i'm sorry for my bad english)
| Code: |
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: |
[brb_speak $nick $uhost $handle $chan $args]
|
result if slaps botnick without any word after
| Quote: |
-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):
| Quote: |
* ahlan slaps severus with
<mybot> hai, ahlan, miss me?
|
brb action result:
| Quote: |
* ahlan bbl
no reply from bot
|
How do i fix thoose?
thx for advice _________________ ahlan @dal.net |
|
| Back to top |
|
 |
heartbroken Op

Joined: 23 Jun 2011 Posts: 106 Location: somewhere out there
|
Posted: Tue Apr 15, 2014 2:52 am Post subject: |
|
|
| Code: | 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 |
|
| Back to top |
|
 |
ahlan Voice
Joined: 14 Apr 2014 Posts: 4 Location: Bandung Indonesia
|
Posted: Tue Apr 15, 2014 9:55 am Post subject: |
|
|
wow you're cool, heartbroken, call proc within proc solved.
but for slap respon, botnick still send msg twice:
| Quote: |
* 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: |
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.
And where:
| Code: |
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 |
|
| Back to top |
|
 |
ahlan Voice
Joined: 14 Apr 2014 Posts: 4 Location: Bandung Indonesia
|
Posted: Tue Apr 15, 2014 10:31 am Post subject: |
|
|
Maybe I write like this:
| Code: |
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  _________________ ahlan @dal.net |
|
| Back to top |
|
 |
heartbroken Op

Joined: 23 Jun 2011 Posts: 106 Location: somewhere out there
|
Posted: Tue Apr 15, 2014 10:43 am Post subject: |
|
|
you can add another proc for public messages into code below :
| Code: | 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 |
|
| Back to top |
|
 |
ahlan Voice
Joined: 14 Apr 2014 Posts: 4 Location: Bandung Indonesia
|
Posted: Tue Apr 15, 2014 11:06 am Post subject: |
|
|
thank you bro!!, muach muach...  _________________ ahlan @dal.net |
|
| Back to top |
|
 |
|
|
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
|
|