diff --git a/Shared/testbot.js b/Shared/testbot.js index a97073f..aad8609 100644 --- a/Shared/testbot.js +++ b/Shared/testbot.js @@ -53,14 +53,13 @@ client.on("message", function(msg) { //DEBUGGING let dialogJson = { "hello": [ - "Hi there {1}!", - "Howdy {1}!" + "Hi there {1} {2} {3} {2} {1}!" ], "goodbye": "See ya!" } let dialog = shared.GenerateDialogFunction(dialogJson); //eventually be require("./dialog.json") -console.log(dialog("hello", "Kayne")); +console.log(dialog("hello", "Kayne", "Matthew", "Ruse")); //actually log in client.login(process.env.DEVELOPER_TOKEN); diff --git a/Shared/utility.js b/Shared/utility.js index 3b51a39..bcb9c30 100644 --- a/Shared/utility.js +++ b/Shared/utility.js @@ -23,7 +23,7 @@ exports.CloneArray = function(arg) { //GenerateDialogFunction //dialogJson - the json object containing the bot's dialog exports.GenerateDialogFunction = function(dialogJson) { - return function(key, data1 = "", data2 = "", data3 = "") { + return function(key, ...data) { let result; if (Array.isArray(dialogJson[key])) { @@ -32,10 +32,13 @@ exports.GenerateDialogFunction = function(dialogJson) { result = dialogJson[key]; } - return result - .replace(/\{1\}/g, data1) - .replace(/\{2\}/g, data2) - .replace(/\{3\}/g, data3); + let counter = 0; + data.map((dat) => { + counter++; + result = result.replace(/\{([1-9][0-9]*)\}/g, a => a === "{" + counter + "}" ? dat : a); + }); + + return result; } }