From 7b776bef822e4f905c216b76c19b693716d49779 Mon Sep 17 00:00:00 2001 From: franck403 <79372051+franck403@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:39:23 -0400 Subject: [PATCH] Update parser.js --- parser/parser.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/parser/parser.js b/parser/parser.js index 5b583b3..281c7e5 100644 --- a/parser/parser.js +++ b/parser/parser.js @@ -30,7 +30,6 @@ class ChatterScript { if (line.startsWith('on ')) { const eventName = line.split(' ')[1].replace(':', ''); this.events[eventName] = []; - this.log.push(`Event handler for '${eventName}' registered.`); } // Handle class definitions @@ -38,16 +37,15 @@ class ChatterScript { const className = line.split(' ')[1].replace(':', ''); this.classes[className] = {}; currentClass = className; - this.log.push(`Class '${className}' defined.`); } // Handle function definitions inside classes else if (line.startsWith('function ') && currentClass) { const funcName = line.split(' ')[1].replace(':', ''); this.classes[currentClass][funcName] = (args) => { - this.log.push(`Executing function ${funcName} in class ${currentClass} with args: ${JSON.stringify(args)}`); + const name = args[0] || "there"; // Default name if no argument is provided + this.log.push(`Bot replies: Hello, ${name}!`); }; - this.log.push(`Function '${funcName}' defined in class '${currentClass}'.`); } // Handle replies and messages @@ -61,9 +59,8 @@ class ChatterScript { // Allow calls to defined functions and methods else if (this.isFunctionCall(line)) { - const methodName = line.split('(')[0].trim(); const args = this.extractArgs(line); - this.callFunction(methodName, args); + this.callFunction(line, args); } } } @@ -92,9 +89,6 @@ class ChatterScript { // Check if the class and method exist if (className in this.classes && methodName in this.classes[className]) { this.classes[className][methodName](args); // Call the function with arguments - this.log.push(`Called method ${className}.${methodName} with args: ${JSON.stringify(args)}`); - } else { - this.log.push(`Error: Method ${methodName} not found in class ${className}`); } } } @@ -102,7 +96,6 @@ class ChatterScript { triggerEvent(eventName, data) { if (this.events[eventName]) { this.events[eventName].forEach(callback => callback(data)); - this.log.push(`Event '${eventName}' triggered with data: ${JSON.stringify(data)}`); } }