| View previous topic :: View next topic |
| Author |
Message |
emokid Voice
Joined: 07 Dec 2007 Posts: 22
|
Posted: Mon Dec 10, 2007 12:44 pm Post subject: Macro Module |
|
|
This is the current macro module I'm using:
| Code: | # <BOT> MACRO add viruskill oper gline <1> +3d You have a virus. Go away!
# <BOT> MACRO edit viruskill oper gline [1] +7d You have a virus. Go away!
# <BOT> MACRO setsep |
# <BOT> MACRO viruskill 167.6.90.254
# <BOT> MACRO rename viruskill virus
# <BOT> MACRO list
# <BOT> MACRO del virus <wildcard>
SB:registercommand MACRO 0 -none MACROS
SB:registercustomvariable global MACRO:!
proc SB:proc_macro {nick host handle chan arg} {
SB:setmiscvariables
#set macros [getdata $handle MACRO]
set macros [bnick MACRO:$handle]
set gf [join [getfirst $macros]]
switch -exact -- [stl $misc1] {
help {
printh $nick "\002The MACRO command\002"
printh $nick "Usage: (/msg) $::botnick MACRO <del | clear | list | ren(ame) | add <macro name> <command> | edit <macro name> <new command>>"
printh $nick ""
printh $nick "The MACRO command lets you define a 'macro' (like in word processing programs)"
printh $nick "to execute repeated / routine commands by only using a trigger word. This"
printh $nick "reduces the amount of typing needed for common commands and tasks. In addition,"
printh $nick "this command will also allow the use of variables in your macros."
printh $nick "StormBot.TCL 5.0 will enable the command through the normal command"
printh $nick "processor, effectively creating a new, personalized command (just for you)."
printh $nick ""
printh $nick "Example:"
printh $nick " $::botnick MACRO add virus SAY Hey, <1>, you have a virus or trojan!"
printh $nick " $::botnick virus Mikey"
printh $nick " <$::botnick> Hey, Mikey, you have a virus or trojan!"
printh $nick ""
printh $nick "Valid variable patterns: <1> \[5\] <-7> \[2-5\] \[9-13\] <1->"
printh $nick "\[1\] = take the 1st data element (optional)"
printh $nick "<2> = 2nd data element (required - will return error if missing)"
printh $nick "Also accepted: \$BOTNICK \$CHAN \$NICK"
return 0
}
setsep {# Not completed yet #}
add {
if {$misc2 == ""} {printh $nick "Error: macro name not defined"; return 0}
if {$misc3 == ""} {printh $nick "Error: macro definition not given"; return 0}
set m [lsearch -exact [stl [commandlist]] $lmisc2]
if {$m > -1} {printh $nick "I'm sorry, but $umisc2 is a StormBot.TCL command word. Please choose another name for your MACRO."; return 0}
set m [lsearch -exact [stl $gf] [stl $misc2]]
if {$m > -1} {printh $nick "I'm sorry, but you already have \"[join $misc2]\" defined as a MACRO."; return 0}
lappend macros [list $misc2 $misc3end]
set count [llength [regexp -all -inline -nocase -- {\[[0-9\-]+\]} [join $misc3end]]]
incr count [llength [regexp -all -inline -nocase -- {<[0-9\-]+>} [join $misc3end]]]
incr count [llength [regexp -all -inline -nocase -- {\$ME} [join $misc3end]]]
incr count [llength [regexp -all -inline -nocase -- {\$NICK} [join $misc3end]]]
incr count [llength [regexp -all -inline -nocase -- {\$HANDLE} [join $misc3end]]]
set commandcount [llength [regexp -all -inline -- \\\|\\\| $misc3end]]
incr commandcount
print $nick "I have added the macro \"[join $misc2]\" (commands: ${commandcount}, variables: $count)"
setbnick MACRO:$handle $macros
writedata
return 0
}
del {
if {$misc2 == ""} {printh $nick "Error: macro name not given"; return 0}
set deleteme [lsearch -glob -all -inline [stl $gf] [stl $misc2end]]
if {$deleteme == ""} {printh $nick "No MACRO matches on: [join $misc2end]"; return 0}
set temp ""
foreach a $macros {
# Isn't working with special chars ~ set macros [ldestroy -glob -nocase $macros "$killme *"]
set bad 0
foreach killme $deleteme {
debug.print 1 "> MACRO: \$KILLME ($killme), \$A ($a)"
if ![string eq [stl $killme] [sl0 $a]] {
debug.print 1 "> MACRO: --> \$A ($a), \$TEMP ($temp)"
incr bad 0
} else {
incr bad 1
debug.print 1 "> MACRO: --> \$A ($a) was rejected. \$TEMP ($temp) should be unchanged."
}
}
if !($bad) {lappend temp $a}
}
set macros $temp
print $nick "The following MACROs were deleted: [join $deleteme ", "]"
setbnick MACRO:$handle $macros
writedata
return 0
}
update - edit {
if {$misc2 == ""} {printh $nick "What MACRO am I editing?"; return 0}
if {$misc3 == ""} {printh $nick "What is the new MACRO gonna be?"; return 0}
set m [lsearch -exact [stl $gf] [jstl $misc2]]
if {$m < 0} {printh $nick "There's no such MACRO for you (\"[join $misc2]\")."; return 0}
lset macros $m [list $misc2 $misc3end]
print $nick "MACRO \"[join $misc2]\" edited to: [join $misc3end]"
setbnick MACRO:$handle $macros
writedata
return 0
}
ren - rename {
if {$misc2 == ""} {printh $nick "What MACRO am I renaming?"; return 0}
if {$misc3 == ""} {printh $nick "What is the new MACRO name?"; return 0}
set m [lsearch -exact [stl $gf] [jstl $misc2]]
if {$m < 0} {printh $nick "There's no such MACRO for you (\"[join $misc2]\")."; return 0}
set macro [lindex $macros $m]
# $M should work; GETFIRST doesn't sort, so the indeces should
# still correspond.
set n [lsearch -exact [stl $gf] [jstl $misc3]]
if {$n > -1} {printh $nick "I'm sorry, but you already have \"[join $misc3]\" defined as a MACRO."; return 0}
lset macro 0 $misc3; # No JOIN here: keep in KILLCODE format
lset macros $m $macro
setbnick MACRO:$handle $macros
print $nick "Renamed MACRO \"[join $misc2]\" to \"[join $misc3]\""
writedata
return 0
}
list {
set count 0
set max [len [llength $macros]]
set max2 [getlongest $gf]
debug.print "> MACRO - LIST: $macros"
foreach a [lsort -inc -dict -uni -index 0 $macros] {
debug.print "> MACRO - LIST: $a"
debug.print "> MACRO - LIST: [l0 $a] - [jl1 $a]"
incr count
print $nick "[using z*$max $count]) [using *$max2 [jl0 $a]]: [jl1 $a]"
debug.print "> MACRO - LIST: [l0 $a] - [jl1 $a]"
}
print $nick "> End of MACRO LIST."
}
clear {
if {[stl $misc2] != "clear"} {print $nick "Are you \002\037SURE\037\002 about this? Use \"clear clear\" to clear your list out."; return 0}
setbnick MACRO:$handle
print $nick "Your MACRO list has been cleared."
writedata
return 0
}
default {
print $nick "> Command format change! I'll compensate this time\; next time, use: (/msg) $::botnick [jl1e $arg]"
do_callcommand $nick $host $handle $chan [jl1e $arg]
return 0
}
}
return 0
}
|
I want to know if with this module, I can input more than 1 command into the single line it allows for the macro.
i.e. If you do /msg botnick macro #channel add macroname SAY I am a macro
But add another command to that same line, like "SAY I am a macro" and after that make it "ACT dances" so it says "I am a macro" then "dances" afterwards, all in the same command line.
Do more lines have to be added to the module, or is it possible with just this module alone with some separation symbol I'm unaware of? I've tried the semicolon to separate commands, but to no avail...it just displays the semicolon symbol itself instead of making the line into two separate commands. |
|
| Back to top |
|
 |
domino Voice
Joined: 19 Oct 2010 Posts: 1
|
Posted: Wed Oct 20, 2010 12:30 am Post subject: |
|
|
Heh. Someone just directed me to this post, even though it's 3 years old.
This is the MACRO bead from StormBot.TCL V5. It still exists in V6 ( available at: http://www.stormbot.org/ ).
Why didn't you just come ask us?
Anyway: use a double vertical bar to separate commands; MACRO is coded to handle it already.
<bot> macro add TEST say $CHAN I'm a macro! || act $CHAN dances a jig || say $CHAN See? I can dance, too! |
|
| 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
|
|