From ea25fc71b7a34ae0d40cd03e3cdba99966c71df6 Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Sat, 3 Oct 2020 08:27:03 +0800 Subject: [PATCH 1/2] fix: It's always return undefined if variable(_global or _var) is 0 or false --- src/brain.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/brain.js b/src/brain.js index 4d2159f..9e29ad1 100644 --- a/src/brain.js +++ b/src/brain.js @@ -847,7 +847,7 @@ class Brain { target[parts[0]] = parts[1]; } else { // Getting a bot/env variable - insert = target[data] || "undefined"; + insert = target[data] !== undefined ? target[data] : "undefined"; } } else if (tag === "set") { // user vars From c43e40f2f0cc2ae4cd4b5f7eebf94168f0eb603a Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Sat, 3 Oct 2020 08:29:25 +0800 Subject: [PATCH 2/2] test: add test for the variable bug --- test/test-bot-variables.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/test-bot-variables.js b/test/test-bot-variables.js index 69a1fbf..2e1d143 100644 --- a/test/test-bot-variables.js +++ b/test/test-bot-variables.js @@ -49,6 +49,21 @@ exports.test_global_variables = async function(test) { return test.done(); }; +exports.test_global_variables_set_by = async function(test) { + var bot; + bot = new TestCase(test, ` + + get mode + - Debug mode is: + + + set debug mode * + - >Switched to . + `); + await bot.reply("Get mode.", "Debug mode is: undefined"); + bot.rs._global['myMode'] = 0; + await bot.reply("Get mode.", "Debug mode is: 0"); + return test.done(); +}; + exports.test_bot_variables_utf8 = async function(test) { var bot; bot = new TestCase(test, `