27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
// This is an example Input Modifier that looks for commands from the user.
|
|
|
|
const modifier = (text) => {
|
|
let stop = false
|
|
|
|
// This matches when the user types in ":something arg1 arg2" in any of the three input formats. For example, they could
|
|
// type ":status" and then command would be "status" and args would be [], or they could type ":walk north" and command
|
|
// would be "walk" and args would be ["north"].
|
|
const commandMatcher = text.match(/\n? ?(?:> You |> You say "|):(\w+?)( [\w ]+)?[".]?\n?$/i)
|
|
if (commandMatcher) {
|
|
const command = commandMatcher[1]
|
|
const args = commandMatcher[2] ? commandMatcher[2].trim().split(' ') : []
|
|
state.message = `Got command '${command}' with args ${JSON.stringify(args)}`
|
|
stop = true
|
|
text = null
|
|
} else {
|
|
delete state.message
|
|
}
|
|
|
|
// You must return an object with the text property defined.
|
|
// If you include { stop: true } when inside of an input modifier, processing will be stopped and nothing will be
|
|
// sent to the AI.
|
|
return { text, stop }
|
|
}
|
|
|
|
// Don't modify this part
|
|
modifier(text)
|