mirror of
https://github.com/Ratstail91/SANCTUM.git
synced 2025-11-29 02:24:27 +11:00
Updated GenerateDialogFunction()
This commit is contained in:
@@ -53,14 +53,13 @@ client.on("message", function(msg) {
|
|||||||
//DEBUGGING
|
//DEBUGGING
|
||||||
let dialogJson = {
|
let dialogJson = {
|
||||||
"hello": [
|
"hello": [
|
||||||
"Hi there {1}!",
|
"Hi there {1} {2} {3} {2} {1}!"
|
||||||
"Howdy {1}!"
|
|
||||||
],
|
],
|
||||||
"goodbye": "See ya!"
|
"goodbye": "See ya!"
|
||||||
}
|
}
|
||||||
|
|
||||||
let dialog = shared.GenerateDialogFunction(dialogJson); //eventually be require("./dialog.json")
|
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
|
//actually log in
|
||||||
client.login(process.env.DEVELOPER_TOKEN);
|
client.login(process.env.DEVELOPER_TOKEN);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ exports.CloneArray = function(arg) {
|
|||||||
//GenerateDialogFunction
|
//GenerateDialogFunction
|
||||||
//dialogJson - the json object containing the bot's dialog
|
//dialogJson - the json object containing the bot's dialog
|
||||||
exports.GenerateDialogFunction = function(dialogJson) {
|
exports.GenerateDialogFunction = function(dialogJson) {
|
||||||
return function(key, data1 = "", data2 = "", data3 = "") {
|
return function(key, ...data) {
|
||||||
let result;
|
let result;
|
||||||
|
|
||||||
if (Array.isArray(dialogJson[key])) {
|
if (Array.isArray(dialogJson[key])) {
|
||||||
@@ -32,10 +32,13 @@ exports.GenerateDialogFunction = function(dialogJson) {
|
|||||||
result = dialogJson[key];
|
result = dialogJson[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
let counter = 0;
|
||||||
.replace(/\{1\}/g, data1)
|
data.map((dat) => {
|
||||||
.replace(/\{2\}/g, data2)
|
counter++;
|
||||||
.replace(/\{3\}/g, data3);
|
result = result.replace(/\{([1-9][0-9]*)\}/g, a => a === "{" + counter + "}" ? dat : a);
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user