forked from MousAIDungeon/Scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommandParser.js
27 lines (23 loc) · 1.05 KB
/
commandParser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// 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)