From Gwen Morse's Wiki
Jump to: navigation, search
;HELP: info Grabs lines from the mud output, beginning with a starting line (-b) 
; catching the next lines (body -y) up to an end line (-e). The whole thing is controlled by 3 triggers
; How can the caught text be used: Either a macro name is given by the -M option. This macro is called 
; with the grabbed text as parameter line. The text is also stored in a variable (can be set by -v 
; default is fulldetail (historically)). The separate lines are concatenated by @{N} by default or the 
; delimiter given with (-d) (@{N} is used by an extension of echo that converts those to newlines). 
; When using quote mode (-q) the given macro is called for each line of grabbed text (much like quote)
; The triggering and grabbing is stopped after:
; a number ob body text lines (-n)
; a certain time (-t)
; after a second command send to the mud produced an output (see variables mud_custom_prompt, 
; mud_custom_prompt_response) it is also possible to specifiy the number of commands send to the 
; mud whose output shall be caught (e.g. the quality of different spells each listed by a separate command)
; Which lines are caught is defined by -c (b beginning line, y BodYlines, e endline, eg. -cy (default) 
; for only body lines, -cbye for all, and -cby for only the starting line and the body lines)
; if the trigger texts (-b, -y, -e) are prefixed the matching mode can be determined by the 
; prefix (r# regexp, g# glob, s# simple) by using -C a command can be given whose output shall be 
; caught, alternatively this command can be send before calling /trig_grab

;HELP: examples
;/trig_grab -b"g#*--------" -e"r#^-+$" -M/echo  -q -ag -cbye -Cinfo
;catches the output of the info command of the MUD Morgengrauen ( and echoes it line by line (-q quot emode)

;/trig_grab -b"g#*--------" -e"r#^-+$" -M/echo -d# -ag -cy -Cinfo
;only catches the body lines (see -c) and no start/end line and outputs these per echoing them after catching the whole thing (lines concatenated by #, see -d)

;/trig_grab -e"r#exits?:" -Clook -M/scan_room -aCred -d" "
; grabs the room description of the actual room, colors it red (-aCred) and calls a macro named scan_room (see -M) with the whol description as parameter (lines separated by a single space

;HELP: options
;a Attributes for the triggers
;b Beginning Text syn: [[rgs]#]Text
;e Ending Text syn: [[rgs]#]Text
;q Quote Mode (def. off)
;n Number of Body Lines
;N Number of Commands (whose output shall be caught) sent to the Mud (Prompt-Hooks)
;P custom Prompt Text (second command after the first, see mud_custom_prompt)
;t Time of catching (sec)
;v global variable name to store the grabbed lines (def. fulldetail)
;M callback Macro name (def. content of nextmakro)
;d Line delimeter (def. @{N})
;c Catch Mode ([b][y][e] b beginning y Body e end) (def. y)
;y Body Trigger Text (e.g. for prefix -y"The Guardian says: ") syn: [[rgs]#]Text (def. *)
;p Priority
;C command to send to the mud, whose output shall be caught

; examples for custom promt (shouldn't produce mud output to other players)
/set mud_custom_prompt=examine xxxx
/set mud_custom_prompt_response=No such thing!

; example for a german mud
;/set mud_custom_prompt=wuschel
;/set mud_custom_prompt_response=Wen willst Du denn wuscheln?

/def trig_grab = \
	/test ++trig_grab_counter%;\
	/let opt_M=%nextmakro%;\
	/let opt_v=fulldetail%;\
	/let opt_a=n%;\
	/let opt_d=@{N}%;\
	/let opt_p=1%;\
	/let opt_c=y%;\
	/let opt_q=0%;\
	/let opt_y=*%;\
	/test getopts("C:a:b:e:qn#p#t#v:d:c:P:M:x:N#")%;\
	/if (opt_P!~"") \
	   /let opt_e=$[trig_def_custom_prompt(opt_P)]%;\
	/eval -s0 $[trig_grab_start()]%;\
;	/list trig_grab_start_%{trig_grab_counter}%;\
	/if (opt_b=~"") /trig_grab_start_%{trig_grab_counter}%; /endif%;\
	/if (opt_C!~"") \
	/if (opt_P!~"") \
	   /trig_send_custom_prompt %opt_P%;\

/def trig_send_custom_prompt = \
	/eval %mud_custom_prompt

/def trig_def_custom_prompt = \
	/eval /return "s#%mud_custom_prompt_response"

/def trig_grab_body = \
	/let result=/def $[trig_grab_text(opt_y)] -p$[opt_p+1] -F -q -a%opt_a $[opt_n ? strcat("-n",opt_n) : ""] trig_grab_body_%{trig_grab_counter} = \
	$[opt_n ? strcat("/if (--trig_grab_number_",trig_grab_counter,"<=0) /trig_grab_end_",trig_grab_counter,"%;/break%; /endif%;") : ""] \
	/return result

/def trig_grab_text = \
	/if ({*}=/"[rgs]#*") \
	  /let param=$[substr({*},0,1)]%;\
	  /test param:=param=~"s" ? "-msimple" : param=~"r" ? "-mregexp" : "-mglob"%;\
	  /let param=%param -t"$[substr({*},2)]"%;\
	/else \
	  /let param=-mglob -t"%{*}"%;\
	/return param%;

/def trig_grab_end = \
	/if (opt_e!~"") \
	   /let result=/def $[trig_grab_text(opt_e)] -a%opt_a -p$[opt_p+2] -1 -F -q trig_grab_end_%{trig_grab_counter} = %;\
	/elseif (opt_N) \
	   /let result=/def -hPROMPT -p$[opt_p+2] -n%opt_N -F -q trig_grab_end_%{trig_grab_counter} = %;\
	/else \
	   /let result=/def trig_grab_end_%{trig_grab_counter} = %;\
	   /let result=%result \
	     $[opt_N ? strcat("/if (--trig_grab_number_",trig_grab_counter,">0) /break%; /endif%;") : ""] \
	     $[!opt_N ? trig_grab_command("e") : ""] \
	     $[strcat("/purge trig_grab_*_",trig_grab_counter,"%;")] \
	     $[!opt_q ? strcat(opt_M," -- %",opt_v , "%;") : "" ]%;\
	   /return result%;\

/def trig_grab_start = \
	/if (opt_b!~"") \
	   /let result=/def $[trig_grab_text(opt_b)] -a%opt_a -p%opt_p -1 -F -q trig_grab_start_%{trig_grab_counter} = %;\
	/else \
	   /let result=/def trig_grab_start_%{trig_grab_counter} = %;\
	   /let result=%result \
	     $[!opt_q ? strcat("/set ",opt_v,"=%;") : "" ] \
	     $[trig_grab_command("b")] \
	     $[opt_t ? strcat("/repeat -",opt_t," 1 /trig_grab_end_",trig_grab_counter,"%;") :""] \
	     $[opt_n ? strcat("/set trig_grab_number_",trig_grab_counter,"=",opt_n,"%;") : "" ] \
	     $[opt_N ? strcat("/set trig_grab_number_",trig_grab_counter,"=",opt_N,"%;") : "" ] \
	     $[escape("%$",trig_grab_end())] \%;\
	   /return result%;\

/def trig_grab_command = \
	/if (opt_c=/strcat("*",{1},"*")) \
	/if (opt_q) \
	  /return strcat(opt_M," -- \%{*}\%;")%;\
	/else \
	  /return strcat("/test ",opt_v,":=strcat(",opt_v,",{*},'",opt_d,"')\%;")%;\
	/return ""%;