* finally fixed + enabled chatAI scripting!
* added core funcs "bigger_eq/greater_eq, smaller_eq" in addition to "bigger/greater, smaller & equal" * added scripted func "lfind" - return position of element in a list.
This commit is contained in:
parent
993bc000df
commit
f0b340ef3d
@ -9,16 +9,52 @@
|
|||||||
// @3: channel name. empty string if the chat message was not sent in a channel (for example say, yell or whisper)
|
// @3: channel name. empty string if the chat message was not sent in a channel (for example say, yell or whisper)
|
||||||
//--------------------------------------------
|
//--------------------------------------------
|
||||||
|
|
||||||
// not using this yet, still more or less bugged. add stuff manually if you relly need.
|
processchatai,{${@0}},{${@1}},{${@2}},{${@3}} ${@def}
|
||||||
// processchatai,{${@0}},{${@1}},{${@2}},{${@3}} ${@def}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------
|
||||||
|
#script=FlushChatAI
|
||||||
|
#permission=255
|
||||||
|
// -----------------------------------
|
||||||
|
// purpose: remove all registered chat AI scripts. usable as command.
|
||||||
|
logdebug flushing chat AI scripts.
|
||||||
|
lclean #processchatai::pattern_list
|
||||||
|
lclean #processchatai::script_list
|
||||||
|
lclean #processchatai::cond_list
|
||||||
|
lclean #processchatai::register_list
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
#script=DropChatAIScript
|
||||||
|
// ----------------------------------
|
||||||
|
// purpose: drop all entries registered to call the script specified in @def
|
||||||
|
set,amount 0
|
||||||
|
loop
|
||||||
|
set,pos ?{lfind,#processchatai::script_list,true ${@def}}
|
||||||
|
if ?{not ?{strlen ${pos}}}
|
||||||
|
exitloop
|
||||||
|
endif
|
||||||
|
set,what_sc ?{lerase,#processchatai::script_list ${pos}}
|
||||||
|
set,what_cond ?{lerase,#processchatai::cond_list ${pos}}
|
||||||
|
set,what_ptn ?{lerase,#processchatai::pattern_list ${pos}}
|
||||||
|
lerase,#processchatai::register_list ${pos}
|
||||||
|
logdetail Dropped ChatAI for script '${what_sc}', cond [${what_cond}], pattern [${what_ptn}]
|
||||||
|
add,amount 1
|
||||||
|
endloop
|
||||||
|
unset what_sc
|
||||||
|
unset what_cond
|
||||||
|
unset what_ptn
|
||||||
|
unset pos
|
||||||
|
return ${amount}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
#script=processchatai
|
#script=processchatai
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// purpose: iterate over registered AI scripts, test if the chat message matches the condition,
|
// purpose: iterate over registered AI scripts, test if the chat message matches a given condition,
|
||||||
// and execute appropriate script with predefined arguments
|
// and execute appropriate script with predefined arguments.
|
||||||
|
// returns: false if the incoming chatmessage was invalid, else true
|
||||||
// TODO: get object name (player or creature) and pass it to the called scripts
|
// TODO: get object name (player or creature) and pass it to the called scripts
|
||||||
|
|
||||||
// filter out chat messages that came from us
|
// filter out chat messages that came from us
|
||||||
@ -28,23 +64,24 @@ endif
|
|||||||
|
|
||||||
// filter out CHAT_MSG_WHISPER_INFORM ("whisper to ... : blah blah")
|
// filter out CHAT_MSG_WHISPER_INFORM ("whisper to ... : blah blah")
|
||||||
if ?{equal,${@0} 7}
|
if ?{equal,${@0} 7}
|
||||||
logdebug -- chat is whisper inform, skipping
|
|
||||||
return false
|
return false
|
||||||
endif
|
endif
|
||||||
|
|
||||||
// split the msg into a list containing only words. remove special characters also.
|
set,msg ?{lowercase ${@def}}
|
||||||
lcsplit,wlist,{ !?,;.:-_\\/<>()[]"$=+&} ${@def}
|
|
||||||
|
|
||||||
logdebug JOIN: ?{ljoin,wlist +}
|
default,filter { !?,;.:-_\\/<>()[]"$=+&#'*~`´^°}
|
||||||
|
|
||||||
|
// split the msg into a list containing only words. remove special characters also.
|
||||||
|
lcsplit,wlist,{${filter}} ${msg}
|
||||||
|
|
||||||
// remove empty entries
|
// remove empty entries
|
||||||
lclean,wlist
|
lclean,wlist
|
||||||
|
|
||||||
// obtain name of the language that was used
|
|
||||||
set,langname ?{GetSCPValue,lang,${@1} name}
|
|
||||||
default,langname UNK LANG
|
|
||||||
|
|
||||||
set,msg ?{lowercase ${@def}}
|
// obtain name of the language that was used
|
||||||
|
set,langname ?{GetSCPValue,language,${@1} name}
|
||||||
|
default,langname UNKNOWN
|
||||||
|
|
||||||
|
|
||||||
set,i 0
|
set,i 0
|
||||||
set,len ?{llen pattern_list}
|
set,len ?{llen pattern_list}
|
||||||
@ -63,26 +100,39 @@ loop
|
|||||||
if ?{equal,NONE ${cond}}
|
if ?{equal,NONE ${cond}}
|
||||||
set,call true
|
set,call true
|
||||||
else
|
else
|
||||||
if ?{equal,ALL ${cond}}
|
if ?{equal,ANY ${cond}}
|
||||||
set,call ?{lcontains_ext,{${pattern}},{ } ${msg}}
|
set,call ?{lcontains_ext,wlist,{ } ${pattern}}
|
||||||
else
|
else
|
||||||
if ?{equal,EXACT ${cond}}
|
if ?{equal,EXACT ${cond}}
|
||||||
out ${pattern}
|
|
||||||
out ${msg}
|
|
||||||
set,call ?{equal,{${pattern}} ${msg}}
|
set,call ?{equal,{${pattern}} ${msg}}
|
||||||
else
|
else
|
||||||
if ?{equal,EXACT_PARTIAL ${cond}}
|
if ?{equal,EXACT_PARTIAL ${cond}}
|
||||||
set,call ?{strlen ?{strfind,{${pattern}} ${msg}}}
|
set,call ?{strlen ?{strfind,{${pattern}} ${msg}}}
|
||||||
|
else
|
||||||
|
if ?{equal,ALL ${cond}}
|
||||||
|
// split the pattern into a list, then get its size. the amount of words matching the pattern list must be
|
||||||
|
// equal or greater then the amount of words in the pattern list
|
||||||
|
lcsplit,tmpl,{${filter}} ${pattern}
|
||||||
|
lclean,tmpl
|
||||||
|
set,pattln ?{llen tmpl}
|
||||||
|
set,matched ?{lcontains_ext,wlist,{ } ${pattern}}
|
||||||
|
set,call ?{greater_eq,${matched} ${pattln}}
|
||||||
|
unset pattln
|
||||||
|
unset matched
|
||||||
|
ldelete tmpl
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
logdebug AI call: ${call}
|
||||||
|
|
||||||
if ${call}
|
if ${call}
|
||||||
logdebug DEBUG: ChatAI: calling script ${script}, condition ${cond} matched.
|
// logdebug DEBUG: ChatAI: calling script ${script}, condition ${cond} matched.
|
||||||
${script},{${@0}},{${@1}},{${@2}},{${@3}},{${langname}} ${@def}
|
${script},{${@0}},{${@1}},{${@2}},{${@3}},{${langname}} ${@def}
|
||||||
else
|
//else
|
||||||
logdebug DEBUG: ChatAI: NOT called script ${script}, condition ${cond} not matched.
|
// logdebug DEBUG: ChatAI: NOT called script ${script}, condition ${cond} not matched.
|
||||||
endif
|
endif
|
||||||
|
|
||||||
add,i 1
|
add,i 1
|
||||||
@ -105,7 +155,7 @@ return true
|
|||||||
// @0: script name that has to be called if the condition is matched
|
// @0: script name that has to be called if the condition is matched
|
||||||
// @1: condition. allowed values are:
|
// @1: condition. allowed values are:
|
||||||
// ALL - the chat message must contain all words provided
|
// ALL - the chat message must contain all words provided
|
||||||
// ANY - the chat message must contain any word provided -- NOT WORKING YET [didnt find the reason yet :( ]--
|
// ANY - the chat message must contain any word provided
|
||||||
// ALL_ORDER - same like all, but in the order provided -- NOT YET IMPLEMENTED
|
// ALL_ORDER - same like all, but in the order provided -- NOT YET IMPLEMENTED
|
||||||
// ALL_CONSECUTIVE - same like ALL_ORDER, but the words must follow exactly one after another -- NOT YET IMPLEMENTED
|
// ALL_CONSECUTIVE - same like ALL_ORDER, but the words must follow exactly one after another -- NOT YET IMPLEMENTED
|
||||||
// EXACT - the chat message must be exactly equal to the string supplied.
|
// EXACT - the chat message must be exactly equal to the string supplied.
|
||||||
@ -124,34 +174,16 @@ set,cond ?{uppercase ${@1}}
|
|||||||
default,cond NONE
|
default,cond NONE
|
||||||
|
|
||||||
|
|
||||||
if ?{isset [${@0};${pattern};${cond}]}
|
if ?{lcontains,#processchatai::register_list {[${@0};${pattern};${cond}]}}
|
||||||
logdebug Chat AI script already registered. script: '${@0}', condition: ${cond}, pattern: '${@def}'
|
logdebug Chat AI script already registered. script: '${@0}', condition: ${cond}, pattern: '${@def}'
|
||||||
return false
|
return false
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ?{strlen ?{strfind,ALL ${cond}}}
|
lpushback,#processchatai::pattern_list ${pattern}
|
||||||
|
|
||||||
set,lname ${@0}_pattern
|
|
||||||
lcsplit,{${lname}},{ } ${pattern}
|
|
||||||
if ?{not ?{llen ${lname}}}
|
|
||||||
logerror Script error: RegisterChatAIScript: pattern is empty, but required! (called by '${@caller}')
|
|
||||||
return false
|
|
||||||
endif
|
|
||||||
lpushback,#processchatai::pattern_list ${lname}
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
lpushback,#processchatai::pattern_list ${pattern}
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
||||||
lpushback,#processchatai::script_list ${@0}
|
lpushback,#processchatai::script_list ${@0}
|
||||||
lpushback,#processchatai::cond_list ${cond}
|
lpushback,#processchatai::cond_list ${cond}
|
||||||
|
lpushback,#processchatai::register_list {[${@0};${pattern};${cond}]}
|
||||||
|
|
||||||
set,[${@0};${pattern};${cond}]
|
logdetail Chat AI script registered. script: '${@0}', condition: ${cond}, pattern: '${pattern}' [now ?{llen #processchatai::pattern_list} registered]
|
||||||
|
|
||||||
logdetail Chat AI script registered. script: '${@0}', condition: ${cond}, pattern: '${@def}' [now ?{llen #processchatai::pattern_list} registered]
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ return ${result}
|
|||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
#script=lcontains_ext
|
#script=lcontains_ext
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
// return true if any substring in @def matches any element in list @0.
|
// returns the amount of matched substrings of @def in list @0.
|
||||||
// default delimiter is space, override with @1.
|
// default delimiter is space, override with @1.
|
||||||
// by default, any char in @1 serves as delimiter.
|
// by default, any char in @1 serves as delimiter.
|
||||||
// if you set @2 to true, the exact string @1 is used as delimiter (no default is set)
|
// if you set @2 to true, the exact string @1 is used as delimiter (no default is set)
|
||||||
@ -57,15 +57,15 @@ ${engine},myl,{${delim}} ${@def}
|
|||||||
|
|
||||||
// list to check must at least contain 1 element
|
// list to check must at least contain 1 element
|
||||||
if ?{not ?{llen ${l}}}
|
if ?{not ?{llen ${l}}}
|
||||||
return
|
return 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
// and our pattern list must contain 1 element also
|
// and our pattern list must contain 1 element also
|
||||||
if ?{not ?{llen myl}}
|
if ?{not ?{llen myl}}
|
||||||
return
|
return 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
set,result false
|
set,result 0
|
||||||
|
|
||||||
loop
|
loop
|
||||||
if ?{equal,${i} ?{llen ${l}}}
|
if ?{equal,${i} ?{llen ${l}}}
|
||||||
@ -79,14 +79,10 @@ loop
|
|||||||
endif
|
endif
|
||||||
set,myelem ?{lindex,myl ${j}}
|
set,myelem ?{lindex,myl ${j}}
|
||||||
if ?{equal,{${elem}} ${myelem}}
|
if ?{equal,{${elem}} ${myelem}}
|
||||||
set,result true
|
add,result 1
|
||||||
exitloop
|
|
||||||
endif
|
endif
|
||||||
add,j 1
|
add,j 1
|
||||||
endloop
|
endloop
|
||||||
if ${result}
|
|
||||||
exitloop
|
|
||||||
endif
|
|
||||||
add,i 1
|
add,i 1
|
||||||
endloop
|
endloop
|
||||||
|
|
||||||
@ -101,3 +97,40 @@ unset delim
|
|||||||
|
|
||||||
return ${result}
|
return ${result}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------
|
||||||
|
#script=lfind
|
||||||
|
//--------------------------------------------
|
||||||
|
// return the position of the first element matching @def
|
||||||
|
// @0: list name, @def: search string
|
||||||
|
// @1: ignore case?
|
||||||
|
// if nothing is found, return empty string
|
||||||
|
|
||||||
|
set,i 0
|
||||||
|
set,l ?{globname,{${@caller}} ${@0}}
|
||||||
|
|
||||||
|
if ?{not ?{llen ${l}}}
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
set,result
|
||||||
|
loop
|
||||||
|
if ?{equal,${i} ?{llen ${l}}}
|
||||||
|
exitloop
|
||||||
|
endif
|
||||||
|
set,elem ?{lindex,{${l}} ${i}}
|
||||||
|
if ${@1}
|
||||||
|
set,eq ?{equal,{?{lowercase ${elem}}} ?{lowercase ${@def}}}
|
||||||
|
else
|
||||||
|
set,eq ?{equal,{${elem}} ${@def}}
|
||||||
|
endif
|
||||||
|
if ${eq}
|
||||||
|
set,result ${i}
|
||||||
|
exitloop
|
||||||
|
endif
|
||||||
|
add,i 1
|
||||||
|
endloop
|
||||||
|
unset i
|
||||||
|
unset l
|
||||||
|
unset elem
|
||||||
|
return ${result}
|
||||||
|
|||||||
@ -7,21 +7,22 @@
|
|||||||
// @3: channel name
|
// @3: channel name
|
||||||
// @4: language name
|
// @4: language name
|
||||||
|
|
||||||
#onload
|
|
||||||
// call us only if somebody says a text containing "hello" and "world"
|
|
||||||
RegisterChatAIScript,chat_ai_helloworld,EXACT hello world
|
|
||||||
#/onload
|
|
||||||
|
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
#script=chat_ai_helloworld
|
#script=chat_ai_helloworld
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
|
#onload
|
||||||
|
// call us only if somebody says a text containing "hello" and "world"
|
||||||
|
RegisterChatAIScript,{${@myname}},ALL hello world
|
||||||
|
set,counter 0
|
||||||
|
#/onload
|
||||||
|
|
||||||
if ?{equal,${@0} 0}
|
if ?{equal,${@0} 0}
|
||||||
// say some stuff is the language that was used by the sender
|
// say some stuff is the language that was used by the sender
|
||||||
say,${@1} Hello World! This is an example!
|
say,${@1} Hello World! This is an example! You used ${@4} language.
|
||||||
else
|
else
|
||||||
// else shout back in our default language
|
// or shout back in our default language
|
||||||
if ?{equal,${@0} 5}
|
if ?{equal,${@0} 5}
|
||||||
yell Yah "Hello World!" is widely used to proof that something is working!!
|
yell Yah "Hello World!" is widely used to proof that something is working!! You used ${@4} language.
|
||||||
else
|
else
|
||||||
if ?{equal,${@0} 14}
|
if ?{equal,${@0} 14}
|
||||||
chan,{${@3}} Recieved a nice "Hello World" in channel ${@3} ;)
|
chan,{${@3}} Recieved a nice "Hello World" in channel ${@3} ;)
|
||||||
@ -29,4 +30,10 @@ else
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
add,counter 1
|
||||||
|
|
||||||
|
// after 5 times of calling this script, it might get annoying, drop it
|
||||||
|
if ?{greater_eq,${counter} 5}
|
||||||
|
DropChatAIScript ${@myname}
|
||||||
|
endif
|
||||||
|
|
||||||
|
|||||||
@ -105,11 +105,14 @@ void DefScriptPackage::_InitFunctions(void)
|
|||||||
AddFunc("removeevent",&DefScriptPackage::func_removeevent);
|
AddFunc("removeevent",&DefScriptPackage::func_removeevent);
|
||||||
AddFunc("abs",&DefScriptPackage::func_abs);
|
AddFunc("abs",&DefScriptPackage::func_abs);
|
||||||
AddFunc("greater",&DefScriptPackage::func_bigger);
|
AddFunc("greater",&DefScriptPackage::func_bigger);
|
||||||
|
AddFunc("greater_eq",&DefScriptPackage::func_bigger_eq);
|
||||||
AddFunc("bigger",&DefScriptPackage::func_bigger);
|
AddFunc("bigger",&DefScriptPackage::func_bigger);
|
||||||
|
AddFunc("bigger_eq",&DefScriptPackage::func_bigger_eq);
|
||||||
AddFunc("equal",&DefScriptPackage::func_equal);
|
AddFunc("equal",&DefScriptPackage::func_equal);
|
||||||
AddFunc("isset",&DefScriptPackage::func_isset);
|
AddFunc("isset",&DefScriptPackage::func_isset);
|
||||||
AddFunc("not",&DefScriptPackage::func_not);
|
AddFunc("not",&DefScriptPackage::func_not);
|
||||||
AddFunc("smaller",&DefScriptPackage::func_smaller);
|
AddFunc("smaller",&DefScriptPackage::func_smaller);
|
||||||
|
AddFunc("smaller_eq",&DefScriptPackage::func_smaller_eq);
|
||||||
AddFunc("strlen",&DefScriptPackage::func_strlen);
|
AddFunc("strlen",&DefScriptPackage::func_strlen);
|
||||||
AddFunc("tohex",&DefScriptPackage::func_tohex);
|
AddFunc("tohex",&DefScriptPackage::func_tohex);
|
||||||
AddFunc("and",&DefScriptPackage::func_and);
|
AddFunc("and",&DefScriptPackage::func_and);
|
||||||
|
|||||||
@ -187,10 +187,12 @@ private:
|
|||||||
DefReturnResult func_removeevent(CmdSet&);
|
DefReturnResult func_removeevent(CmdSet&);
|
||||||
DefReturnResult func_abs(CmdSet&);
|
DefReturnResult func_abs(CmdSet&);
|
||||||
DefReturnResult func_bigger(CmdSet&);
|
DefReturnResult func_bigger(CmdSet&);
|
||||||
|
DefReturnResult func_bigger_eq(CmdSet&);
|
||||||
DefReturnResult func_equal(CmdSet&);
|
DefReturnResult func_equal(CmdSet&);
|
||||||
DefReturnResult func_isset(CmdSet&);
|
DefReturnResult func_isset(CmdSet&);
|
||||||
DefReturnResult func_not(CmdSet&);
|
DefReturnResult func_not(CmdSet&);
|
||||||
DefReturnResult func_smaller(CmdSet&);
|
DefReturnResult func_smaller(CmdSet&);
|
||||||
|
DefReturnResult func_smaller_eq(CmdSet&);
|
||||||
DefReturnResult func_strlen(CmdSet&);
|
DefReturnResult func_strlen(CmdSet&);
|
||||||
DefReturnResult func_tohex(CmdSet&);
|
DefReturnResult func_tohex(CmdSet&);
|
||||||
DefReturnResult func_and(CmdSet&);
|
DefReturnResult func_and(CmdSet&);
|
||||||
|
|||||||
@ -369,6 +369,16 @@ DefReturnResult DefScriptPackage::func_bigger(CmdSet& Set)
|
|||||||
return toNumber(Set.arg[0]) > toNumber(Set.defaultarg);
|
return toNumber(Set.arg[0]) > toNumber(Set.defaultarg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DefReturnResult DefScriptPackage::func_smaller_eq(CmdSet& Set)
|
||||||
|
{
|
||||||
|
return toNumber(Set.arg[0]) <= toNumber(Set.defaultarg);
|
||||||
|
}
|
||||||
|
|
||||||
|
DefReturnResult DefScriptPackage::func_bigger_eq(CmdSet& Set)
|
||||||
|
{
|
||||||
|
return toNumber(Set.arg[0]) >= toNumber(Set.defaultarg);
|
||||||
|
}
|
||||||
|
|
||||||
DefReturnResult DefScriptPackage::func_not(CmdSet& Set)
|
DefReturnResult DefScriptPackage::func_not(CmdSet& Set)
|
||||||
{
|
{
|
||||||
return !isTrue(Set.defaultarg);
|
return !isTrue(Set.defaultarg);
|
||||||
|
|||||||
@ -239,6 +239,7 @@ DefReturnResult DefScriptPackage::func_lmclean(CmdSet& Set)
|
|||||||
return toString((uint64)r);
|
return toString((uint64)r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// erase element at position @def, return erased element
|
||||||
DefReturnResult DefScriptPackage::func_lerase(CmdSet& Set)
|
DefReturnResult DefScriptPackage::func_lerase(CmdSet& Set)
|
||||||
{
|
{
|
||||||
DefList *l = lists.GetNoCreate(_NormalizeVarName(Set.arg[0],Set.myname));
|
DefList *l = lists.GetNoCreate(_NormalizeVarName(Set.arg[0],Set.myname));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user