Implement suggestions from Michael

This commit is contained in:
rejas 2020-03-28 09:24:30 +01:00
parent 4e4d3418b3
commit ff7dc95e93
3 changed files with 17 additions and 12 deletions

View File

@ -29,11 +29,14 @@ Module.register("compliments", {
"You look nice!", "You look nice!",
"Hi, sexy!" "Hi, sexy!"
], ],
1403 : [ "....-01-01": [
"Happy birthday, Albert Einstein!" "Happy new year!"
], ],
1012: [ "....-..-14": [
"Happy birthday, Ada Lovelace!" "Have a great 14th day of the month!"
],
"2020-12-10": [
"Happy 205th Birthday, Ada Lovelace!"
] ]
}, },
updateInterval: 30000, updateInterval: 30000,
@ -108,7 +111,7 @@ Module.register("compliments", {
*/ */
complimentArray: function() { complimentArray: function() {
var hour = moment().hour(); var hour = moment().hour();
var date = moment().format("DDMM"); var date = moment().format("YYYY-MM-DD");
var compliments; var compliments;
if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) { if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) {
@ -129,8 +132,10 @@ Module.register("compliments", {
compliments.push.apply(compliments, this.config.compliments.anytime); compliments.push.apply(compliments, this.config.compliments.anytime);
if (date in this.config.compliments) { for (entry in this.config.compliments) {
compliments.push.apply(compliments, this.config.compliments[date]); if (new RegExp(entry).test(date)) {
compliments.push.apply(compliments, this.config.compliments[entry]);
}
} }
return compliments; return compliments;

View File

@ -27,8 +27,8 @@ let config = {
morning: [], morning: [],
afternoon: [], afternoon: [],
evening: [], evening: [],
1012: [ "....-01-01": [
"Happy birthday, Ada Lovelace!" "Happy new year!"
] ]
} }
} }

View File

@ -96,12 +96,12 @@ describe("Compliments module", function() {
before(function() { before(function() {
// Set config sample for use in test // Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_date.js"; process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_date.js";
MockDate.set("2000-12-10"); MockDate.set("2000-01-01");
}); });
it("Show happy birthday compliment on special date", function() { it("Show happy new year compliment on new years day", function() {
return app.client.waitUntilWindowLoaded().getText(".compliments").then(function(text) { return app.client.waitUntilWindowLoaded().getText(".compliments").then(function(text) {
expect(text).to.be.oneOf(["Happy birthday, Ada Lovelace!"]); expect(text).to.be.oneOf(["Happy new year!"]);
}); });
}); });