mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-06-08 18:25:54 +02:00
fixed string parsing, force double-quote strings
This commit is contained in:
parent
bc360f15fb
commit
74701ea663
1 changed files with 4 additions and 4 deletions
|
@ -14,8 +14,8 @@ export function getCommand(name) {
|
||||||
return commandMap[name];
|
return commandMap[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
const commandRegex = /!(\w+)(?:\(([\s\S]*)\))?/
|
const commandRegex = /!(\w+)(?:\(((?:\d+|true|false|"[^"]*")(?:\s*,\s*(?:\d+|true|false|"[^"]*"))*)\))?/
|
||||||
const argRegex = /(?:"[^"]*"|'[^']*'|[^,])+/g;
|
const argRegex = /\d+|true|false|"[^"]*"/g;
|
||||||
|
|
||||||
export function containsCommand(message) {
|
export function containsCommand(message) {
|
||||||
const commandMatch = message.match(commandRegex);
|
const commandMatch = message.match(commandRegex);
|
||||||
|
@ -82,7 +82,7 @@ function checkInInterval(number, lowerBound, upperBound, endpointType) {
|
||||||
* @param {string} message - A message from a player or language model containing a command.
|
* @param {string} message - A message from a player or language model containing a command.
|
||||||
* @returns {string | Object}
|
* @returns {string | Object}
|
||||||
*/
|
*/
|
||||||
function parseCommandMessage(message) {
|
export function parseCommandMessage(message) {
|
||||||
const commandMatch = message.match(commandRegex);
|
const commandMatch = message.match(commandRegex);
|
||||||
if (!commandMatch) return `Command is incorrectly formatted`;
|
if (!commandMatch) return `Command is incorrectly formatted`;
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ export function getCommandDocs() {
|
||||||
}
|
}
|
||||||
let docs = `\n*COMMAND DOCS\n You can use the following commands to perform actions and get information about the world.
|
let docs = `\n*COMMAND DOCS\n You can use the following commands to perform actions and get information about the world.
|
||||||
Use the commands with the syntax: !commandName or !commandName("arg1", 1.2, ...) if the command takes arguments.\n
|
Use the commands with the syntax: !commandName or !commandName("arg1", 1.2, ...) if the command takes arguments.\n
|
||||||
Do not use codeblocks. Only use one command in each response, trailing commands and comments will be ignored.\n`;
|
Do not use codeblocks. Use double quotes for strings. Only use one command in each response, trailing commands and comments will be ignored.\n`;
|
||||||
for (let command of commandList) {
|
for (let command of commandList) {
|
||||||
docs += command.name + ': ' + command.description + '\n';
|
docs += command.name + ': ' + command.description + '\n';
|
||||||
if (command.params) {
|
if (command.params) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue